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

Nagios+fetion发送手机报警使用了几个月.每次报警短信来都要看下手机.感觉麻烦.上网找了下.发现Nagios也可以跟MSN结合起来.如果是这样.上班时间发送报警消息到MSN上.下班后再发送到手机上岂不是更好.

下面是我的安装过程.写得比较简单:

首先下载MSN linux客户端工具:

[root@yunwei tmp]# wget

解压.、移至web工作目录.(发送报警消息的脚本需要通过web路径访问这个程序)

[root@yunwei tmp]# unzip sendMsg.zip

[root@yunwei tmp]# mv sendMsg /www/msn

[root@yunwei ~]# cd /www/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访问如下:

wps_clip_image-16407

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

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

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

Message text: //消息内容

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

wps_clip_image-29334

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"

wget -O - -q --post-data="sender=$SENDER&password=$PASSWD&recipient=$TO2&message=$MESSAGE"

[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"

wget -O - -q --post-data="sender=$SENDER&password=$PASSWD&recipient=$TO2&message=$MESSAGE"

记得chmod +x ..  不然没执行权限... 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/23397.html