nagios 短信报警通知
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
}
|
收 藏
成长的对话版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!