使用nagios短信报警

上周五给服务器安装了短信报警,记录一下,以飨观众。(其实很简单的说。只是克里夫老西要我分享一下,我就乘机发一篇博好了。)

首先,安装一个飞信机器人,这里有安装步骤和说明书。下面是我的超级精简版:

这里下载主程序,解压到某个地方(如/home/berg/fetion),从这里下载libace库,解压到/usr/lib

进入/home/berg/fetion/,运行./fetion,出来帮助信息就表示你成功了

然后写一个脚本,用来发送飞信消息,我用的是perl:

#!/usr/bin/perl
use strict;
use Fcntl qw(:flock);
my @mobile = split /\s+/, $ARGV[1];
foreach (@mobile) {
system “/home/sharej/bin/fetion/fetion –mobile=137******** –pwd=password –to=$_ –msg-utf8=’$ARGV[0]‘”;
}

脚本很简单,就是接受两个参数,第一个是要发送的信息,第二个是要发送到的电话号码,空格分开。

第三步就是配置nagios。

给你的contact加上pager这一项,在我的debian下面我修改了/etc/nagios3/conf.d/contacts_nagios2.cfg:

12 define contact{
13     contact_name                    berg
14     use                             generic-contact
15     email                           ****@gmail.com
16     pager                           1381016****
17 }

然后在提醒方式上加上用短消息提醒的命令,还是这个文件:

7     service_notification_commands   notify-service-by-email,service-notify-by-sms
8     host_notification_commands      notify-host-by-email,host-notify-by-sms

最后,在command.cfg里面添加两个命令:

23 define command {
24     command_name host-notify-by-sms
25     command_line /home/sharej/bin/nagios/sms_alert.sh “[nagios] $NOTIFICATIONTYPE$ Host Alert $HOSTNAME$ is $HOSTSTATE$” “$CONTACTPAGER$”
26 }
27
28 define command {
29     command_name service-notify-by-sms
30     command_line /home/sharej/bin/nagios/sms_alert.sh “[nagios] $NOTIFICATIONTYPE$ Service Alert $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$” “$CONTACTPAGER$”
31 }

ok了,你可以进入你的web界面,随便点一个service,然后点击右边的“Send custom service notification”来测试一下飞信发送短信的效果了。

Tags: 相关Tags:

» «

相关文章

  • No Related Posts

发表评论

只有思想的碰撞才能产生火花!请留下你宝贵的评论吧: