Nagios+MSN+Fetion自定义时间发送报警消息-创新互联

DocumentRoot "/var/www/html"

创新互联是专业的井陉矿网站建设公司,井陉矿接单;提供网站建设、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行井陉矿网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

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

require_once('msnpauth.php');  //将msnpauth.php改为msnpauth-1.1.3.php  msnpauth.php需要SSL支持.所以我们用msnpauth-1.1.3.php就好了

修改后通过web访问如下:

Nagios+MSN+Fetion自定义时间发送报警消息

Sign-in name: //发送消息的MSN帐号

Password: //发送消息的MSN密码

Recipient: //接收消息的MSN帐号

Message text: //消息内容

Nagios+MSN+Fetion自定义时间发送报警消息

测试下能不能发送.能发送的话.说明程序没问题.

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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:Nagios+MSN+Fetion自定义时间发送报警消息-创新互联
分享链接:http://lszwz.com/article/doogsi.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款