Nagios使用飞信Robot发送报警短信:
一、概述
Nagios 是配置Nagios使用飞信Robot短信报警、配置Nagios使用飞信Robot短信报警,Linux 环境下使用率最高的配置Nagios使用飞信Robot短信报警监控软件,它善于监控服务,容易进行二次定制。
飞信 Robot 是一款基于移动飞信服务的类 Unix 实现。通过 飞信Robot 可以很方便的在 shell 下发送免费短信。
本文介绍介绍了如何通过 飞信Robot 使得 Nagios 可以免费发送报警短信。
平台:CentOS 5.2 x86_64
#p#
二、飞信 Robot
写此文时,使用的 飞信 软件版本为:飞信20080910047-lin64.tar.gz md5sum:9265d8f57556672220ee6a22c77c65af。使用的支持库 library64_linux.tar.gz md5sum 为:2e858e9184c4761bb0d1f9cea14dc49e 。
安装 飞信 Robot
下载 飞信 Robot 以及依赖库。下载完成后记得执行一下ldconfig刷新一下。
解压缩 飞信20080910047-lin64.tar.gz 得到二进制文件。直接运行 飞信 即可:
引用
[root@cacti install]# ./fetion -h
- 1.
- 2.
Usage:
fetion -h
-h: help
fetion -u mobile -p pwd [-b batchfile] [-EN] [-d]
fetion -c [config_file] -id [n] [-EN] [-d]
-u: fetion user account(only supports mobile phone No.)
-p: Account password
-b: Batch file name
-d: Debug on and write logs to [mobile]-debug.log
-c: config file name, refer to fetion.conf
-i: id, refer to fetion.conf
-EN: English
[root@cacti install]#
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
可能出现的问题
在 64 位系统下会出现 libstdc++ 包版本过低的问题。具体表现为:[root@cacti ~]# fetion -h
fetion: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /usr/lib64/libACE.so.5.4.7)出现此问题,是由于 gcc 的版本太低,同时导致 libstdc++ 库版本过低。CentOS 5.2 使用 libstdc++-4.1.2-42.el5 版本。而通过 rpm 查询 可以看到,此版本最高只提供了 GLIBCXX_3.4.8 。
如果你有足够的时间,可以自己编译高版本的 gcc。并且在运行 飞信 时指定 lib 地址。
另外你还可以找一个 Fedora Core 9 中的 libstdc++ 。它包含了所需要的库。[root@cacti ~]# rpm -Uvh --force libstdc++-4.3.0-8.x86_64.rpm
warning: libstdc++-4.3.0-8.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 4f2a6fd2
Preparing... ########################################### [100%]
1:libstdc++ ########################################### [100%]
#p#
三、perl 脚本准备
此脚本从 论坛上配置Nagios使用飞信Robot短信报警这篇文章 修改而来。稍微做了一点加工。
脚本的作用是将 nagios 中的报警信息以及要通知的手机号码格式化的输入到其他文本中。这里的“格式化”是符合 飞信 脚本模式的格式化。在输出完成后,调用 飞信 去依照文本发短信。
我修改的内容是让脚本支持一次通知多个手机。
#!/usr/bin/perl
use strict;
use Fcntl qw(:flock);
open SMS, "]/tmp/sms.txt" or die "NO OK";
flock(SMS,LOCK_EX);
my @mobile = split /\s+/, $ARGV[1];
foreach (@mobile) {
print SMS "sms $_ $ARGV[0]\n";
}
print SMS "quit\n";
system "/usr/bin/fetion -u 136xxxxxx -p xxxxxxxx -b /tmp/sms.txt";
#unlink "/home/sms/sms.txt";
flock(SMS,LOCK_UN);
close SMS;
#unlink "/home/sms/sms.txt";
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
推荐将此脚本放在nagios/libexec/下。
记得在 /tmp 下创建 sms.txt 文件,777。
#p#
四、Nagios 配置
nagios 配置2个点:
1.定义短信提醒方式。调用前面写的 perl 脚本。同时将报警信息和手机号码传入脚本。
2.定义管理员接受报警方式。
直接贴配置文件了:
定义短信提醒调用脚本
define command {
command_name host-notify-by-sms
command_line /usr/local/nagios/libexec/sms "IP: $HOSTADDRESS$($HOSTNAME$) is $HOSTSTATE$\n$SHORTDATETIME$" "$CONTACTPAGER$"
}
define command {
command_name service-notify-by-sms
command_line /usr/local/nagios/libexec/sms "'$HOSTADDRESS$' $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" "$CONTACTPAGER$"
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
定义管理员接受报警方式
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
service_notification_commands notify-service-by-email,service-notify-by-sms
host_notification_commands notify-host-by-email,host-notify-by-sms
email youremailaddress;
pager 136xxxxxxx 136xxxxxx
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
【编辑推荐】