分类: 系统运维
2012-05-28 15:51:01
网上有很多有关使用飞信机器人进行nagios报警,各有各的优点。
下面是我当前正在采用的方式,该方式比较简单应用,也比较容易理解。
step1:安装fetion。
a.下传文件
主程序
#wget
库文件
#wget
b.建立目标
#mkdir -p /usr/local/fetion /usr/local/fetion/lib32
将主程序复制到/usr/local/fetion目录,并设置可执行权限。
将库文件解压到/usr/local/fetion/lib32目录,加入动态库配置文件,如下:
#echo "/usr/local/fetion/lib32" >> /etc/ld.so.conf
#ldconfig
step2:配置命令对像
#vi /usr/local/nagios/etc/objects/commands.cfg
...
#notify-host-by-fetion command definition
define command{
command_name notify-host-by-fetion
command_line /usr/local/fetion/fetion --msg-type=1 --mobile=1375xxxxx --pwd=xxxxx --to=$CONTACTPAGER$ --msg-utf8="`/usr/bin/printf "%b" "\n**Demo-tech MIS dep.**\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$"`";
}
#notify-service-by-fetion command definition
define command{
command_name notify-service-by-fetion
command_line /usr/local/fetion/fetion --msg-type=1 --mobile=1375xxxxxx --pwd=xxxxx --to=$CONTACTPAGER$ --msg-utf8="`/usr/bin/printf "%b" "\n**Demo-Tech MIS Dep.**\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTNAME$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nAdditional Info:$SERVICEOUTPUT$"`";
}
...
step3:配置联系人模板,增加通知句柄
#vi /usr/local/nagios/etc/objects/templates.cfg
...
define contact{
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email,notify-service-by-fetion ; 增加通知句柄notify-service-by-fetion
host_notification_commands notify-host-by-email,notify-host-by-fetion ; 增加通知句柄notify-host-by-fetion
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
step4:配置联系人或组,增加手机号
#vi /usr/local/nagios/etc/objects/contacts.cfg
...
define contact{
contact_name guofs139
use generic-contact
email //接收者邮箱
pager 137xxxxxxxx //接收者手机号
}
define contact{
contact_name guofs163
use generic-contact
email //接收者邮箱
pager 182xxxxxxxx //接收者手机号
}
define contactgroup{
contactgroup_name group1-cn
members guofs139,guofs163
}
提示:收发手机短信可以像收发邮件一样。