本文介绍nagios报警设置,包括网页报警、邮件报警与飞信报警。
一、网页报警
二、邮件报警 (使用sendEmail 发送邮件)
复制代码代码如下:
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” | /usr/local/bin/sendEmail -f -t -s mail.scomd.com -u “from nagios” -xu nagios -xp scomd ; /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$” | /usr/local/bin/sendEmail -f -t -s mail.scomd.com -u “from nagios” -xu nagios -xp scomd } 发现一个小问题,用163测试,密码错误的竟然也可以发送。
三、飞信报警 (移动用户必须开通飞信业务)
复制代码代码如下:
define command {
command_name host-notify-by-fetion command_line LD_LIBRARY_PATH=/usr/local/nagios/fx /usr/local/nagios/fx/fetion –mobile=13691515****–pwd=passwd –to=13691515**** –msg-utf8=”Host $HOSTSTATE$ alert for $HOSTNAME$! on ‘$LONGDATETIME$’” $CONTACTPAGER$ } define command { command_name service-notify-by-fetion command_line LD_LIBRARY_PATH=/usr/local/nagios/fx /usr/local/nagios/fx/fetion –mobile=13691515**** –pwd= passwd –to=13691515**** –msg-utf8=”$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$” $CONTACTPAGER$ } 编辑contact.cfg,添加短信通知
复制代码代码如下:
define contact{ contact_name nagiosadmin use generic-contact alias Nagios Admin service_notification_commands notify-service-by-email,service-notify-by-fetion host_notification_commands notify-host-by-email,host-notify-by-fetion pager 13691515**** } |