-
公司管理的服务器太多了!在年前部属了cacti,但cacti只能做事后分析的工作,而实时报警功能不强,在部属cacti前就在监控PC上安装了nagios,只是一直没有时间详细研究!目前在我们的几百台服务器上都使用脚本自动化管理!然后发报警邮件!
这段时间有点时间下来研究nagios,从今天开始就将我近段时间研究的结果记录下来!为以后再部属好查寻,做一下资料!
今天主要记录下昨天研究成功的基础nagios上报警使用MSN消息的方式!
下载sendMsg安装,只需要将sendMsg目录放在web 根目录下就可以,配置好MSN注册使用的MSN帐号、密码;配置接收人的MSN帐号:
$senderPass='密码';
$sendToList = array('接受消息人1','接受消息人2');
配置好上面消息后可以测试:
在IE中打开以面的链接,那么在MSN报警接收MSN帐户就可以接收到下面的中文消息:
###################################### 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"
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
}
添加上面的联系人后,注意在联系人组中也需要添加上该联系人
define contactgroup{
contactgroup_name admin
alias Nagios Administrators
members support,freeke2
}
文章出处:DIY部落