nagios的安装在此页面 http://bbotte.blog.51cto.com/6205307/1403997
在灌云等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站建设、成都网站制作 网站设计制作按需求定制制作,公司网站建设,企业网站建设,高端网站设计,网络营销推广,成都外贸网站制作,灌云网站建设费用合理。提示:飞信接口已经不可用
nagios要添加飞信报警功能,尽管网上有很多教程,不过许多都需要瞎折腾才能正常用飞信,所以下面记录一下,供参考
系统centos6.4 64位
安装飞信
下载地址 http://pan.baidu.com/s/1sXpGj 找到linux安装包 > 飞信 >fetiontar.zip
# unzip fetiontar.zip # cd fetiontar # ls fetion lib # mkdir /usr/local/fetion # cp fetion /usr/local/fetion/ # chmod 755 /usr/local/fetion/fetion
# ls lib/ #lib文件夹下的so文件 ld-2.5.so libcap.so.1 libcrypt.so.1 libpcre.so.0.0.1 ld-linux.so.2 libcap.so.1.10 libc.so.6 libproc-3.2.7.so ld-lsb.so.3 libcidn-2.5.so libeay32.dll libpthread-2.5.so ld.so.conf libcidn.so.1 libnss_ldap-2.5.so libpthread.so.0 libACE-5.6.5.so libcom_err.so.2 libnss_ldap.so.2 libssl.so.0.9.7a libACE-5.6.8.so libcom_err.so.2.1 libpamc.so.0 libssl.so.0.9.8 libACE-5.7.2.so libcrypt-2.5.so libpamc.so.0.81.0 libssl.so.4 libACE_SSL-5.6.5.so libcrypto.so.0.9.7a libpam_misc.so.0 libstdc++.so.6 libACE_SSL-5.6.8.so libcrypto.so.0.9.8 libpam_misc.so.0.81.2 libstdc++.so.6.0.8 libACE_SSL-5.7.2.so libcrypto.so.0.9.8b libpam.so.0 readme libc-2.5.so libcrypto.so.4 libpam.so.0.81.5 libcap.so libcrypto.so.6 libpcre.so.0
设置fetion的库文件
# cp -r lib/ /lib64/fetion # vim /etc/ld.so.conf.d/fetion.conf /lib64/fetion
# ldconfig -v|grep fetion ldconfig: /etc/ld.so.conf.d/kernel-2.6.32-431.11.2.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg ldconfig: /lib64/fetion/libstdc++.so.6 is not a symbolic link ldconfig: /lib64/fetion/libpamc.so.0 is not a symbolic link ldconfig: /lib64/fetion/libpam_misc.so.0 is not a symbolic link ldconfig: /lib64/fetion/libpcre.so.0 is not a symbolic link ldconfig: /lib64/fetion/ld-linux.so.2 is not a symbolic link ldconfig: /lib64/fetion/libcom_err.so.2 is not a symbolic link ldconfig: /lib64/fetion/libcap.so.1 is not a symbolic link ldconfig: /lib64/fetion/libpam.so.0 is not a symbolic link /lib64/fetion:
查看缺少哪些库,然后依次安装
# ldd /usr/local/fetion/fetion linux-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 => not found libkrb5.so.3 => not found libcom_err.so.2 => /lib64/fetion/libcom_err.so.2 (0x001de000) libk5crypto.so.3 => not found libresolv.so.2 => /lib/libresolv.so.2 (0x001e1000) /lib/ld-linux.so.2 (0x0070f000) libz.so.1 => not found libgssapi_krb5.so.2 => not found libkrb5.so.3 => not found libk5crypto.so.3 => not found libz.so.1 => not found libpthread.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: error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory
# yum install krb5-libs libgssapi_krb5.so.2 libz.so.1 -y # /usr/local/fetion/fetion ************************ IMPORTANT STATEMENT ************************ ** ** ** PLEASE DON'T USE THIS SOFTWARE TO SEND JUNK SHORT MESSAGES. ** ** OTHERWISE PLEASE BEAR YOUR OWN CONSEQUENCES. ** ** ** ** Version:[20101205002-linux] ** ********************************************************************* This program is the console version of China Fetion! It's free for personal user. This project website: http://www.it-adv.net/ AUTHOR:KelvinH MSN/EMAIL:shichangguo@msn.com Usage: --mobile=[mobile] --sid=[sid] --pwd=[pwd] --config=[config file] *format:index mobile password --index=[index no in config file,refer to sample.conf] --debug *debug mode on --hide *login fetion in hidden state --to=[mobile/sid] --command-path=[command file path] --robotmode --daemon(linux only) --proxy-ip(http proxy ip) --proxy-port(http proxy port) --msg-gb=[gb2312/gbk message] --msg-utf8=[utf8 message] --msg-type=[0/1/2 sms longsms smartmsg] --file-gb=[gb2312/gbk file] --file-utf8=[utf8 file] --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
#这里是提示输入验证码,验证码到目录,即下面的手机号.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为自己创建的文件,定义监控的服务和主机,监控的动作 测试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 测试host发送短信: 把被监控端关机的nagios日志,HOST NOTIFICATION: linux;webserver1;DOWN;notify-host-by-fetion;CRITICAL - Host Unreachable (192.168.22.241) 无图无真相 另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。cd /usr/local/nagios/etc/objects
commands.cfg #定义飞信的发送命令
define command {
command_name notify-host-by-fetion
command_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
}
define command {
command_name notify-service-by-fetion
command_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 #创建用户和用户组,定义使用飞信发送通知信息
define contact{
contact_name linux
use linux-contact
alias linux server1
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,f,s
host_notification_options d,u,r,f,s
service_notification_commands notify-service-by-fetion
host_notification_commands notify-host-by-fetion
}
define contactgroup{
contactgroup_name linux
alias linux group1
members linux
}
templates.cfg #在模板中定义检测后所要执行的选择
define contact{
name linux-contact
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,f,s
host_notification_options d,u,r,f,s
service_notification_commands notify-service-by-fetion
host_notification_commands notify-host-by-fetion
register 0
}
define host{
name mylinux-server
use generic-host
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 120
notification_options d,u,r
contact_groups linux
register 0
}
define service{
name linux-service
active_checks_enabled 1
passive_checks_enabled 1
parallelize_check 1
obsess_over_service 1
check_freshness 0
notifications_enabled 1
event_handler_enabled 1
flap_detection_enabled 1
failure_prediction_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 1
retry_check_interval 2
contact_groups linux
notification_options w,u,c,r
notification_interval 60
notification_period 24x7
register 0
}
linuxhost.cfg #定义主机和监控的服务
define host{
use mylinux-server
host_name webserver1
alias webserver1
address 192.168.22.241
}
define hostgroup{
hostgroup_name group1
alias Linux group1
members webserver1
}
define service{
use linux-service
host_name webserver1
service_description check users
check_command check_nrpe!check_users
}
define service{
use linux-service
host_name webserver1
service_description check load
check_command check_nrpe!check_load
}
define service{
use linux-service
host_name webserver1
service_description check zombie proce
check_command check_nrpe!check_zombie_procs
}
define service{
use linux-service
host_name webserver1
service_description check total proce
check_command check_nrpe!check_total_procs
}
define service{
use linux-service
host_name webserver1
service_description check rootdisk
check_command check_nrpe!check_rootdisk
}
define service{
use linux-service
host_name webserver1
service_description check swap
check_command check_nrpe!check_swap
}
define service{
use linux-service
host_name webserver1
service_description check sda1
check_command check_nrpe!check_sda1
}
define service{
use linux-service
host_name webserver1
service_description check sda3
check_command check_nrpe!check_sda3
}
define service{
use linux-service
host_name webserver1
service_description check mysql
check_command check_nrpe!check_mysql
}
[1409704648] SERVICE ALERT: webserver1;check users;CRITICAL;SOFT;1;USERS CRITICAL - 4 users currently logged in
[1409704768] SERVICE ALERT: webserver1;check users;CRITICAL;SOFT;2;USERS CRITICAL - 5 users currently logged in
[1409704888] SERVICE ALERT: webserver1;check users;CRITICAL;HARD;3;USERS CRITICAL - 5 users currently logged in
[1409704888] SERVICE NOTIFICATION: linux;webserver1;check users;CRITICAL;notify-service-by-fetion;USERS CRITICAL - 5 users currently logged in
[1409704948] SERVICE ALERT: webserver1;check users;OK;HARD;3;USERS OK - 1 users currently logged in
[1409704948] SERVICE NOTIFICATION: linux;webserver1;check users;OK;notify-service-by-fetion;USERS OK - 1 users currently logged in
[1409705298] HOST ALERT: webserver1;DOWN;HARD;10;CRITICAL - Host Unreachable (192.168.22.241)
[1409705298] HOST NOTIFICATION: linux;webserver1;DOWN;notify-host-by-fetion;CRITICAL - Host Unreachable (192.168.22.241)
[1409705307] Warning: Return code of 255 for check of service 'check sda3' on host 'webserver1' was out of bounds.
[1409705307] SERVICE ALERT: webserver1;check sda3;UNKNOWN;HARD;3;(Return code of 255 is out of bounds)
[1409705310] Warning: Return code of 255 for check of service 'check users' on host 'webserver1' was out of bounds.
[1409705310] SERVICE ALERT: webserver1;check users;UNKNOWN;HARD;3;(Return code of 255 is out of bounds)
[1409705313] Warning: Return code of 255 for check of service 'check load' on host 'webserver1' was out of bounds.
[1409705313] SERVICE ALERT: webserver1;check load;UNKNOWN;HARD;3;(Return code of 255 is out of bounds)
[1409705319] SERVICE ALERT: webserver1;check sda1;OK;HARD;3;DISK OK - free space: /boot 158 MB (86% inode=99%):
[1409705331] SERVICE ALERT: webserver1;check swap;OK;HARD;3;DISK OK - free space: / 17097 MB (91% inode=94%): /dev/shm 245 MB (100% inode=99%): /boot 158 MB (86% inode=99%):
[1409705335] SERVICE ALERT: webserver1;check zombie proce;OK;HARD;3;PROCS OK: 0 processes with STATE = Z
[1409705335] HOST ALERT: webserver1;UP;HARD;1;PING OK - Packet loss = 0%, RTA = 0.79 ms
[1409705335] HOST NOTIFICATION: linux;webserver1;UP;notify-host-by-fetion;PING OK - Packet loss = 0%, RTA = 0.79 ms
[1409705338] SERVICE ALERT: webserver1;check rootdisk;OK;HARD;3;DISK OK - free space: / 17097 MB (91% inode=94%):
文章题目:Nagios配合飞信发短信-创新互联
文章起源:http://kswsj.cn/article/dhdied.html