`
blogfeifei
  • 浏览: 1198846 次
文章分类
社区版块
存档分类
最新评论

nagios 使用MSN 发报警消息

 
阅读更多

公司管理的服务器太多了!在年前部属了cacti,但cacti只能做事后分析的工作,而实时报警功能不强,在部属cacti前就在监控PC上安装了nagios,只是一直没有时间详细研究!目前在我们的几百台服务器上都使用脚本自动化管理!然后发报警邮件!
这段时间有点时间下来研究nagios,从今天开始就将我近段时间研究的结果记录下来!为以后再部属好查寻,做一下资料!
今天主要记录下昨天研究成功的基础nagios上报警使用MSN消息的方式!

1、准备MSN 机器人登陆使用的MSN帐号、接收报警消息的MSN帐号,两个一定要相互加为好友的关系;

2、MSN 机器人使用PHP 类:sendMsg
下载sendMsg安装,只需要将sendMsg目录放在web 根目录下就可以,配置好MSN注册使用的MSN帐号、密码;配置接收人的MSN帐号:

$senderUser='MSN帐号';
$senderPass='密码';
$sendToList = array('接受消息人1','接受消息人2');


配置好上面消息后可以测试:
在IE中打开以面的链接,那么在MSN报警接收MSN帐户就可以接收到下面的中文消息:

http://noc.chinarenservice.com/msn/index.php?SendMess=我打死你




3、 commands.cfg 配置

[root@TS263 servers]# less /usr/local/nagios/etc/servers/commands.cfg
###################################### Msn Alert #########################################################
# 'notify-by-msn' command definition
define command{
command_name notify-host-by-msn
command_line /usr/bin/printf "%b" "***** Nagios 1.0 *****/n/nNotification Type: $NOTIFICATIONTYPE$/n/nService: $SERVICEDESC$/nHost: $HOSTALIAS$/nAddress: $HOSTADDRESS$/nState: $SERVICESTATE$/n/nDate/Time: $DATETIME$/n/nAdditional Info:/n/n$OUTPUT$" > /usr/local/nagios/msnhost.out | $USER1$/messagehost.sh
}
# 'notify-service-by-msn' command definition
define command{
command_name notify-service-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$" > /usr/local/nagios/msnservice.out | $USER1$/messageservice.sh
}
[root@TS263 servers]# less /usr/local/nagios/libexec/messageservice.sh
#!/bin/bash
message=`cat /usr/local/nagios/msnservice.out`
wget -qO- http://noc.chinarenservice.com/msn/index.php?SendMess="$message"

4、添加一个MSN接收消息的联系人

[root@TS263 servers]# less /usr/local/nagios/etc/servers/contacts.cfg
define contact{
contact_name freeke2
alias freeke2
use generic-contact
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-msn
host_notification_commands notify-host-by-msn
email myfreeke@gmail.com
pager 15920094782
address1 myfreeke@gmail.com
address2 555-555-5555
}
添加上面的联系人后,注意在联系人组中也需要添加上该联系人

[root@TS263 servers]# less /usr/local/nagios/etc/servers/contactgroup.cfg
define contactgroup{
contactgroup_name admin
alias Nagios Administrators
members support,freeke2
}

然后在service配置是添加上contact_groups admin 就可以正常使用MSN报警功能了。效果就像上面的图一下接收报警信息!

配置nagios使用MSN,问了不少人,由于自己不懂shell和写代码,以至于自己在这上面郁闷了非常长的一段时间!



原文地址 http://user.qzone.qq.com/56802890/blog/1216772013

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics