Nagios飞信配置

运维 系统运维
Nagios飞信配置:Nagios是一个监控系统运行状态和网络信息的监控系统。Nagios能监控所指定的本地或远程主机以及服务,同时提供异常通知功能等。就比如是以飞信的方式发送。这篇文章主要讲的是Nagios飞信配置。

  nagios组合飞信

  1、软件环境(centos 5为例)

  官网地址:[url]http://www.it-adv.net/[/url]

  支持库安装:需要Glibc2.4以上的版本

  2、安装过程

  支持库和安装包内容如下:

  1.   # tar zxvf libraryrh4×32.tar.gz  
  2.  
  3.   libACE-5.6.5.so  
  4.  
  5.   libACE_SSL-5.6.5.so  
  6.  
  7.   libcrypto.so.0.9.7a  
  8.  
  9.   libssl.so.0.9.7a  
  10.  
  11.   # tar zxvf fetion20080522004-linrh4.tar.gz  
  12.  

  我将fetion放在/../nagios/libexec/sms

  把支持库复制到/usr/lib/目录下,并作软链接如下:

  1.   cp lib*so* /usr/lib/  
  2.  
  3.   ln -s /usr/lib/libcrypto.so.0.9.7a /usr/lib/libcrypto.so.4  
  4.  
  5.   ln -s /usr/lib/libssl.so.0.9.7a /usr/lib/libssl.so.4  
  6.  

  设定lib库配置文件

  1.   #vi /etc/ld.so.conf  
  2.  
  3.   #增加一条  
  4.  
  5.   /usr/lib/  
  6.  
  7.   #保存退出后,执行  
  8.  
  9.   #ldconfig  
  10.  
  11.   fetion的目录结构:  
  12.  
  13.   .\Readme.txt: 本说明文件  
  14.  
  15.   .\fetion:主程序  
  16.  
  17.   .\sound\*.wav:各种音效文件,您可以用自己喜欢的文件替换  
  18.  
  19.   .\plugins\plugin_*: 插件程序,您可以修改插件以达到自己的各性化需求  
  20.  

  完成之后测试,安装是否成功;执行

  1.   #cd install  
  2.  
  3.   # ./fetion -h  
  4.  
  5.   Usage:  
  6.  
  7.   fetion -h  
  8.  
  9.   -h: help  
  10.  
  11.   fetion -u mobile -p pwd [-b batchfile] [-EN] [-d]  
  12.  
  13.   fetion -u mobile -p pwd [-b batchfile] [-EN] [-d]  
  14.  
  15.   -u: Fetion user account(only supports mobile phone No.)  
  16.  
  17.   -p: Account password  
  18.  
  19.   -b: Batch file name  
  20.  
  21.   -d: Debug and write logs to [mobile]-debug.log  
  22.  
  23.   -EN: English  
  24.  

  3、实际测试

  测试帐号:13888888888

  密码:123456 (如果密码中含有特殊字符,请使用单引号)

  如果发送成功。那么飞信安装过程就OK了

  4、飞信组合nagios

  Fetion以后台方式启动:nohup /usr/local/nagios/libexec/sms/fetion -u 13888888888 -p 123456 >/dev/null 2>1 &

  写一个perl脚本(本脚本由gzmaster小弟提供)

  1.   Sms.pl (/../nagios/libexec/sms/sms.pl)  
  2.  
  3.   #!/usr/bin/perl -w  
  4.  
  5.   use strict;  
  6.  
  7.   use Data::Dumper;  
  8.  
  9.   use LWP::UserAgent;  
  10.  
  11.   my $mesg = shift;  
  12.  
  13.   $mesg =~ s/\//|/g;  
  14.  
  15.   my @number = (接收手机号,接收手机号);  
  16.  
  17.   foreach my $number ( @number ) {  
  18.  
  19.   #print “send sms to $number \n”;  
  20.  
  21.   my $send_sms_url = “http://localhost:40000/API/buddy/sms/” . $number . “/” . $mesg . ‘?rand=0.7394060082921254′;  
  22.  
  23.   my $request = HTTP::Request->new(GET => $send_sms_url);  
  24.  
  25.   my $ua = LWP::UserAgent->new;  
  26.  
  27.   $ua->timeout( 5 );  
  28.  
  29.   $ua->agent(“Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; Maxthon 2.0)”);  
  30.  
  31.   my $response = $ua->request($request);  
  32.  
  33.   my $content = $response->content();  
  34.  
  35.   }  
  36.  

  修改相应的配置文件

  修改用户及组:contacts.cfg

  添加:

  1.   define contact{  
  2.  
  3.   contact_name sms-members  
  4.  
  5.   use sms-mail-contact  
  6.  
  7.   alias Nagios Admin SMS  
  8.  
  9.   pager 138888888888  
  10.  
  11.   }  
  12.  
  13.   define contactgroup{  
  14.  
  15.   contactgroup_name admins-and-lijs  
  16.  
  17.   alias Nagios Administrators  
  18.  
  19.   members sms-members  
  20.  
  21.   }  
  22.  

  修改报警选项:templates.cfg

  1.   define contact{  
  2.  
  3.   name generic-contact  
  4.  
  5.   service_notification_period 24×7  
  6.  
  7.   host_notification_period 24×7  
  8.  
  9.   service_notification_options w,u,c,r,f,s  
  10.  
  11.   host_notification_options d,u,r,f,s  
  12.  
  13.   service_notification_commands notify-service-by-email; service-notify-by-sms  
  14.  
  15.   host_notification_commands notify-host-by-email  
  16.  
  17.   register 0  
  18.  
  19.   }  
  20.  
  21.   define contact{  
  22.  
  23.   name sms-mail-contact  
  24.  
  25.   service_notification_period 24×7  
  26.  
  27.   host_notification_period 24×7  
  28.  
  29.   service_notification_options w,u,c,r,f,s  
  30.  
  31.   host_notification_options d,u,r,f,s  
  32.  
  33.   service_notification_commands service-notify-by-sms  
  34.  
  35.   host_notification_commands notify-host-by-email  
  36.  
  37.   register 0  
  38.  
  39.   }  
  40.  

  修改调用脚本:commands.cfg

  1.   #host-notify-by-sms  
  2.  
  3.   define command {  
  4.  
  5.   command_name host-notify-by-sms  
  6.  
  7.   command_line /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nHost: $HOSTNAME$\nState:  
  8.  
  9.   $HOSTSTATE$\nWAN_IP: $HOSTALIAS$\nLAN_IP: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n” | /usr/local/nagios/lib  
  10.  
  11.   exec/sms.pl 710880931 “** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **” $CONTACTEMAIL$  
  12.  
  13.   }  
  14.  
  15.   #service notify by sms  
  16.  
  17.   define command {  
  18.  
  19.   command_name service-notify-by-sms  
  20.  
  21.   command_line /usr/local/nagios/libexec/sms/sms.pl ‘** $NOTIFICATIONTYPE$ alert – $HOSTNAME$ $SERVICEDESC$ is $SERVICESTA  
  22.  
  23.   TE$ info: $SERVICEOUTPUT$’  
  24.  
  25.   }  
  26.  

  测试下nagios情况。然后再测试报警。Nagios飞信配置就OK了。

【编辑推荐】

Nagios报错notify-by-email解决

Nagios配置文件的结构

配置Nagios监控Oracle服务器

责任编辑:zhaolei 来源: nagiostutorial
相关推荐

2011-03-23 13:32:14

Nagios飞信

2011-03-23 09:07:49

Nagios飞信

2011-03-25 13:10:08

2010-05-31 09:06:12

Nagios飞信

2011-03-24 10:08:42

Nagios飞信Linux

2011-03-23 12:55:51

NagiosMSN飞信

2011-03-24 13:00:31

Nagios飞信

2010-05-31 11:10:37

Nagios pnp

2011-03-21 09:17:06

Nagios

2011-03-31 16:05:18

Redhat配置nagios

2011-08-22 12:25:02

nagios

2011-11-08 21:58:01

Nagios 配置 流

2011-03-25 10:37:17

2011-03-25 16:49:33

nagios服务

2011-03-23 09:07:50

Nagios短信

2010-05-31 10:22:31

Nagios pnp

2011-03-28 15:22:00

nagios

2012-10-27 14:32:22

2010-05-31 12:22:13

Nagios pnp

2011-03-31 16:05:18

Redhat配置nagios
点赞
收藏

51CTO技术栈公众号