2013年4月2日星期二

Nagios飞信linux短信报警脚本配置


Nagios飞信linux短信报警脚本配置
1.编写发送脚本

  1. vi sendsms.sh  
  2.  
  3. #!/bin/bash  
  4.  
  5. fetionDir=/usr/local/fetion/  
  6.  
  7. cd $fetionDir  
  8.  
  9. DIR=`pwd`  
  10.  
  11. user=13724506486 
  12.  
  13. pwd=gjb88888 
  14.  
  15. for phone in `cat $DIR/phonelist.txt`  
  16.  
  17. do  
  18.  
  19. 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]‘  
  20.  
  21. if (($? == 0 ));then  
  22.  
  23. if [[ -f $DIR/msg.txt ]];then  
  24.  
  25. echo "================" >> msg.txt  
  26.  
  27. fi  
  28.  
  29. phone=`echo "$phone" | sed ‘s/^[ \t]*//’ | sed ‘s/[ \t]*$//’`  
  30.  
  31. echo "sms $phone $1" >> $DIR/msg.txt  
  32.  
  33. echo "quit" >> $DIR/msg.txt  
  34.  
  35. $fetionDir/fetion –mobile=$user –pwd=$pwd –to=$phone –msg-utf8="$1" 
  36.  
  37. else  
  38.  
  39. continue  
  40.  
  41. fi  
  42.  
  43. done  
  44.  

2.接收者电话号码Nagios飞信

  1. vi /usr/local/fetion/phonelist.txt  
  2.  
  3. #hugwww  
  4.  
  5. 13724506486  
  6.  

3.修改飞信目录权限(否则运行Nagios的用户不能写入信息内容到/usr/local/fetion/msg.txt)

  1. chown -R nagios.nagios /usr/local/fetion  
  2.  
  3. chmod +x /usr/local/fetion/sendsms.sh  
  4.  

4.配置Nagios飞信

  1. vi commands.cfg  
  2.  
  3. ###################################################################  
  4.  
  5. #  
  6.  
  7. # notify-host-by-sendmsg/notify-service-by-sendmsg //定义发送飞信报警的命令  
  8.  
  9. #  
  10.  
  11. ###################################################################  
  12.  
  13. define command {  
  14.  
  15. command_name notify-host-by-fetion  
  16.  
  17. command_line /usr/local/fetion/sendsms.sh "Host $HOSTSTATE$ alert for $HOSTNAME$($HOSTADDRESS$) on $TIME$."  
  18.  
  19. }  
  20.  
  21. define command {  
  22.  
  23. command_name notify-service-by-fetion  
  24.  
  25. command_line /usr/local/fetion/sendsms.sh ""$TIME$":$SERVICEDESC$($HOSTADDRESS$) is $SERVICESTATE$."  
  26.  
  27. }  
  28.  

5.Nagios飞信定义联系人

  1. vi contacts.cfg  
  2.  
  3. define contact {  
  4.  
  5. contact_name admin  
  6.  
  7. alias system admin  
  8.  
  9. host_notification_period 24×7  
  10.  
  11. service_notification_period 24×7  
  12.  
  13. host_notification_options d,r  
  14.  
  15. service_notification_options w,u,c,r  
  16.  
  17. service_notification_commands notify-service-by-email,notify-service-by-fetion  
  18.  
  19. host_notification_commands notify-host-by-email,notify-host-by-fetion  
  20.  
  21. email hugwww@115.com  
  22.  
  23. pager 13724506486  
  24.  
  25. }  
  26.  

6.测试Nagios飞信故障时是否能够触发短信报警

  1. /usr/local/fetion/sendsms.sh "nagios Host alert"  
  2.  

没有评论:

发表评论

在PVE使用虚拟 USB 存储设备 + ARPL 引导 DSM

  部分内容来自: https://blog.myds.cloud/archives/synoboot-usb-image-in-pve-virtual-machine.html 虚拟机建好之后,打开配置文件 nano /etc/pve/qemu-server/100.conf ...