Nagios使用飞信Robot发送报警短信

运维 系统运维
Nagios使用飞信Robot发送报警短信:Nagios是一个监控系统运行状态和网络信息的监控系统。Nagios能监控所指定的本地或远程主机以及服务,同时提供异常通知功能等。这篇文章讲述的是Nagios使用飞信Robot发送报警短信。

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 得到二进制文件。直接运行 飞信 即可:

  引用

  1.   [root@cacti install]# ./fetion -h  
  2.  

  Usage:

  1.   fetion -h  
  2.  
  3.   -h: help  
  4.  
  5.   fetion -u mobile -p pwd [-b batchfile] [-EN] [-d]  
  6.  
  7.   fetion -c [config_file] -id [n] [-EN] [-d]  
  8.  
  9.   -u: fetion user account(only supports mobile phone No.)  
  10.  
  11.   -p: Account password  
  12.  
  13.   -b: Batch file name  
  14.  
  15.   -d: Debug on and write logs to [mobile]-debug.log  
  16.  
  17.   -c: config file name, refer to fetion.conf  
  18.  
  19.   -i: id, refer to fetion.conf  
  20.  
  21.   -EN: English  
  22.  
  23.   [root@cacti install]#  
  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 中的报警信息以及要通知的手机号码格式化的输入到其他文本中。这里的“格式化”是符合 飞信 脚本模式的格式化。在输出完成后,调用 飞信 去依照文本发短信。

  我修改的内容是让脚本支持一次通知多个手机。

  1.   #!/usr/bin/perl  
  2.  
  3.   use strict;  
  4.  
  5.   use Fcntl qw(:flock);  
  6.  
  7.   open SMS, "]/tmp/sms.txt" or die "NO OK";  
  8.  
  9.   flock(SMS,LOCK_EX);  
  10.  
  11.   my @mobile = split /\s+/, $ARGV[1];  
  12.  
  13.   foreach (@mobile) {  
  14.  
  15.   print SMS "sms $_ $ARGV[0]\n";  
  16.  
  17.   }  
  18.  
  19.   print SMS "quit\n";  
  20.  
  21.   system "/usr/bin/fetion -u 136xxxxxx -p xxxxxxxx -b /tmp/sms.txt";  
  22.  
  23.   #unlink "/home/sms/sms.txt";  
  24.  
  25.   flock(SMS,LOCK_UN);  
  26.  
  27.   close SMS;  
  28.  
  29.   #unlink "/home/sms/sms.txt";  
  30.  

  推荐将此脚本放在nagios/libexec/下。

  记得在 /tmp 下创建 sms.txt 文件,777。

#p#

  四、Nagios 配置

  nagios 配置2个点:

  1.定义短信提醒方式。调用前面写的 perl 脚本。同时将报警信息和手机号码传入脚本。

  2.定义管理员接受报警方式。

  直接贴配置文件了:

  定义短信提醒调用脚本

  1.   define command {  
  2.  
  3.   command_name host-notify-by-sms  
  4.  
  5.   command_line /usr/local/nagios/libexec/sms "IP: $HOSTADDRESS$($HOSTNAME$) is $HOSTSTATE$\n$SHORTDATETIME$" "$CONTACTPAGER$"  
  6.  
  7.   }  
  8.  
  9.   define command {  
  10.  
  11.   command_name service-notify-by-sms  
  12.  
  13.   command_line /usr/local/nagios/libexec/sms "'$HOSTADDRESS$' $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" "$CONTACTPAGER$"  
  14.  
  15.   }  
  16.  

  定义管理员接受报警方式

  1.   define contact{  
  2.  
  3.   contact_name nagiosadmin ; Short name of user  
  4.  
  5.   use generic-contact ; Inherit default values from generic-contact template (defined above)  
  6.  
  7.   alias Nagios Admin ; Full name of user  
  8.  
  9.   service_notification_commands notify-service-by-email,service-notify-by-sms  
  10.  
  11.   host_notification_commands notify-host-by-email,host-notify-by-sms  
  12.  
  13.   email youremailaddress;  
  14.  
  15.   pager 136xxxxxxx 136xxxxxx  
  16.  
  17.   }  
  18.  

【编辑推荐】

配置Nagios监控Oracle服务器

Nagios监控系统搭建问题

Nagios监控全解-手机短信

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

2011-03-23 12:55:51

NagiosMSN飞信

2011-03-23 09:07:49

Nagios飞信

2011-03-23 13:32:14

Nagios飞信

2011-03-24 10:08:42

Nagios飞信Linux

2011-03-25 13:10:08

2010-05-31 09:06:12

Nagios飞信

2011-03-24 09:15:54

Nagios飞信

2011-04-06 14:24:18

2011-03-23 09:07:50

Nagios短信

2011-03-22 16:31:27

Nagios

2011-03-24 08:56:23

escalationsNagios报警

2014-03-12 16:09:21

Zabbix短信报警

2012-08-06 10:19:36

2011-03-21 15:44:52

escalationsNagios

2011-03-24 08:56:21

Nagios邮件

2011-03-25 14:56:43

Nagiosescalations

2011-04-01 17:01:11

Zabbix短信

2012-02-02 17:10:35

Windows PhoC#发送短信

2011-03-23 14:43:09

2018-08-23 08:13:20

子弹短信微信老罗
点赞
收藏

51CTO技术栈公众号