Nagios微信报警

下面是具体的操作步骤
一.注册微信公众平台。注册地址 https://mp.weixin.qq.com/
二.下载nodejs程序,在程序config/config.coffee中填写刚注册的公众号和密码。 启用程序(nodejs的启动很简单建议大家用forever作成一个系统服务,上网找找资料由于篇幅问题在这里略过)。程序下载地址:https://github.com/ym1623/node_wx
本程序有两个功能:1.是模拟登陆 2.是获取好友列表



三.写一个调用微信接口的SHELL,我写了几行SHELL在这里奉上。
weixin.rar
四.Nagios的配置
1.在 objects/commands.cfg中增加如下信息


define command{
command_name    notify-host-by-weixin    
command_line    /usr/bin/printf "%b" "*****ERS monitor Robot*****\n\n Notification Type: $NOTIFICATIONTYPE$\n Host: $HOSTNAME$\nState: $HOSTSTATE$\n Address: $HOSTADDRESS$\n Info: $HOSTOUTPUT$\n\n Date/Time: $LONGDATETIME$\n" >/usr/local/nagios/var/weixin.out | /usr/local/bin/weixin.sh -f $CONTACTADDRESS1$
       }
# 'notify-service-by-weixin' command definition
 define command{   
 command_name    notify-service-by-weixin
                        
 command_line    /usr/bin/printf "%b" "***** ERS monitor Robot*****\n\nNotification Type:                                          $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" > /usr/local/nagios/var/weixin.out | /usr/local/bin/weixin.sh -f $CONTACTADDRESS1$
                                 }


注意:command_line后面的是在一行中
2.以objects/contacts.cfg中示例信息如下:



define contact{
contact_name              nagiosadmin             ; Short name of user
alias                           Nagios Admin            ; Full name of user
service_notification_period     24×7
host_notification_period        24×7
service_notification_options    w,u,c,r,f,s
host_notification_options       d,u,r,f,s
service_notification_commands    notify-host-by-email,notify-host-by-sms ,notify-service-by-weixin
host_notification_commands      notify-host-by-email,notify-host-by-sms ,notify-service-by-weixin
pager                          134123456               ;pager number
email                           [email protected]           ;Email message
address1                     2447905640               ;微信好友ID号
}
define contact{
contact_name              nagiosadmin             ; Short name of user
alias                           Nagios Admin            ; Full name of user
service_notification_period     24×7
host_notification_period        24×7
service_notification_options    w,u,c,r,f,s
host_notification_options       d,u,r,f,s
service_notification_commands    notify-host-by-email,notify-host-by-sms ,notify-service-by-weixin
host_notification_commands      notify-host-by-email,notify-host-by-sms ,notify-service-by-weixin
pager                          134123456               ;pager number
email                           [email protected]           ;Email message
address1                     2447905640               ;微信好友ID号
}


注明:微信ID号可以通过   http://nodejs IP/wx/friend获取 格式如下:
  • {


    • id: 11212856820,
    • nick_name: "微信昵称",
    • remark_name: "",
    • group_id: 0

    }


保存重启nagios 测试一下 大功告成


http://www.icanwen.com/?p=746




你可能感兴趣的:(接口,程序,密码,nagios,forever)