设为首页 收藏本站
查看: 1070|回复: 0

用nagios监控linux和windows服务器(七)

[复制链接]

尚未签到

发表于 2019-1-16 10:59:15 | 显示全部楼层 |阅读模式
  十一、Nagios使用飞信短信报警
  1.安装飞信机器人
  将下载下来的fetion20091117-linux.tar.gz、fetion放在/tmp下
  cd /usr/local
  tar -zxvf /tmp/fetion20091117-linux.tar.gz    //将fetion解压到/usr/local下
  mv fx fetion       //将安装目录更名为fetion
  cp /tmp/fetion /usr/local/fetion/       //将fetion文件替换成fetion补丁文件
  # 必须将libACE-5.7.2.so、libACE_SSL-5.7.2.so、libcrypto.so.4、libssl.so.4四个文件copy到/lib目录下,因为fetion是默认到/lib下找这四个文件,否则fetion将无法启动。
  cp /usr/local/fetion/libACE-5.7.2.so /lib/
  cp /usr/local/fetion/libACE_SSL-5.7.2.so /lib/
  cp /usr/local/fetion/libcrypto.so.4 /lib/
  cp /usr/local/fetion/libssl.so.4 /lib/
  2.测试飞信安装是否成功
  root@web74 fetion]# ./fetion
  出现跟下面一样的内容则表示安装成功
  ************************ IMPORTANT STATEMENT ************************
  **                                                                 **
  **   PLEASE DON'T USE THIS SOFTWARE TO SEND JUNK SHORT MESSAGES.   **
  **   OTHERWISE PLEASE BEAR YOUR OWN CONSEQUENCES.                  **
  **                                                                 **
  **                                Version:[20100721003-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]
  --add=[uri]
  --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/3 sms longsms smartmsg mms]
  --file-gb=[gb2312/gbk file]
  --file-utf8=[utf8 file]
  --query-cmcc-no
  --testaccount
  --auto-retry
  --get-web-session
  --action=getpiccode --mobile=13910000000 --pwd=[pwd] (--piccode-url=[url])
  --action=appsubscribe --mobile=[mobile] --pwd=[pwd] --pic-certificate-id=[certid] --pic-cert-code=[certcode] --apply-sub-service-url=[url]
  --action=subscribe --mobile=[mobile] --pwd=[pwd] --sms-code=[smscode] --subscribe-url=[url]
  --action=updatepwd --mobile=[mobile] --pwd=[pwd] --sms-code=[smscode] --update-pwd-url=[url]
  3.编写发送短信的脚本
  vi /usr/local/fetion/sendsms.sh
  -------------------------------------――
  #!/bin/sh
  fetionDir=/usr/local/fetion
  cd $fetionDir
  DIR=`pwd`
  # 设置发短信的号码和飞信登录密码
  user=159xxxxxxxx
  pwd=x123dsl5dow
  for phone in `cat $DIR/phonelist.txt`
  do
  echo "$phone" | sed '/^[ \t]*$/d' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//' | grep '^1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
  if (($? == 0 ));then
  if [[ -f $DIR/msg.txt ]];then
  cat /dev/null > msg.txt
  fi
  phone=`echo "$phone" | sed 's/^[ \t]*//' | sed 's/[ \t]*$//'`
  echo "sms $phone $1" >> $DIR/msg.txt
  echo "quit" >> $DIR/msg.txt
  # 下面行定义飞信发送报警短信的命令
  $fetionDir/fetion --mobile=$user --pwd=$pwd --to=$phone --msg-utf8="$1"
  else
  continue
  fi
  done
  ---------------------------------------
  # phonelist.txt为接收短信号码列表,必须是发送飞信用户的好友
  # 在此控制短信接收者面不是在nagios联系人中,好处是修改接收者后不需要重启nagios
  # 可以使用#号注释接收者的号码以屏蔽接收者
  vi /usr/local/fetion/phonelist.txt
  # Phone NO.1
  136xxxxxxxx
  # Phone NO.2
  159xxxxxxxx
  #修改飞信目录权限(否则运行Nagios的用户不能写入信息内容到/usr/local/fetion/msg.txt)
  chown -R nagios.nagios /usr/local/fetion
  chmod +x /usr/local/fetion/sendsms.sh
  chmod +x /usr/local/fetion/fetion
  4.配置Nagios
  1).定义发送飞信报警短信的命令
  vi /usr/local/nagios/etc/objects/commands.cfg
  #########################################################################
  #
  # notify-host-by-sendmsg/notify-service-by-sendmsg //定义飞信发送报警短信的命令
  #
  #########################################################################
  # 下面是定义系统报警短信命令
  define command {
  command_name notify-host-by-sendmsg
  command_line /usr/local/fetion/sendsms.sh "Host $HOSTSTATE$ alert for $HOSTNAME$($HOSTADDRESS$) on $TIME$."
  }
  # 下面是定义服务报警短信命令
  define command {
  command_name notify-service-by-sendmsg
  command_line /usr/local/fetion/sendsms.sh ""$TIME$":$SERVICEDESC$($HOSTADDRESS$) is $SERVICESTATE$."
  }
  2).定义联系人模板
  vi /usr/local/nagios/etc/objects/templates.cfg
  define contact{
  name sendmsg-contact ; The name of this contact template
  service_notification_period     24x7                    ; service notifications can be sent anytime
  host_notification_period        24x7                    ; host notifications can be sent anytime
  service_notification_options    w,u,c,s             ; send notifications for all service states, flapping events, and scheduled downtime events
  host_notification_options       d,u,s               ; send notifications for all host states, flapping events, and scheduled downtime events
  service_notification_commands notify-service-by-sendmsg ; 使用定义的飞信报警命令
  host_notification_commands notify-host-by-sendmsg ; 使用定义的飞信报警命令
  register 0 ; DONT REGISTER THIS DEFINITION ¨C ITS NOT A REAL CONTACT, JUST A TEMPLATE!
  }
  3).定义联系人及修改联系人组
  vi /usr/local/nagios/etc/objects/contacts.cfg
  # 下面是定义接收报警短信的联系人,之前已经创建了接收短信的号码文件,所以此处无需再添加联系人的手机号码
  define contact{
  contact_name msgreceiver ; Short name of user
  use sendmsg-contact ; 使用上面定义的联系人模板
  alias MsgReceiver ; Full name of user
  email xuanding@yxqz.net
  将新添加的联系人增加到联系人组里,将msgreceiver增加到联系人组的members行后面,联系人中间用,分隔
  5.测试故障时是否能够触发短信报警
  [root@localhost fetion]# /usr/local/fetion/sendsms.sh "nagios Host alert for"
  #显示下面信息则代表短信正常发送出去了
  159xxxxxxxx
  Send Msg to:
  TP=3 ID=823479704   LO=0 SU=0 RE=0 SI=423500854 SE=6764  MO=159xxxxxxxx GR=      ST=101  RE=1 OL=499  NN=15986367479LN=
  SIP-C/2.0 280 Send SMS OK
  T: sip:423500854@fetion.com.cn;p=6764
  I: 2
  Q: 1 M
  D: Tue, 21 Sep 2010 06:40:58 GMT
  XI: bc00ddb33ee84def8ca7ee0d42401e2a
  短信正常收到,则测试OK。




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-663932-1-1.html 上篇帖子: 用nagios监控linux和windows服务器(六) 下篇帖子: nagios安装与基本配置(二)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表