sunyke 发表于 2019-1-16 14:10:50

基于FreeBSD与Fetion.py,nagios的飞信告警系统

前段时间,中国移动改变的了飞信的登录认证方式,导致飞信机器人不能正常发出预警信息。而飞信机器人更新后,其只能兼容于比较新的linux内核。无奈在Freebsd上还是使用不了。没办法,唯有用其他方式,所以就找到了fetion.py 和PyFeton.py.


1.更新或者安装bash
#cd /usr/port/shell/bash
#make install clean


2.增加SMS脚本


#cd /usr/local/nagios/libexec/
#ee SMS:
--------------------------------------------------
#! /usr/local/bin/bash
cd /usr/local/nagios/libexec
if [ $# -ne 5 ];then
      phone="$1"
      passwd="$2"
      sendto="$3"
      msg="$4"
/usr/local/bin/python /usr/local/fetion/fetion.py "$phone" "$passwd"   "$sendto" "
fi
----------------------------------------------------


3.修改command.conf文件,增加如下:
----------------------------------------------------
# 'notify-service-by-sms' command definition
define command{
      command_name    notify-service-by-SMS
      command_line/usr/local/nagios/libexec/SMS mobile no. password mobile no. "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **"
      }

#'notify-host-by-sms' command definition
define command{
      command_name    notify-host-by-SMS
      command_line    /usr/local/nagios/libexec/SMS mobile no. password mobile no. "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"
      }
--------------------------------------------------------


4.修改templates.conf文件,修改如下:
---------------------------------------------------------
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-email,notify-service-by-SMS
      host_notification_commands      notify-host-by-email,notify-host-by-SMS
      register                        0                     
      }
------------------------------------------------------------


接下来我彻底地FML,有root作测试时一直可以发出信息,但用此脚本死活都不行,以为上面两个文件没足够权限,就赋了777,但是还是不行。最后唯有转到
nagios帐号下运行了,终于发现了问题所在:


原来脚本在/usr/local/nagios/libexec/下增加了一个log文件,Pyfetion.log
没赋nagios写入的权限。


#chown nagios:nagios /usr/local/nagils/libexec/Pyfetion.log







记号:由于FreeBSD的默认安装位置都系/usr/loca/,所以bash的运行路径应该
是#!/usr/local/bin/bash 而非 /usr/bin/bash














附件:http://down.运维网.com/data/2357010

页: [1]
查看完整版本: 基于FreeBSD与Fetion.py,nagios的飞信告警系统