您的位置:首页 > 移动开发 > 微信开发

Nagios微信报警

2014-02-17 21:28 239 查看
下面是具体的操作步骤一.注册微信公众平台。注册地址 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 userservice_notification_period 24×7host_notification_period 24×7service_notification_options w,u,c,r,f,shost_notification_options d,u,r,f,sservice_notification_commands notify-host-by-email,notify-host-by-sms ,notify-service-by-weixinhost_notification_commands notify-host-by-email,notify-host-by-sms ,notify-service-by-weixin
pager 134123456 ;pager numberemail abc@abc.com ;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                           abc@abc.com           ;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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: