首页 > 代码库 > Linux利用sendmail和fetion发送报警通知
Linux利用sendmail和fetion发送报警通知
一、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=yi15093547036 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格式的解压软件
[root@fetion ~]# wget http://www.rarsoft.com/rar/rarlinux-4.0.1.tar.gz [root@fetion ~]# tar xf rarlinux-4.0.1.tar.gz [root@fetion ~]# cd rar [root@fetion rar]# make mkdir -p /usr/local/bin mkdir -p /usr/local/lib cp rar unrar /usr/local/bin cp rarfiles.lst /etc cp default.sfx /usr/local/lib [root@fetion rar]# cd ..
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 ~]# ldconfig
3、下载飞信可执行程序并传到服务器里
[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" --debug [ 00:25:58.021626] [User.cpp] [1484] nav.fetion.com.cn=221.130.45.201 [ 00:25:58.022126] [User.cpp] [1506] Before connect to nav.fetion.com.cn [ 00:25:58.040545] [User.cpp] [1518] After connected to nav.fetion.com.cn [ 00:25:58.251901] [SystemConfig.cpp] [104] sipc-proxy=221.176.31.1:8080 [ 00:25:58.251944] [SystemConfig.cpp] [115] parseSystemConfig 221.176.31.1:8080 [ 00:25:58.266999] [User.cpp] [1615] Before connect to uid.fetion.com.cn:443 [ 00:25:58.313536] [User.cpp] [1628] After connect to uid.fetion.com.cn:443 [ 00:25:58.417277] [User.cpp] [1431] parseSSIResult:18237179590 165618352 20472 1012841212 101 [ 00:25:58.433929] [User.cpp] [1924] After connected to 221.176.31.1:8080 [ 00:25:58.750377] [User.cpp] [2005] Need picture authentication! [ 00:25:58.750441] [User.cpp] [756] Geting piccode..... [ 00:25:58.757552] [User.cpp] [841] get-pic-code from nav.fetion.com.cn [ 00:25:58.757603] [User.cpp] [849] Before connect to nav.fetion.com.cn [ 00:25:58.768193] [User.cpp] [862] After connected to pic-code-server HTTP/1.1 200 OK Connection: close Date: Sun, 28 Sep 2014 16:25:59 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: 2361 <?xml version="1.0" encoding="UTF-8"?><results><pic-certificate id="937e4f7d-1ec6-4b51-aeac-4e6d92ac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Axr93LKMZBO0Z59fWuloo636h0sc7YeCdH03xnqHim3SUahfRCOUEjYvTJUYyCdozya6KiijpYOtwooooAKKKKACiiigAooooAKKKKACiiigAooooA/9k=" /></results> [ 00:25:58.780389] [User.cpp] [932] Write to picture file:18237179590.jpg 图形验证码已经生成,文件名为:18237179590.jpg请识别后输入图形验证码: VYyW 您输入的识别码是:VYyW [ 00:26:25.955548] [User.cpp] [1464] getPublicIP:10.0.0.1 [ 00:26:25.955585] [User.cpp] [2083] Register renew time:600 [ 00:26:25.955642] [User.cpp] [1270] sending to:18237179590 [ 00:26:25.955657] [User.cpp] [1276] run,using cmcc mobile:18237179590 [ 00:26:25.956545] [User.cpp] [2228] wait send result [ 00:26:25.961531] [User.cpp] [2228] wait send result [ 00:26:25.967620] [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: 75003170806 L: 112 XI: 330a2e0248f142f5a3c15a0602524436
当第二次或者以后多次执行命令的时候已经被保存在缓存文件中了,所以就不用在此输入验证码了
[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、如下图所示
飞信是针对移动手机端的,如果用联通的飞信客户端就会出现以下错误,请朋友们切记
飞信报警请参考:
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 验证码帮助
本文出自 “郑彦生” 博客,请务必保留此出处http://467754239.blog.51cto.com/4878013/1559168
Linux利用sendmail和fetion发送报警通知