Chinaunix首页 | 论坛 | 博客
  • 博客访问: 32585
  • 博文数量: 8
  • 博客积分: 357
  • 博客等级: 一等列兵
  • 技术积分: 110
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-12 13:27
个人简介

IT老人

文章分类

全部博文(8)

文章存档

2017年(1)

2010年(7)

我的朋友

分类: LINUX

2010-06-17 17:26:09

利用飞信实现nagios的报警,无费用、实现简单。本文介绍使用“飞信”实现nagios的实时报警提示
 
1.注册一个移动的飞信号,假设电话为13912345678, 密码为123456
2.在IE中测试

=短信内容

 
作为内容能否发到13912345678手机上,能则以下方案可用。
 
3.编辑 fetion_send.pl
#! /usr/bin/perl
# usage: fetion_send  -f phonenumber -p password -t phonenumber
use strict;
use warnings;
use Getopt::Std;
use LWP::Simple;
my %options;
getopts('f:p:t:',\%options);
my $fetion_url="?";
my $from = "username=".$options{f};
my $password= "password=".$options{p};
my $to = "sendto=".$options{t};
my $date_command = "/bin/date";
my $date = `$date_command`; chop($date);
my $line;
my $content;
while (defined($line=)) {
while (defined($line=)) {
        $content .= $line;
}
open(LOG,">>/var/log/nagios3/fetion_notify.log");
chomp($content);
my $url= $fetion_url.$from.'&'.$password.'&'.$to.'&'.'message='.$content;
#print ("\n $url \n");
my $return =get($url);
#print ("\n $return \n");
print LOG (" Sent SMS  |$content| to $to \n");
print LOG (" fetion_send():url=|$url| \n");
print LOG (" Sent return= $return\n");
print LOG (" ----------------------------------------\n");
close(LOG);
 
3. 使 fetion_send.pl能运行, 放到/usr/lib/nagios/plugins/fetion_send.pl
    chmod +x fetion_send.pl
4.测试

#echo "测试“|/usr/lib/nagios/plugins/fetion_send.pl -f 13912345678 -p 123456   -t 13912345678

测试能否收到信息

5.编辑配置文件 notify.cfg
# 'notify-host-by-fetion' command definition
define command{
        command_name    notify-host-by-fetion
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | $USER1$/fetion_send.pl -f 13912345678 -p 123456  -t  $_CONTACTMOBILE_PHONE_NUM$
        }
# 'notify-service-by-fetion' command definition
define command{
        command_name    notify-service-by-fetion-tt
 
        command_line    /usr/bin/printf "%b" "类型: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | $USER1$/fetion_send.pl  -f 13912345678 -p 123456  -t $_CONTACTMOBILE_PHONE_NUM$
}
6. 在contact.cfg 中增加自定义变量
    _mobile_phone_num                13912345678
7.在contact的相关定义项中
 
将在原有的Email报警项中
service_notification_commands   notify-service-by-email
host_notification_commands      notify-host-by-email
 
增加飞信的报警项,也可以只用飞信报警。
service_notification_commands   notify-service-by-email,notify-service-by-fetion-tt
        host_notification_commands      notify-host-by-email,notify-service-by-fetion-tt
注意还要开启报警通知,也就是,设
host_notifications_enabled      1
service_notifications_enabled   1
 
8.主机和服务状态发生变化将会通过“飞信”报警到你手机上。
 
阅读(733) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-06-20 10:08:37

你好!博客狠棒If you are looking for nike air max 2010 and kobe shoes. I will tell you that MBT Shoes is well-known for its positive effect to human body. MBT is one technology originally, MBT Shoes clearance sale, it began in Masai which is a tribe of Eastern Africa. 回复 | 举报