monicazhang 发表于 2016-4-14 11:00:06

Nagios是怎样用飞信短信报警

来自:网络

Nagios使用飞信短信报警 以下内容摘自官方文档:viewthread ... tra=page%3D1&page=1 其中很明确的说明了下载安装的步骤: >> 安装 << 本程序为绿色程序,无需安装,下载解压后即可使用。 1. 根据您的需求,分别下载附件中的windows或者linux版本的机器人主程序(回贴后才能下载噢,请别嫌麻烦),解压(注意:主程序所在目录的路径中不要存在空格,如 c:\Program files\... 这样的目录) 下载: 以下内容需要回复才能看到 windows版本: fetion.rar (156.81 KB) fetion.rar (156.81 KB) windows版本 linux版本: fetion (491.63 KB) fetion (491.63 KB) linux版本 2. 下载机器人支持库(使用机器人以前版本的朋友可以直接忽略),把压缩包中的文件解压到主程序相同的目录 windows 版本:fetion/win32dll_20101113.rar linux版本:fetion/linuxso_20101113.rar (在Redhat4 下编译,其它LINUX发行版的朋友请测试) linux64位(centos5.4)版本: fetion/cenos54X64_20101113.rar (感谢QQ“走過你的風”网友提供。Centos5.4 64位linux系统下,如果用上面提供的linux版本动态库,会提示Segmentation fault,程序异常退出) (为何分开下载?因为机器人主程序经常更新,而支持库不会更新) 注意:linux用户,请不要把支持库中的 lib* 复制到 /usr/lib 下,因为发行版本不同,可能会覆盖您机器中的核心库,导致严重系统问题。                     nagios培训
您可以把库解压到主程序的相同目录,然后以 LD_LIBRARY_PATH=. ./fetion 来运行) >> 使用说明 << 以下参数提供登录用的账号密码(三种方式,手机号-密码 飞信号-密码 文件--索引) --mobile=[手机号] 登录手机号 --sid=[飞信号] 登录飞信号 --pwd=[密码] 登录密码 --config=[文件名] 存储手机号、密码的文件。 --index=[索引号] 索引 以下参数提供接收者 --to=[手机号/飞信号/URI] 接收消息的手机号/飞信号/URI.如果知道对方URI,则只需自己在对方好友列表,无需对方在自己好友列表就能发送。 支持多个号码,中间用,逗号分隔 --msg-utf8=[信息] 发送的消息,UTF8编码 --msg-gb=[信息] 发送的消息,GB编码 --file-utf8=[文件utf8格式] 发送文件内容 --file-gb=[文件gb格式] 发送文件内容 --msg-type= 发送消息类型:普通消息 长消息 智能短信 小工具 --query-cmcc-no 查询移动公司手机段 以下为可选项 --debug 显示调试信息 --hide 隐身登录 --exit-on-verifycode 服务器需要进行图形验证时,程序退出(1)或者等待用户手工输入识别信息(程序默认) --proxy-ip=http代理ip --proxy-port=http代理端口 (机器人需要 HTTP CONNECT代理,大家常用的 ccproxy 是支持的) >> 举例 << 以下为 windows 下举例: fetion --mobile=13711123456 --pwd=mypwd --to=137xxxxxxxx --msg-gb=测试 fetion --sid=6630321 --pwd=mypwd --to=137xxxxxxxx --msg-gb=测试 fetion --config=sample.conf --index=1 --to=137xxxxxxxx --msg-gb=测试 linux下,请使用如下命令: LD_LIBRARY_PATH=. ./fetion --mobile=13711123456 --pwd=mypwd --to=137xxxxxxxx --msg-utf8=测试 LD_LIBRARY_PATH=. ./fetion --sid=6630321 --pwd=mypwd --to=137xxxxxxxx --msg-utf8=测试 LD_LIBRARY_PATH=. ./fetion --config=sample.conf --index=1 --to=137xxxxxxxx --msg-utf8=测试 发送消息中如果需要换行,请用 \n // 以下为 sample.conf 内容,文件内容中, #号为注释行 # This config file is for fetion robot tool. # Usage demo: ./fetion --config=/etc/fetion.conf --index=1 # ID Mobile Password 1 137xxxx 1234234 1、下载飞信机器人&准备工作 下载地址: 注意: 1.1、下载主程序 首先要下载fetion机器人主程序,由于ITIL先锋论坛设定,必须要回复才能看到,所以无法直接通过wget下载 1.2、下载机器人支持库 ReaHat和CentOS用户应使用LINUX X86/32(REDHAT ES4X32)版。
                      nagios实施
下载链接:fetion/linuxso_20101113.rar 51CTO共享的下载链接:data/209362# 64位系统的用户可以下载64位版 下载链接:fetion/cenos54X64_20101113.rar 注:经过实践,64位系统的类库会有Segmentation fault错误 所以还是下载32位版本的,按照顺序安装配置,测试通过 cd /usr/local/src/tarbag wget fetion/linuxso_20101113.rar 1.3、安装rar for linux 由于下载的是rar包,所以要解压rar包,需安装相关的rar解压工具 下载地址:download.htm 我本地是64位的系统,所以要注意下载64位的包 cd /usr/local/src/tarbag wget rar/rarlinux-x64-4.1.1.tar.gz tar zxvf rarlinux-x64-4.1.1.tar.gz -C ../software cd ../software/rar/ make 排错 安装完以后执行 rar和unrar命令会出现如下错误: rar: /lib64/libc.so.6: version `GLIBC_2.7' not found (required by rar) unrar: /lib64/libc.so.6: version `GLIBC_2.7' not found (required by unrar) 这个时候不要慌张,执行下列命令 yes|cp rar_static /usr/local/bin/rar && yes|cp rar_static /usr/local/bin/unrar
                                    监控软件
参考: ... 322011102162817732/ 这样就安装好了,安装后就有了rar和unrar这两个程序,rar是压缩程序,unrar是解压程序。它们的参数选项很多,举例说明一下其用法 rar a all *.jpg 这条命令是将所有.jpg的文件压缩成一个rar包,名为all.rar,该程序会将.rar 扩展名将自动附加到包名后。 unrar e all.rar 这条命令是将all.rar中的所有文件解压出来。 注: 可能部分系统安装时会出现问题,如果觉得麻烦,可以直接在Win下解压好再传至Linux服务器 2、安装飞信机器人 2.1、首先,解压下载好的rar包 cd /usr/local/src/tarbag/ mkdir /usr/local/src/software/fetion/ cp linuxso_20101113.rar ../software/fetion/ cd ../software/fetion/ unrar linuxso_20101113.rar cp lib* /usr/lib/ 2.2、接下来只要把fetion主程序放到一个方便调用的地方,我放的位置是/usr/local/fetion/ cd /usr/local/src/software/ cp fetion /usr/local/fetion/ 经测试,不需要任何多余的文件,只需要fetion主程序即可 3、测试安装是否成功 3.1、执行下面命令,得到如下提示即表示安装成功 ./fetion ************************ IMPORTANT STATEMENT ************************ ** ** ** PLEASE DON'T USE THIS SOFTWARE TO SEND JUNK SHORT MESSAGES. ** ** OTHERWISE PLEASE BEAR YOUR OWN CONSEQUENCES. ** ** ** ** Version: ** ********************************************************************* This program is the console version of China Fetion! It's free for personal user. This project website:AUTHOR:KelvinH MSN/EMAIL:shichangguo@msn.com Usage: --mobile= --sid= --pwd= --config= *format:index mobile password --index= --debug *debug mode on --hide *login fetion in hidden state --to= --command-path= --robotmode --daemon(linux only) --proxy-ip(http proxy ip) --proxy-port(http proxy port) --msg-gb= --msg-utf8= --msg-type= --file-gb= --file-utf8= --query-cmcc-no --auto-retry --exit-on-verifycode --t3key= 3.2、发送短信测试 测试的参数如下所示,带--debug选项可以查看发送详情 ./fetion --mobile=139******** --pwd=mypass --to=139******** --msg-utf8="system error go to sleep" --debug [ 23:56:55.644046] After connected to 221.176.31.45:8080 [ 23:56:56.668260] getPublicIP:107.6.15.235 [ 23:56:56.668287] Register renew time:600 [ 23:56:56.668337] sending to:13950415178 [ 23:56:56.668354] run,using cmcc mobile:13950415178 [ 23:56:56.669028] wait send result SIP-C/4.0 280 Send SMS OK T: sip:778666014@ ;p=5405 I: 2 Q: 1 M L: 115 D: Thu, 15 Mar 2012 15:56:56 GMT XI: 959C5DFD2CDFA2702E20CAD606382916 得到如上提示即表示成功,恭喜你将收到一条短信了
                  nagios配置
4、编写发送脚本 vi /usr/local/fetion/sendsms.sh #!/bin/susr/local/fetion/fetion --mobile=139******** --pwd=mypass --to=$1 --msg-utf8=$2 此脚本的作用是将收短信人的手机号和短信作为参数,具体飞信机器人的命令参数,查看文档。 写好脚本后测试下,如果能收到短信,说明配置成功。 5、配置nagios 5.1、配置command.cfg 在mail报警代码下边新添加 ################################################################################ # # notify-host-by-sendmsg/notify-service-by-sendmsg //定义发送飞信报警的命令 # ################################################################################ # 'notify-host-by-sms' command definition define command { command_name notify-host-by-sms command_line /usr/local/fetion/sendsms.sh 13950415178 "Host $HOSTSTATE$ alert for $HOSTNAME$! on '$DATETIME$' " $CONTACTPAGER$ } # 'notify-service-by-sms' command definition define command { command_name notify-service-by-sms command_line /usr/local/fetion/sendsms.sh 13950415178 "$HOSTNAME$/$HOSTADDRESS$/$SERVICEDESC$/$SERVICESTATE$" } 这样command.cfg就配置好了 注: 其中139********就是sendsms中的$1,多个电话号码可用逗号分割开 双引号中的内容可随意定义,届时就是服务器故障时发送的短信内容,其中的变量值在resource.cfg。 5.2、配置 templates.cfg 找到define contact {,然后将notify-service-by-sms,notify-host-by-sms插入如下位置 define contact { name generic-contact ; The name of this contact template ...... service_notification_commands notify-service-by-email,notify-service-by-sms ; send service notifications via email & sms host_notification_commands notify-host-by-email,notify-host-by-sms ; send host notifications via email & sms } 或者添加如下内容 define contact{ name sendmsg-contact ; The name of this contact template service_notification_period 24x7 ; service notifications can be sent anytime host_notification_period 24x7 ; host notifications can be sent anytime service_notification_options w,u,c,s ; send notifications for all service states, flapping events, and scheduled downtime events host_notification_options d,u,s ; send notifications for all host states, flapping events, and scheduled downtime events service_notification_commands notify-service-by-sendmsg ; 使用定义的飞信报警命令 host_notification_commands notify-host-by-sendmsg ; 使用定义的飞信报警命令 register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE! } 5.3、配置contacts.cfg 如果采用email和sms同时发送的方式就无需修改了,如果采用只发送sms的话,可以将contacts.cfg的内容修改为如下内容 vi /usr/local/nagios/etc/objects/contacts.cfg define contact{ contact_name msgreceiver ; Short name of user use sendmsg-contact ; 使用上面定义的联系人模板 alias MsgReceiver ; Full name of user email admin@xxxx } define contactgroup{ contactgroup_name admins-sendmsg alias SMS Monitor members msgreceiver ;与上面定义的contact_name对应 }                          开源监控软件                         nagios安装

6、测试故障时是否能够触发短信报警 手动停止http服务 nagios的默认监控周期是5分钟,每一分钟重试1次,重试3次后无法连接上就会发送短信到手机上 所以,最长8分钟短信就如约发到手机上 如果要调整监控的周期,可以修改templates.cfg中的相关参数 define host{ name linux-server ; The name of this host template use generic-host ; This template inherits other values from the generic-host template check_period 24x7 ; By default, Linux hosts are checked round the clock check_interval 5 ; Actively check the host every 5 minutes retry_interval 1 ; Schedule host check retries at 1 minute intervals max_check_attempts 10 ; Check each Linux host 10 times (max) check_command check-host-alive ; Default command to check Linux hosts notification_period workhours ; Linux admins hate to be woken up, so we only notify during the day ; Note that the notification_period variable is being overridden from ; the value that is inherited from the generic-host template! notification_interval 120 ; Resend notifications every 2 hours notification_options d,u,r ; Only send notifications for specific host states contact_groups admins ; Notifications get sent to the admins by default register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE! }


想做Nagios, Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流QQ群号 :476809427
页: [1]
查看完整版本: Nagios是怎样用飞信短信报警