热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Nagios配合飞信发短信

nagios的安装在此页面 http:bbotte.blog.51cto.com62053071403997 提示:飞信接口已经不可用nagios要添加飞信报警功能,尽管网上有

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

Nagios配合飞信发短信

下面就可以给飞信的好友发送信息了

# /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/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
        }



测试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] 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


测试host发送短信:

把被监控端关机的nagios日志,HOST NOTIFICATION: linux;webserver1;DOWN;notify-host-by-fetion;CRITICAL - Host Unreachable (192.168.22.241)

[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配合飞信发短信

Nagios配合飞信发短信

Nagios配合飞信发短信

Nagios配合飞信发短信


推荐阅读
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • 本文介绍了关于apache、phpmyadmin、mysql、php、emacs、path等知识点,以及如何搭建php环境。文章提供了详细的安装步骤和所需软件列表,希望能帮助读者解决与LAMP相关的技术问题。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • 如何搭建服务器环境php(2023年最新解答)
    导读:本篇文章编程笔记来给大家介绍有关如何搭建服务器环境php的相关内容,希望对大家有所帮助,一起来看看吧。本文目录一览:1、怎么搭建p ... [详细]
  • 本文介绍了Python对Excel文件的读取方法,包括模块的安装和使用。通过安装xlrd、xlwt、xlutils、pyExcelerator等模块,可以实现对Excel文件的读取和处理。具体的读取方法包括打开excel文件、抓取所有sheet的名称、定位到指定的表单等。本文提供了两种定位表单的方式,并给出了相应的代码示例。 ... [详细]
  • 安装mysqlclient失败解决办法
    本文介绍了在MAC系统中,使用django使用mysql数据库报错的解决办法。通过源码安装mysqlclient或将mysql_config添加到系统环境变量中,可以解决安装mysqlclient失败的问题。同时,还介绍了查看mysql安装路径和使配置文件生效的方法。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • Windows下配置PHP5.6的方法及注意事项
    本文介绍了在Windows系统下配置PHP5.6的步骤及注意事项,包括下载PHP5.6、解压并配置IIS、添加模块映射、测试等。同时提供了一些常见问题的解决方法,如下载缺失的msvcr110.dll文件等。通过本文的指导,读者可以轻松地在Windows系统下配置PHP5.6,并解决一些常见的配置问题。 ... [详细]
  • 本文介绍了三种方法来实现在Win7系统中显示桌面的快捷方式,包括使用任务栏快速启动栏、运行命令和自己创建快捷方式的方法。具体操作步骤详细说明,并提供了保存图标的路径,方便以后使用。 ... [详细]
  • 负载均衡_Nginx反向代理动静分离负载均衡及rewrite隐藏路径详解(Nginx Apache MySQL Redis)–第二部分
    nginx反向代理、动静分离、负载均衡及rewrite隐藏路径详解 ... [详细]
  • 线程漫谈——线程基础
    本系列意在记录Windwos线程的相关知识点,包括线程基础、线程调度、线程同步、TLS、线程池等。进程与线程理解线程是至关重要的,每个进程至少有一个线程,进程是线程的容器,线程才是真正的执行体,线程必 ... [详细]
  • 这个问题困扰了我两天,卸载Dr.COM客户端(我们学校上网要装这个客户端登陆服务器,以后只能在网页里输入用户名和密码了),问题解决了。问题的现象:在实验室机台式机上安装openfire和sp ... [详细]
  • 1、PLSQLDeveloper记住登陆密码在使用PLSQLDeveloper时,为了工作方便希望PLSQLDeveloper记住登录Oracle的用户名和密码&#x ... [详细]
  • 找到JDK下载URL当然去官网找了。目前最新的1.8的下载URL(RPM)如下:http:download.oracle.comotn-pubjavajdk8u161-b122f3 ... [详细]
  • Telnet的使用(Telnet远程连接Linux)
    一、环境描述:客户端:Win10操作系统 ... [详细]
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有