为nagios添加告警短信发送功能

一、调试python脚本,使之能正常运行。
1.上传python脚本到服务器
2.运行脚本,如果提示suds模块不存在则需要使用easyinstall 安装suds
/usr/local/bin/SendSMS.py 13328100000 'TestMessage1' ' '
easy_install suds
3.测试脚本
/usr/local/bin/SendSMS.py 13328100000 'TestMessage2' ' '
二、修改contact配置文件,增加电话号码属性。
cd /etc/nagios/objects/
vim contacts.cfg ,修改如下:

define contact{
  contact_name guicj ; Short name of user
  use generic-contact ; Inherit default values from generic-contact template (defined above)
  alias Nagios Admin ; Full name of user

  email 18251100000@139.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
  pager 18251100000 ;cellphone number
}

三、修改command配置文件,增加自定义命令。
vim commands.cfg ,增加如下内容
# 'notify-host-by-sms' command definition
define command{
  command_name notify-host-by-sms
  command_line /usr/local/bin/SendSMS.py $CONTACTPAGER$ "*Nagios*:Host "$HOSTALIAS$" is $HOSTSTATE$! Date/Time: $DATETIME$" ""
}

# 'notify-service-by-sms' command definition
define command{
  command_name notify-service-by-sms
  command_line usr/local/bin/SendSMS.py $CONTACTPAGER$ "*Nagios*Notification Type: $NOTIFICATIONTYPE $Service: $SERVICEDESC $Host: $HOSTALIAS$ Address: $HOSTADDRESS$ State: $SERVICESTATE$ Date/Time: $LONGDATETIME$ Additional Info: $SERVICEOUTPUT$" ""
}

四、修改用户模板,使之默认调用新增命令。
vim templates.cfg
define contact{
  name generic-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,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
  host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
  service_notification_commands notify-service-by-email,notify-service-by-sms ; send service notifications via email
  host_notification_commands notify-host-by-email,notify-host-by-sms ; send host notifications via email
  register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
五、重启nagios,进行测试。

posted @ 2012-07-16 15:20  Hello! Linux 博客  Views(2213)  Comments(0Edit  收藏  举报