您好,登錄后才能下訂單哦!
DocumentRoot "/var/www/html"
Nagios+fetion發送手機報警使用了幾個月.每次報警短信來都要看下手機.感覺麻煩.上網找了下.發現Nagios也可以跟MSN結合起來.如果是這樣.上班時間發送報警消息到MSN上.下班后再發送到手機上豈不是更好.
下面是我的安裝過程.寫得比較簡單:
首先下載MSN linux客戶端工具:
[root@yunwei tmp]# wget http://downloads.fanatic.net.nz/dev/php/sendMsg.zip (百度網盤)
解壓.、移至web根目錄/var/www/html.(發送報警消息的腳本需要通過web路徑訪問這個程序)
[root@yunwei tmp]# unzip sendMsg.zip
[root@yunwei tmp]# mv sendMsg /var/www/html/msn
[root@yunwei ~]# cd /var/www/html/msn
[root@yunwei msn]# ls
index.php msnpauth-1.1.3.php msnpauth.php sendMsg.php simple.php template.tpl
修改sendMsg.php
[root@yunwei msn]# head sendMsg.php
<?php
require_once('msnpauth.php'); //將msnpauth.php改為msnpauth-1.1.3.php msnpauth.php需要SSL支持.所以我們用msnpauth-1.1.3.php就好了
修改后通過web訪問如下:
Sign-in name: //發送消息的MSN帳號
Password: //發送消息的MSN密碼
Recipient: //接收消息的MSN帳號
Message text: //消息內容
測試下能不能發送.能發送的話.說明程序沒問題.
OK .程序沒問題了.現在跟Nagios結合起來:
在Nagios的commands.cfg中加入如下內容.
[root@yunwei msn]# cat /usr/local/nagios/etc/objects/commands.cfg | grep msn
# 'host-notify-by-msn' command definition
command_name host-notify-by-msn
command_line /usr/bin/printf "%b" "***** Nagios *****/n/nNotification Type: $NOTIFICATIONTYPE$/nHost: $HOSTNAME$/nState: $HOSTSTATE$/nAddress: $HOSTADDRESS$/nInfo: $HOSTOUTPUT$/n/nDate/Time: $LONGDATETIME$/n" > /tmp/msnhost.out | $USER1$/check_msn_host.sh
command_name service-notify-by-msn
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" > /tmp/msnservice.out | $USER1$/check_msn_service.sh
在contacts.cfg加入如下內容:
[root@yunwei msn]# cat /usr/local/nagios/etc/objects/contacts.cfg | grep -v "#"
define contact{
contact_name msn
alias Nagios_msn
service_notification_period 24*7
host_notification_period 24*7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands service-notify-by-msn
host_notification_commands host-notify-by-msn
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin,msn //添加msn contact.
}
創建發送報警的腳本:
[root@yunwei msn]cat /usr/local/nagios/libexec/check_msn_service.sh
#!/bin/bash
SENDER=msnnagios@hotmail.com
PASSWD=test
TO1=123@live.cn
TO2=222@hotmail.com
MESSAGE=`cat /tmp/msnservice.out`
wget -O - -q --post-data="sender=$SENDER&password=$PASSWD&recipient=$TO1&message=$MESSAGE" http://localhost/msn/index.php
wget -O - -q --post-data="sender=$SENDER&password=$PASSWD&recipient=$TO2&message=$MESSAGE" http://localhost/msn/index.php
[root@yunwei msn]cat /usr/local/nagios/libexec/check_msn_host.sh
#!/bin/bash
SENDER=msnnagios@hotmail.com
PASSWD=test
TO1=123@live.cn
TO2=222@hotmail.com
MESSAGE=`cat /tmp/msnhost.out`
wget -O - -q --post-data="sender=$SENDER&password=$PASSWD&recipient=$TO1&message=$MESSAGE" http://localhost/msn/index.php
wget -O - -q --post-data="sender=$SENDER&password=$PASSWD&recipient=$TO2&message=$MESSAGE" http://localhost/msn/index.php
記得chmod +x .. 不然沒執行權限...
原本想MSN給群發送消息.這樣效率會快一些,但是實驗不成功...發送多人消息又不能以逗號隔開.只好多寫幾條命令.達到的效果是一樣的. 如果發送的消息是空的或者發送失敗.注意下./tmp/msnhost.out跟 /tmp/msnservice.out的權限.
現在Nagios+MSN報警已經完成了.
還有最后一步. 上班時間發MSN消息 .下班發送手機報警 .
修改Nagios的timeperiods.cfg
自己定義下時間.我這里定義了兩個.workhours 跟free_times
define timeperiod{
timeperiod_name workhours
alias Normal Work Hours
monday 09:00-18:00
tuesday 09:00-18:00
wednesday 09:00-18:00
thursday 09:00-18:00
friday 09:00-18:00
}
define timeperiod{
timeperiod_name free_times
alias Normal Work Hours
sunday 18:01-08:59
monday 18:01-08:59
tuesday 18:01-08:59
wednesday 18:01-08:59
thursday 18:01-08:59
friday 18:01-08:59
saturday 18:01-08:59
}
修改飛信的報警時間參數(我們的飛信報警是設置在templates.cfg配置文件里)
service_notification_period 24x7 // 改為free_times
host_notification_period 24x7 // 改為free_times
修改MSN的報警時間參數(這個是在contacts.cfg ,我們剛剛新加的)
service_notification_period 24x7 // 改為workhours
host_notification_period 24x7 // 改為workhours
這樣上班時間的報警就發送到MSN上.下班后才發送到手機.方便多了.
來張報警效果圖:
wps_clip_p_w_picpath-15791
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。