Nagios配合飞信发短信
nagios的安装在此页面http://bbotte.blog.51cto.com/6205307/1403997
提示:飞信接口已经不可用
nagios要添加飞信报警功能,尽管网上有很多教程,不过许多都需要瞎折腾才能正常用飞信,所以下面记录一下,供参考
系统centos6.4 64位
安装飞信
下载地址http://pan.baidu.com/s/1sXpGj找到linux安装包> 飞信 >fetiontar.zip
#unzipfetiontar.zip#cdfetiontar#lsfetionlib#mkdir/usr/local/fetion#cpfetion/usr/local/fetion/#chmod755/usr/local/fetion/fetion
#lslib/#lib文件夹下的so文件ld-2.5.solibcap.so.1libcrypt.so.1libpcre.so.0.0.1ld-linux.so.2libcap.so.1.10libc.so.6libproc-3.2.7.sold-lsb.so.3libcidn-2.5.solibeay32.dlllibpthread-2.5.sold.so.conflibcidn.so.1libnss_ldap-2.5.solibpthread.so.0libACE-5.6.5.solibcom_err.so.2libnss_ldap.so.2libssl.so.0.9.7alibACE-5.6.8.solibcom_err.so.2.1libpamc.so.0libssl.so.0.9.8libACE-5.7.2.solibcrypt-2.5.solibpamc.so.0.81.0libssl.so.4libACE_SSL-5.6.5.solibcrypto.so.0.9.7alibpam_misc.so.0libstdc++.so.6libACE_SSL-5.6.8.solibcrypto.so.0.9.8libpam_misc.so.0.81.2libstdc++.so.6.0.8libACE_SSL-5.7.2.solibcrypto.so.0.9.8blibpam.so.0readmelibc-2.5.solibcrypto.so.4libpam.so.0.81.5libcap.solibcrypto.so.6libpcre.so.0
设置fetion的库文件
#cp-rlib//lib64/fetion#vim/etc/ld.so.conf.d/fetion.conf/lib64/fetion
#ldconfig-v|grepfetionldconfig:/etc/ld.so.conf.d/kernel-2.6.32-431.11.2.el6.x86_64.conf:6:duplicatehwcap1nosegnegldconfig:/lib64/fetion/libstdc++.so.6isnotasymboliclinkldconfig:/lib64/fetion/libpamc.so.0isnotasymboliclinkldconfig:/lib64/fetion/libpam_misc.so.0isnotasymboliclinkldconfig:/lib64/fetion/libpcre.so.0isnotasymboliclinkldconfig:/lib64/fetion/ld-linux.so.2isnotasymboliclinkldconfig:/lib64/fetion/libcom_err.so.2isnotasymboliclinkldconfig:/lib64/fetion/libcap.so.1isnotasymboliclinkldconfig:/lib64/fetion/libpam.so.0isnotasymboliclink/lib64/fetion:
查看缺少哪些库,然后依次安装
#ldd/usr/local/fetion/fetionlinux-gate.so.1=>(0x00e41000)libACE-5.7.2.so=>/lib64/fetion/libACE-5.7.2.so(0x007ec000)libACE_SSL-5.7.2.so=>/lib64/fetion/libACE_SSL-5.7.2.so(0x002ad000)libssl.so.4=>/lib64/fetion/libssl.so.4(0x0069d000)libstdc++.so.6=>/lib64/fetion/libstdc++.so.6(0x004f8000)libm.so.6=>/lib/libm.so.6(0x00c7d000)libgcc_s.so.1=>/lib/libgcc_s.so.1(0x00dfe000)libc.so.6=>/lib/libc.so.6(0x002c2000)libcrypto.so.4=>/lib64/fetion/libcrypto.so.4(0x03e4a000)librt.so.1=>/lib/librt.so.1(0x001d0000)libdl.so.2=>/lib/libdl.so.2(0x001d9000)libgssapi_krb5.so.2=>notfoundlibkrb5.so.3=>notfoundlibcom_err.so.2=>/lib64/fetion/libcom_err.so.2(0x001de000)libk5crypto.so.3=>notfoundlibresolv.so.2=>/lib/libresolv.so.2(0x001e1000)/lib/ld-linux.so.2(0x0070f000)libz.so.1=>notfoundlibgssapi_krb5.so.2=>notfoundlibkrb5.so.3=>notfoundlibk5crypto.so.3=>notfoundlibz.so.1=>notfoundlibpthread.so.0=>/lib/libpthread.so.0(0x0079e000)
如果缺少libgcc_s.so.1,出现下面情况,那么yum install libgcc_s.so.1
#/usr/local/fetion/fetion/usr/local/fetion/fetion:errorwhileloadingsharedlibraries:libgcc_s.so.1:cannotopensharedobjectfile:Nosuchfileordirectory
#yuminstallkrb5-libslibgssapi_krb5.so.2libz.so.1-y#/usr/local/fetion/fetion************************IMPORTANTSTATEMENT******************************PLEASEDON'TUSETHISSOFTWARETOSENDJUNKSHORTMESSAGES.****OTHERWISEPLEASEBEARYOUROWNCONSEQUENCES.********Version:[20101205002-linux]***********************************************************************ThisprogramistheconsoleversionofChinaFetion!It'sfreeforpersonaluser.Thisprojectwebsite:http://www.it-adv.net/AUTHOR:KelvinHMSN/EMAIL:shichangguo@msn.comUsage:--mobile=[mobile]--sid=[sid]--pwd=[pwd]--config=[configfile]*format:indexmobilepassword--index=[indexnoinconfigfile,refertosample.conf]--debug*debugmodeon--hide*loginfetioninhiddenstate--to=[mobile/sid]--command-path=[commandfilepath]--robotmode--daemon(linuxonly)--proxy-ip(httpproxyip)--proxy-port(httpproxyport)--msg-gb=[gb2312/gbkmessage]--msg-utf8=[utf8message]--msg-type=[0/1/2smslongsmssmartmsg]--file-gb=[gb2312/gbkfile]--file-utf8=[utf8file]--query-cmcc-no--auto-retry--exit-on-verifycode--t3key=[http://www.tui3.com/page/smssend/]
ok,飞信已经安装好了,下面测试
# /usr/local/fetion/fetion --mobile=你的手机号 --pwd=飞信密码 --to=对方的手机号 --msg-utf8="hello hero"
HTTP/1.1 200 OK
Connection: close
Date: Sat, 23 Aug 2014 09:50:19 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Location: nav.fetion.com.cn
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 2473
<?xml version="1.0" encoding="UTF-8"?><results><pic-certificate id="f9c6154e-1e8f-4fe5-bb54-61b6ac4a3a85" pic="*****(省略)"
#这里是提示输入验证码,验证码到目录,即下面的手机号.jpg 文件
# cd /usr/local/fetion/
# ls
1591425****.cache 1591425****.jpg fetion
下面就可以给飞信的好友发送信息了
# /usr/local/fetion/fetion --mobile=1591425**** --pwd=****** --to=****** --msg-utf8="hello hero,you are a man"
SIP-C/4.0 280 Send SMS OK
T: sip:1056282019@fetion.com.cn;p=7019
I: 3
Q: 1 M
RQ: 56602213092
L: 112
XI: 7df854ffd4ff4abeb840b878110fec25
----以上确定飞信可以正常使用,下面详细说明配置内容----
下面几个配置文件相互关联,commands.cfg中定义飞信发送短信的命令,contacts.cfg中说明发送短信的用户和组,templates.cfg定义触发后要执行的动作,比如发飞信或邮件,什么时候发,用那个用户发送,timeperiods.cfg定义时间,工作日或者7x24,这里我使用默认的7x24,linuxhost.cfg为自己创建的文件,定义监控的服务和主机,监控的动作
cd/usr/local/nagios/etc/objectscommands.cfg#定义飞信的发送命令definecommand{command_namenotify-host-by-fetioncommand_line/usr/local/fetion/fetion--mobile=1591425****--pwd=123456--to=1591425****--msg-utf8="$NOTIFICATIONTYPE$\nHost:$HOSTNAME$\nState:$HOSTSTATE$\nAddress:$HOSTADDRESS$\nInfo:$HOSTOUTPUT$\n\nDate/Time:$LONGDATETIME$\n"--msg-type=1}definecommand{command_namenotify-service-by-fetioncommand_line/usr/local/fetion/fetion--mobile=1591425****--pwd=123456--to=1591425****--msg-utf8="$NOTIFICATIONTYPE$\nHost:$HOSTNAME$\nState:$HOSTSTATE$\nAddress:$HOSTADDRESS$\nInfo:$HOSTOUTPUT$\n\nDate/Time:$LONGDATETIME$\n"--msg-type=1}
contacts.cfg#创建用户和用户组,定义使用飞信发送通知信息definecontact{contact_namelinuxuselinux-contactaliaslinuxserver1service_notification_period24x7host_notification_period24x7service_notification_optionsw,u,c,r,f,shost_notification_optionsd,u,r,f,sservice_notification_commandsnotify-service-by-fetionhost_notification_commandsnotify-host-by-fetion}definecontactgroup{contactgroup_namelinuxaliaslinuxgroup1memberslinux}
templates.cfg#在模板中定义检测后所要执行的选择definecontact{namelinux-contactservice_notification_period24x7host_notification_period24x7service_notification_optionsw,u,c,r,f,shost_notification_optionsd,u,r,f,sservice_notification_commandsnotify-service-by-fetionhost_notification_commandsnotify-host-by-fetionregister0}definehost{namemylinux-serverusegeneric-hostcheck_period24x7check_interval5retry_interval1max_check_attempts10check_commandcheck-host-alivenotification_period24x7notification_interval120notification_optionsd,u,rcontact_groupslinuxregister0}defineservice{namelinux-serviceactive_checks_enabled1passive_checks_enabled1parallelize_check1obsess_over_service1check_freshness0notifications_enabled1event_handler_enabled1flap_detection_enabled1failure_prediction_enabled1process_perf_data1retain_status_information1retain_nonstatus_information1is_volatile0check_period24x7max_check_attempts3normal_check_interval1retry_check_interval2contact_groupslinuxnotification_optionsw,u,c,rnotification_interval60notification_period24x7register0}
linuxhost.cfg#定义主机和监控的服务definehost{usemylinux-serverhost_namewebserver1aliaswebserver1address192.168.22.241}definehostgroup{hostgroup_namegroup1aliasLinuxgroup1memberswebserver1}defineservice{uselinux-servicehost_namewebserver1service_descriptioncheckuserscheck_commandcheck_nrpe!check_users}defineservice{uselinux-servicehost_namewebserver1service_descriptioncheckloadcheck_commandcheck_nrpe!check_load}defineservice{uselinux-servicehost_namewebserver1service_descriptioncheckzombieprocecheck_commandcheck_nrpe!check_zombie_procs}defineservice{uselinux-servicehost_namewebserver1service_descriptionchecktotalprocecheck_commandcheck_nrpe!check_total_procs}defineservice{uselinux-servicehost_namewebserver1service_descriptioncheckrootdiskcheck_commandcheck_nrpe!check_rootdisk}defineservice{uselinux-servicehost_namewebserver1service_descriptioncheckswapcheck_commandcheck_nrpe!check_swap}defineservice{uselinux-servicehost_namewebserver1service_descriptionchecksda1check_commandcheck_nrpe!check_sda1}defineservice{uselinux-servicehost_namewebserver1service_descriptionchecksda3check_commandcheck_nrpe!check_sda3}defineservice{uselinux-servicehost_namewebserver1service_descriptioncheckmysqlcheck_commandcheck_nrpe!check_mysql}
测试service发送短信:
被监控端user设置 check_users -w 3 -c 3 现在5人登录,稍后再登出
nagios日志,SERVICE NOTIFICATION: linux;webserver1;check users;CRITICAL;notify-service-by-fetion;USERS CRITICAL - 5 users currently logged in
[1409704648]SERVICEALERT:webserver1;checkusers;CRITICAL;SOFT;1;USERSCRITICAL-4userscurrentlyloggedin[1409704768]SERVICEALERT:webserver1;checkusers;CRITICAL;SOFT;2;USERSCRITICAL-5userscurrentlyloggedin[1409704888]SERVICEALERT:webserver1;checkusers;CRITICAL;HARD;3;USERSCRITICAL-5userscurrentlyloggedin[1409704888]SERVICENOTIFICATION:linux;webserver1;checkusers;CRITICAL;notify-service-by-fetion;USERSCRITICAL-5userscurrentlyloggedin[1409704948]SERVICEALERT:webserver1;checkusers;OK;HARD;3;USERSOK-1userscurrentlyloggedin[1409704948]SERVICENOTIFICATION:linux;webserver1;checkusers;OK;notify-service-by-fetion;USERSOK-1userscurrentlyloggedin
测试host发送短信:
把被监控端关机的nagios日志,HOST NOTIFICATION: linux;webserver1;DOWN;notify-host-by-fetion;CRITICAL - Host Unreachable (192.168.22.241)
[1409705298]HOSTALERT:webserver1;DOWN;HARD;10;CRITICAL-HostUnreachable(192.168.22.241)[1409705298]HOSTNOTIFICATION:linux;webserver1;DOWN;notify-host-by-fetion;CRITICAL-HostUnreachable(192.168.22.241)[1409705307]Warning:Returncodeof255forcheckofservice'checksda3'onhost'webserver1'wasoutofbounds.[1409705307]SERVICEALERT:webserver1;checksda3;UNKNOWN;HARD;3;(Returncodeof255isoutofbounds)[1409705310]Warning:Returncodeof255forcheckofservice'checkusers'onhost'webserver1'wasoutofbounds.[1409705310]SERVICEALERT:webserver1;checkusers;UNKNOWN;HARD;3;(Returncodeof255isoutofbounds)[1409705313]Warning:Returncodeof255forcheckofservice'checkload'onhost'webserver1'wasoutofbounds.[1409705313]SERVICEALERT:webserver1;checkload;UNKNOWN;HARD;3;(Returncodeof255isoutofbounds)[1409705319]SERVICEALERT:webserver1;checksda1;OK;HARD;3;DISKOK-freespace:/boot158MB(86%inode=99%):[1409705331]SERVICEALERT:webserver1;checkswap;OK;HARD;3;DISKOK-freespace:/17097MB(91%inode=94%):/dev/shm245MB(100%inode=99%):/boot158MB(86%inode=99%):[1409705335]SERVICEALERT:webserver1;checkzombieproce;OK;HARD;3;PROCSOK:0processeswithSTATE=Z[1409705335]HOSTALERT:webserver1;UP;HARD;1;PINGOK-Packetloss=0%,RTA=0.79ms[1409705335]HOSTNOTIFICATION:linux;webserver1;UP;notify-host-by-fetion;PINGOK-Packetloss=0%,RTA=0.79ms[1409705338]SERVICEALERT:webserver1;checkrootdisk;OK;HARD;3;DISKOK-freespace:/17097MB(91%inode=94%):
无图无真相
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。