Nagios邮件报警配置

一、安装sendmail组件

首先要确保sendmail相关组件的完整安装,我们可以使用如下的命令来完成sendmail的安装:

# yum install -y sendmail*

然后重新启动sendmail服务:

# service sendmail restart

二、邮件报警的配置

下面是我的邮件报警的配置过程:

1、开启系统自带的sendmail邮件系统

#service sendmail start

测试发送邮件:

echo “test” | mail wuwenhui@*******.cn

我系统在关掉iptables和selinux前提下是正常的

2、配置nagios中报警邮箱

vi /var/www/html/nagios/etc/objects/contacts.cfg

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user
        email                           nagios@localhost        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }

修改nagios@localhost为接收邮件地址,如果有多个可以用逗号隔开!

3、设置报警方式

#vi /var/www/html/nagios/etc/objects/templates.cfg

define contact{
        name                            generic-contact         ; The name of this contact template
        service_notification_period     24×7                    ; service notifications can be sent anytime
        host_notification_period        24×7                    ; host notifications can be sent anytime
        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
        host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events
        service_notification_commands   notify-service-by-email ; send service notifications via email
        host_notification_commands      notify-host-by-email    ; send host notifications via email
        register                        0                       ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL CONTACT, JUST A TEMPLATE!
        }

这两个 notify-service-by-email 和 notify-host-by-email 是在commands.cfg那里定义的,看看是怎么定义的:

#vi /var/www/html/nagios/etc/objects/commands.cfg

# ‘notify-host-by-email’ command definition
define command{
        command_name    notify-host-by-email
        command_line    /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n” | /bin/mail -s “** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **” $CONTACTEMAIL$
        }
# ‘notify-service-by-email’ command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$” | /bin/mail -s “** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
        }

这里已经默认配置好,我们不用修改直接调用就是了

4、最后重启服务

#service nagios restart

然后随便关掉一些服务测试一下效果!

原创文章,作者:wwh,如若转载,请注明出处:https://www.wuwenhui.cn/4136.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
wwhwwh
上一篇 2016-07-11
下一篇 2016-07-13

相关推荐

  • Serv-U本地服务器密码错误

    服务器上的serv_u 点击本地服务器,输入了正确的密码但提示“本地服务器密码错误”的解决方法。 这类原因一般是 Serv-U程序错误,或密码被修改了,修复方法: 这个是Serv-…

    2013-04-21
    5.3K0
  • 网站.bz2后缀链接打不开

    前阵子公司服务器出了点问题,重装后,发现只要后缀是.bz2的链接都打不开,网上查了下资料,是因为没加扩展支持,到服务器上添加个MIME类型就行了。 打开IIS,选中你的网站右键“属…

    2013-03-12
    7.8K2

发表回复

登录后才能评论

联系我们

在线咨询:点击这里给我发消息

站长邮箱:admin@wuwenhui.cn
工作时间:周一至周五,8:30-17:30,节假日休息

微信
本站支持QQ一键注册登录,所有资源下载均在文章底部~