nagios 短信报警通知

本文介绍了如何使用Nagios通过短信网关进行报警通知,包括创建联系人、组和通知周期,修改邮件命令,以及指定监控项目的详细步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nagios 报警通知可以用多种方式实现,如通过飞信,邮件。具体参见《nagios mail告警通知》,《Nagios使用飞信短信报警》。

下面来说说使用短信网关来发送短信告警信息,这个是最为高效的方式,不过需要付费的哈。

1. 创建一个联系人

 

 

1

2

3

4

5

6

7

8

9

10

11

define contact{

        contact_name                    m_ttlsa

        alias                           ttlsa.com

        service_notification_period     nonworkhours

        host_notification_period        nonworkhours

        service_notification_options    w,u,c

        host_notification_options       d,u

        service_notification_commands   notify-service-by-sms

        host_notification_commands      notify-host-by-sms

        pager                           186xxxxxxxxx

        }

 

2. 创建一个组

 

 

1

2

3

4

5

define contactgroup{

        contactgroup_name       ops

        alias                   ops

        members                 m_ttlsa

        }

 

3. 创建个短信通知周期

 

 

1

2

3

4

5

6

7

8

9

10

11

12

# 'nonworkhours' timeperiod definition

define timeperiod{

        timeperiod_name nonworkhours

        alias           Non-Work Hours

        sunday          00:00-24:00                     ; Every Sunday of every week

        monday          00:00-08:30,17:30-24:00         ; Every Monday of every week

        tuesday         00:00-08:30,17:30-24:00         ; Every Tuesday of every week

        wednesday       00:00-08:30,17:30-24:00         ; Every Wednesday of every week

        thursday        00:00-08:30,17:30-24:00         ; Every Thursday of every week

        friday          00:00-08:30,17:30-24:00         ; Every Friday of every week

        saturday        00:00-24:00                     ; Every Saturday of every week

        }

 

4. 修改发送邮件命令

 

 

1

2

3

4

5

6

7

8

9

10

# 'notify-host-by-sms' command definition

define command {

        command_name    notify-host-by-sms

        command_line    $USER1$/sendsms.pl $CONTACTPAGER$ "Service: $SERVICEDESC$ Address: $HOSTADDRESS$  State: $SERVICESTATE$ Time: $SHORTDATETIME$ Info:$SERVICEOUTPUT$"

        }

# 'notify-service-by-sms' command definition

define command {

        command_name    notify-service-by-sms

        command_line    $USER1$/sendsms.pl $CONTACTPAGER$ "Service: $SERVICEDESC$ Address: $HOSTADDRESS$ State: $SERVICESTATE$ Time: $SHORTDATETIME$ Info:$SERVICEOUTPUT$"

        }

 

5. 发送短信

 

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

#!/usr/bin/env perl

 

use strict;

use warnings;

use POSIX "strftime";

use WWW::Curl::Easy;

use URI::Escape;

 

my $smslog = "/usr/local/nagios/var/sendsms.log";

my ($mobile, $content) = @ARGV;

my $message = uri_escape($content);

 

my $url = 'http://test.ttlsa.com:8080/sendMsg?mobile='.$mobile.'&content='.$message.'&handlerId=XXXXXX';

my $curl = WWW::Curl::Easy->new;

 

$curl->setopt(CURLOPT_HEADER,1);

$curl->setopt(CURLOPT_TIMEOUT, 1);

$curl->setopt(CURLOPT_URL, $url);

open my $response_body,">/dev/null";

$curl->setopt(CURLOPT_WRITEDATA,\$response_body);

 

my $retcode = $curl->perform;

 

if ($retcode == 0) {

        #print("time:". current_time() . " send sucess\n");

        print { open my $fh, ">>", $smslog; $fh or die } "time:". current_time() . " send sucess\n";

} else {

        #print("time:". current_time() . " Error: code " .$retcode. " ".$curl->strerror($retcode)."\n");

        print { open my $fh, ">>", $smslog; $fh or die } "time:". current_time() . " Error: code " .$retcode. " ".$curl->strerror($retcode)."\n";

}

 

sub current_time {    

        return strftime("%Y-%m-%d %H:%M:%S", localtime());

}

 

6. 指定监控项目

 

 

1

2

3

4

5

6

7

define service {

    use                 generic-service

    hostgroup_name          Mongo Servers

    service_description     Mongo Mapped Memory Usage

    check_command           check_mongodb!10.0.0.160!12345!'ttlsa'!'www.ttlsa.com'!memory_mapped!20!28

    contact_groups          ops

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值