一、sendmail报警通知
1、停止系统自带的sendmail服务 # /etc/init.d/postfix stop 2、安装sendmail和mailx # yum -y install sendmail mailx 3、修改sendmail配置文件 # cp /etc/mail.rc /etc/mail.rc.bak # cat >> /etc/mail.rc << EOF set from=13260071987@139.com smtp=smtp.139.com set smtp-auth-user=13260071987@139.com smtp-auth-password=yi150935470xx smtp-auth=login EOF 4、重新启动sendmail服务 # service sendmail restart 5、发送邮件通知 # echo "I love Nagios" | mail -s '邮件主题01:Today learn Nagios' 13260071987@139.com # cat /etc/passwd | mail -s '邮件主题02:Today learn Nagios' 13260071987@139.com # mail -s '邮件主题03:Today learn Nagios' 13260071987@139.com < /etc/issue邮件通知如下图所示
手机短信通知如下图所示
二、fetion报警通知
1、安装解压rar格式的解压软件
2、下载并安装飞信的支持库
[root@fetion ~]# wget http://www.it-adv.net/fetion/linuxso_20101113.rar [root@fetion ~]# unrar x linuxso_20101113.rar -bash: /usr/local/bin/unrar: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录 [root@fetion ~]# yum -y install glibc.i686 [root@fetion ~]# unrar x linuxso_20101113.rar unrar: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory [root@fetion ~]# yum -y install libstdc++.so.6 [root@fetion ~]# yum -y install libstdc++ [root@fetion ~]# yum -y install libstdc++.so.6 [root@fetion ~]# unrar x linuxso_20101113.rar UNRAR 4.01 freeware Copyright (c) 1993-2011 Alexander Roshal Extracting from linuxso_20101113.rar Extracting libcrypto.so.4 OK Extracting libssl.so.4 OK Extracting libACE_SSL-5.7.2.so OK Extracting libACE-5.7.2.so OK All OK [root@fetion ~]# mkdir -p /usr/local/fetion/lib [root@fetion ~]# mv lib*so* /usr/local/fetion/lib/ [root@fetion ~]# echo "/usr/local/fetion/lib/" > /etc/ld.so.conf.d/fetion.conf [root@fetion ~]# ldconfig3、下载飞信可执行程序并传到服务器里
[root@fetion ~]# mv fetion /usr/local/fetion/ [root@fetion ~]# cd /usr/local/fetion/ [root@fetion fetion]# chmod 777 fetion [root@fetion fetion]# chown nagios.nagios fetion [root@fetion fetion]# ll 总用量 628 -rwxrwxrwx 1 nagios nagios 503425 9月 28 23:52 fetion drwxr-xr-x 2 root root 4096 9月 28 23:48 lib [root@fetion fetion]# ./fetion ./fetion: error while loading shared libraries: libgssapi_krb5.so.2: cannot open shared object file: No such file or directory [root@fetion ~]# yum -y install krb5-libs libgssapi_krb5.so.2 [root@fetion fetion]# ./fetion ./fetion: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory [root@fetion ~]# yum -y install libz.so.1 [root@fetion 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/]4、执行命令测试飞信能否正常发送短信
注释:第一次执行命令发送通知会提示输入验证码,这个验证码会自动保存在当前主程序目录下面,并以自已的手机号命名的一个图片,也就是下面的图面。然后再Windows下打开这个图片并输入验证码。
当第二次或者以后多次执行命令的时候已经被保存在缓存文件中了,所以就不用在此输入验证码了
[root@fetion fetion]# ./fetion --mobile=18237179590 --pwd=qinh132619 --to=18237179590 --msg-utf8="QinHeng To Allentuns" --debug [ 00:41:24.719329] [User.cpp] [1924] After connected to 221.176.31.1:8080 [ 00:41:25.128726] [User.cpp] [1464] getPublicIP:10.0.0.1 [ 00:41:25.128765] [User.cpp] [2083] Register renew time:600 [ 00:41:25.128807] [User.cpp] [1270] sending to:18237179590 [ 00:41:25.128821] [User.cpp] [1276] run,using cmcc mobile:18237179590 [ 00:41:25.133096] [User.cpp] [2228] wait send result [ 00:41:25.133885] [User.cpp] [2228] wait send result [ 00:41:25.137441] [User.cpp] [2228] wait send result SIP-C/4.0 280 Send SMS OK T: sip:165618352@fetion.com.cn;p=20472 I: 2 Q: 1 M RQ: 75003437798 L: 112 XI: c97076e9c01345eaaca6b5894e3b79df查看手机短信通知
错误解决方案:
1、如下图所示
飞信是针对移动手机端的,如果用联通的飞信客户端就会出现以下错误,请朋友们切记
三、Nagios的飞信fetion报警
1、配置文件的介绍
2、定义飞信命令
3、在模板里增加飞信报警方式
[root@NagiosServer objects]# vim templates.cfg define contact{ name generic-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 }4、重启nagios服务
[root@NagiosServer objects]# service nagios restart Running configuration check... Stopping nagios: done. Starting nagios: done.5、测试:现在停止客户端的服务,比如ssh
[root@NagiosClient etc]# netstat -tnlp |grep :22 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 4344/sshd tcp 0 0 :::22 :::* LISTEN 4344/sshd [root@NagiosClient etc]# netstat -tnlp |grep :22 |grep -v ':::' tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 4344/sshd [root@NagiosClient etc]# service sshd stop 停止 sshd: [确定] [root@NagiosClient etc]# netstat -tnlp |grep :22 |grep -v ':::'6、查看nagios日志信息
7、手机客户端查看短信通知
注释:这里有点问题,短信拆分了。也即是一条短信由于短信内容过多,拆分成了两条短信或者更多,后面会讲解如何解决这个问题
8、查看监控页面
9.启动ssh服务的时候,仍然会出发报警,依次查看
四、Nagios的139邮箱报警
1、定义command命令
[root@NagiosServer objects]# vim commands.cfg #注释:其实配置文件中已经有了email定义的command,我们只需要修改必要的参数即可,如发送者的邮箱、登陆密码等等 # 'notify-host-by-email' command definition define command{ command_name notify-host-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s '邮件主题01:Today learn Nagios' 13260071987@139.com < /etc/issue } # 'notify-service-by-email' command definition define command{ command_name notify-service-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s '邮件主题01:Today learn Nagios' 13260071987@139.com < /etc/issue }2、添加联系人组报警方式
[root@NagiosServer objects]# vim contacts.cfg define contact{ contact_name nagiosadmin use generic-contact alias Nagios Admin email 13260071987@139.com service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email pager 13260071987 }3、然后测试就可以了!在这里就不在说明
飞信报警请参考:
http://www.it-adv.net/ 飞信机器人官网:
http://dl528888.blog.51cto.com/2382721/770684 学习博文
http://school.21tx.com/2013/10/18/10247.shtml 解决安装fetino的依赖关系
http://bbs.it-adv.net/viewthread.php?action=printable&tid=156 fetion官网解决发送失败的方法
因为我在发送通知的时候报错,错误如下,本来还没有解决。也希望大神帮助
http://www.linuxidc.com/Linux/2012-08/69346.htm 验证码帮助