liyeho 发表于 2019-1-17 08:54:21

Nagios之飞信与email配置

Nagios之飞信与email配置
首先感谢Deidara兄弟的这篇文章及相关飞信php程序
http://deidara.blog.运维网.com/400447/159290
1.先下载相关程序,配置好该程序需要安装配置好php环境支持
Cp * /var/www/html/sms/
Ls /var/www/html/sms/
class.curl.phpclass.fetion.phpclass.SIPC.phpsend.php
更改$sms->phone_num 及$sms->password参数
2.该程序默认调用/usr/local/nagios/ smservice.out该文件的内容为短信内容
用wget -qO- http://localhost:8080/sms/send.php?re=1586718xxxx测试
成功后进入相关nagios配置
3.chown –R nagios.nagos smservice.out

修改contacts.cfg
define contact{
      contact_name                  xxx                   ; Short name of user
      alias                           Nagios             ; Full name of user
      service_notification_period   24x7
      host_notification_period      24x7
      service_notification_options    u,c,r
      host_notification_options       d,u,r
      service_notification_commands   service-notify-by-email,service-notify-sms
      host_notification_commands      host-notify-by-email,host-notify-sms
      email                           xxxx@126.com       ; > /dev/null
}
###### service-notify-sms ######
define command {
       command_name   service-notify-sms
       command_line   /usr/bin/printf "%s" "$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ $CONTACTPAGER$" > /usr/local/nagios/smservice.out | wget -qO- http://localhost:8080/sms/send.php?re=$CONTACTPAGER$ >> /dev/null
}

Emails配置,上面的contancts.cfg文件里已添加email选项
# 'notify-host-by-email' command definition
# '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" | /usr/local/sendEmail-v1.55/sendEmail -f mailaddress -t $CONTACTEMAIL$-s stmpmailaddress -u "" -xu user -xp password -m ""                                 
      }
# '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/sendEmail-v1.55/sendEmail -f nagios@126.com-s mail.126.com -u ¡°from nagios-xu user -xp password -m"** $NOTIFICATIONTYPE$ ice Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
      }
邮箱配置我还没有完善过,不过可以发邮件,本来是想用126,gmail等免费邮的但由于服务器缺少TSL相关模块,所以没有去弄了。如果无须ssl认证的可以直接使用,借朋友的邮箱试过了
相关程序见附件


附件:http://down.运维网.com/data/2353089

页: [1]
查看完整版本: Nagios之飞信与email配置