nagios组合飞信
1、软件环境(centos 5为例)
官网地址:[url]http://www.it-adv.net/[/url]
支持库安装:需要Glibc2.4以上的版本
2、安装过程
支持库和安装包内容如下:
- # tar zxvf libraryrh4×32.tar.gz
- libACE-5.6.5.so
- libACE_SSL-5.6.5.so
- libcrypto.so.0.9.7a
- libssl.so.0.9.7a
- # tar zxvf fetion20080522004-linrh4.tar.gz
我将fetion放在/../nagios/libexec/sms
把支持库复制到/usr/lib/目录下,并作软链接如下:
- cp lib*so* /usr/lib/
- ln -s /usr/lib/libcrypto.so.0.9.7a /usr/lib/libcrypto.so.4
- ln -s /usr/lib/libssl.so.0.9.7a /usr/lib/libssl.so.4
设定lib库配置文件
- #vi /etc/ld.so.conf
- #增加一条
- /usr/lib/
- #保存退出后,执行
- #ldconfig
- fetion的目录结构:
- .\Readme.txt: 本说明文件
- .\fetion:主程序
- .\sound\*.wav:各种音效文件,您可以用自己喜欢的文件替换
- .\plugins\plugin_*: 插件程序,您可以修改插件以达到自己的各性化需求
完成之后测试,安装是否成功;执行
- #cd install
- # ./fetion -h
- Usage:
- fetion -h
- -h: help
- fetion -u mobile -p pwd [-b batchfile] [-EN] [-d]
- fetion -u mobile -p pwd [-b batchfile] [-EN] [-d]
- -u: Fetion user account(only supports mobile phone No.)
- -p: Account password
- -b: Batch file name
- -d: Debug and write logs to [mobile]-debug.log
- -EN: English
3、实际测试
测试帐号:13888888888
密码:123456 (如果密码中含有特殊字符,请使用单引号)
如果发送成功。那么飞信安装过程就OK了
4、飞信组合nagios
Fetion以后台方式启动:nohup /usr/local/nagios/libexec/sms/fetion -u 13888888888 -p 123456 >/dev/null 2>1 &
写一个perl脚本(本脚本由gzmaster小弟提供)
- Sms.pl (/../nagios/libexec/sms/sms.pl)
- #!/usr/bin/perl -w
- use strict;
- use Data::Dumper;
- use LWP::UserAgent;
- my $mesg = shift;
- $mesg =~ s/\//|/g;
- my @number = (接收手机号,接收手机号);
- foreach my $number ( @number ) {
- #print “send sms to $number \n”;
- my $send_sms_url = “http://localhost:40000/API/buddy/sms/” . $number . “/” . $mesg . ‘?rand=0.7394060082921254′;
- my $request = HTTP::Request->new(GET => $send_sms_url);
- my $ua = LWP::UserAgent->new;
- $ua->timeout( 5 );
- $ua->agent(“Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; Maxthon 2.0)”);
- my $response = $ua->request($request);
- my $content = $response->content();
- }
修改相应的配置文件
修改用户及组:contacts.cfg
添加:
- define contact{
- contact_name sms-members
- use sms-mail-contact
- alias Nagios Admin SMS
- pager 138888888888
- }
- define contactgroup{
- contactgroup_name admins-and-lijs
- alias Nagios Administrators
- members sms-members
- }
修改报警选项:templates.cfg
- define contact{
- name generic-contact
- service_notification_period 24×7
- host_notification_period 24×7
- service_notification_options w,u,c,r,f,s
- host_notification_options d,u,r,f,s
- service_notification_commands notify-service-by-email; service-notify-by-sms
- host_notification_commands notify-host-by-email
- register 0
- }
- define contact{
- name sms-mail-contact
- service_notification_period 24×7
- host_notification_period 24×7
- service_notification_options w,u,c,r,f,s
- host_notification_options d,u,r,f,s
- service_notification_commands service-notify-by-sms
- host_notification_commands notify-host-by-email
- register 0
- }
修改调用脚本:commands.cfg
- #host-notify-by-sms
- define command {
- command_name host-notify-by-sms
- command_line /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nHost: $HOSTNAME$\nState:
- $HOSTSTATE$\nWAN_IP: $HOSTALIAS$\nLAN_IP: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n” | /usr/local/nagios/lib
- exec/sms.pl 710880931 “** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **” $CONTACTEMAIL$
- }
- #service notify by sms
- define command {
- command_name service-notify-by-sms
- command_line /usr/local/nagios/libexec/sms/sms.pl ‘** $NOTIFICATIONTYPE$ alert – $HOSTNAME$ $SERVICEDESC$ is $SERVICESTA
- TE$ info: $SERVICEOUTPUT$’
- }
测试下nagios情况。然后再测试报警。Nagios飞信配置就OK了。
【编辑推荐】