您好,登錄后才能下訂單哦!
1. 下載微信公眾平臺私有接口
# yum install -y git
# git clone https://github.com/lealife/WeiXin-Private-API
2. 修改微信公眾平臺私有接口代碼,以配合 nagios 報警
# cp -r WeiXin-Private-API /usr/local/nagios/libexec/weixin
# chown -R nagios.nagios /usr/local/nagios/libexec/weixin
# cd /usr/local/nagios/libexec/weixin
修改 config.php 文件:
$G_CONFIG["weiXin"] = array(
'account' => '微信公眾平臺登錄帳號',
#填寫你注冊的微信訂閱號的帳號和密碼
'password' => '微信公眾平臺登錄密碼',
修改 test.php 文件,只保留如下幾行即可:
<?php
require "config.php";
require "include/WeiXin.php";
$weiXin = new WeiXin($G_CONFIG['weiXin']);
$testFakeId = "$argv[1]"; #微信好友 ID 號,這里通過 nagios 傳入
$msg = `cat /usr/local/nagios/var/nagios.msg`; #要發送的報警信息,由 nagios 傳入
print_r($weiXin->send($testFakeId, "$msg")); #給微信好友發送信息
3. 整合 nagios 和微信公共平臺私有接口
1) 增加微信報警選項: templates.cfg
修改 /usr/local/nagios/etc/objects/templates.cfg
在 define contact{...} 部分,將以下兩行:
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
改為:service_notification_commands notify-service-by-email,service-notify-by-weixin
host_notification_commands notify-host-by-email,host-notify-by-weixin
2) 增加調用命令: commands.cfg
修改 /usr/local/nagios/etc/objects/commands.cfg
在該文件的最后增加以下部分:
##### host-notify-by-weixin command definition
define command{
command_name host-notify-by-weixin
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/nagios/var/nagios.msg && /usr/bin/php /usr/local/nagios/libexec/weixin/test.php
$CONTACTADDRESS1$ &>/dev/null
}
##### service-notify-by-weixin command definition
define command{
command_name service-notify-by-weixin
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$\n" > /usr/local/nagios/var/nagios.msg && /usr/bin/php
/usr/local/nagios/libexec/weixin/test.php $CONTACTADDRESS1$ &> /dev/null
3) 修改聯系人選項: contact.cfg
修改 /usr/local/nagios/etc/objects/contact.cfg
在 define contact{...} 部分增加如下一行
address1 1000000000 #微信好友 ID
4) 重載 nagios 配置
# service nagios reload
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。