linux上nagios3 短信+邮件报警

本文介绍如何在Nagios中配置短信报警功能。通过使用飞信机器人实现短信发送,并详细记录了配置步骤:从安装飞信机器人到编写执行脚本,再到修改Nagios配置文件,最终实现短信通知。

前提

已经架设好nagios,并且配置成功,能用邮件报警

我架设的是3.2.3版本,3.2.3版本的配置文件跟以前版本的位置不太一样,需要配置的大部分是在object目录下的文件。

邮件报警其实很简单,启动本机的sendmail服务,在联系人里将自己的邮件添加上就可以

再来说说短信报警,短信报警我使用的是 飞信机器人 http://www.it-adv.net/ ,可以直接用命令行发短信

一。 下载飞信机器人 解压到/usr/local/sms/目录 ,并在此目录编写一脚本duanxin.sh

#!/bin/sh LD_LIBRARY_PATH=/usr/local/sms /usr/local/sms/fetion --mobile=135xxxx2225 --pwd=xxxxxxxx --to=$1 --msg-gb=$2

此脚本的作用是将收短信人的手机号和短信作为参数,具体飞信机器人的命令参数,查看文档。

写好脚本后测试下,如果能受到短信,说明配置成功。

二。飞信机器人配置好后,开始配置nagios,配置文件位置在/usr/local/nagios/etc/object下

  • 首先配置command.cfg

在mail报警代码下边新添加

#mobile define command { command_name host-notify-by-sms command_line /usr/local/sms/duanxin.sh 15012345678 "Host $HOSTSTATE$ alert for $HOSTNAME$! on '$DATETIME$' " $CONTACTPAGER$ } define command { command_name service-notify-by-sms command_line /usr/local/sms/duanxin.sh 15012345678 "$HOSTNAME$/$HOSTADDRESS$/$SERVICEDESC$/$SERVICESTATE$" }

其中15012345678 是收短信的手机号吗, 第二个参数可以自己随便定制, 但是不要有空格存在,空格可以用/代替

这样command.cfg就配置好了

  • 接着再配置 templates.cfg

找到 define contact {。。。} 在默认的“notify-service-by-email ” 和notify-host-by-email 前面 添加command里面配置的 command_name

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 service-notify-by-sms,notify-service-by-email ; send service notifications via email host_notification_commands notify-host-by-sms,notify-host-by-email ; send host notifications via email register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE! }

这样就配置完成,重启nagios,有问题就可以收到短信了。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值