line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Zabbix::APP; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17200
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
536
|
use Mojo::Zabbix; |
|
1
|
|
|
|
|
232918
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
8
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
3
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
25
|
use POSIX qw(strftime); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
our @EXPORT = qw(initZ pVersion getAllhost getname getItem pHitems pTriggers); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=encoding utf8 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Mojo::Zabbix::APP - The application module of Mojo-Zabbix .Using to get |
20
|
|
|
|
|
|
|
data from zabbix data include host,items, Triggers and warns and so on. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 VERSION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Version 0.04 |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use Mojo::Zabbix::APP; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my @myzinfo = ; ##(get zabbix info from __DATA__ ) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Define for debug and traceing processe infomaition。(打开调试和跟踪) |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $DEBUG=0; |
40
|
|
|
|
|
|
|
my $TRACE=0; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#my @myzinfo = ('test1 http://test1/zabbix testuser pass'); |
43
|
|
|
|
|
|
|
# @可以定义为多行数据,格式按照这种,一个zabbix 服务地址一个 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
for (@myzinfo) { |
46
|
|
|
|
|
|
|
next if /^#/; |
47
|
|
|
|
|
|
|
next if /^\s*$/; |
48
|
|
|
|
|
|
|
my ( $name, $url,$user, $pass ) = split; |
49
|
|
|
|
|
|
|
print "\n$name\n"; |
50
|
|
|
|
|
|
|
my $z; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
eval { $z = initZ( $url,$user,$pss ); }; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
if ($@) { |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
print "Error $@!\n"; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
## Print the version of zabbix api. 打印zabbix 版本 |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
pVersion($z); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
## Print all host lists。 获取所有的主机列表 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
print getAllhost($z); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
## Print warning info of Triggers。打印取得的所有触发器告警信息 |
69
|
|
|
|
|
|
|
pTriggers($z); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
## Print the history data of given items, default for past 24 hours. |
72
|
|
|
|
|
|
|
## 打印给定时间段的item历史数据,如果默认不给时间默认为过去24小时内的 |
73
|
|
|
|
|
|
|
pHitems($z); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#### 初始化的Mojo::zabbix ,必须安装Mojo::zabbix模块,可用cpanm Mojo::zabbix 安装 |
81
|
|
|
|
|
|
|
my %EVcache; |
82
|
|
|
|
|
|
|
my %HTcache; |
83
|
|
|
|
|
|
|
## 缓存hash 对事件id进行缓存,防止重复调用 |
84
|
|
|
|
|
|
|
my $DEBUG = 0; |
85
|
|
|
|
|
|
|
my $TRACE = 0; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub initZ { |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
0
|
|
my ( $url, $user, $pass ) = @_; |
90
|
0
|
0
|
|
|
|
|
print "debug-initZ { parameter } : $url, $user, $pass \n" if $DEBUG; |
91
|
0
|
|
|
|
|
|
my $zbbix = Mojo::Zabbix->new( |
92
|
|
|
|
|
|
|
url => $url, |
93
|
|
|
|
|
|
|
username => $user, |
94
|
|
|
|
|
|
|
password => $pass, |
95
|
|
|
|
|
|
|
debug => $DEBUG, |
96
|
|
|
|
|
|
|
trace => $TRACE, |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
### 打印zabbix 版本 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub pVersion { |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
0
|
0
|
|
my $z = shift; |
106
|
0
|
|
|
|
|
|
my $r = $z->get( "apiinfo.version", ); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $result = $r->{'result'}; |
109
|
0
|
|
|
|
|
|
return $result, "\n"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
### 打印给定时间段的item历史数据,如果默认不给时间默认为过去24小时内的 |
113
|
|
|
|
|
|
|
sub pHitems { |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
0
|
0
|
|
my ( $z, $host, $key, $btime, $ltime ) = @_; |
116
|
0
|
|
0
|
|
|
|
$host //= '192.168.1.1'; |
117
|
0
|
|
0
|
|
|
|
$key //= 'net.if.in[bond0]'; |
118
|
0
|
|
0
|
|
|
|
$btime //= time() - 1 * 3600; |
119
|
0
|
|
0
|
|
|
|
$ltime //= time(); |
120
|
0
|
|
|
|
|
|
my $info; |
121
|
0
|
|
|
|
|
|
my $hostid = gethostID( $z, $host ); |
122
|
0
|
|
|
|
|
|
my ( $name, $itemid ) = getItemID( $z, $hostid, $key ); |
123
|
0
|
|
|
|
|
|
$info = "The Item of $name-$key \n\n"; |
124
|
0
|
0
|
|
|
|
|
print "debug-PHitems { parameter } : $host $key $btime $ltime \n" if $DEBUG; |
125
|
0
|
|
|
|
|
|
my $v = getHisv( $z, $hostid, $itemid, $btime, $ltime ); |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
for ( sort { $b <=> $a } @{$v} ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#print Dumper($_); |
130
|
0
|
|
|
|
|
|
my $stime = strftime( "%Y-%m-%d %H:%M:%S", localtime( $_->[0] ) ); |
131
|
0
|
|
|
|
|
|
$info .= "$stime $_->[1] \n"; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
|
return $info; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
### 打印取得的所有触发器告警信息 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub pTriggers { |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
0
|
0
|
|
my $z = shift; |
142
|
0
|
|
|
|
|
|
my $info; |
143
|
0
|
|
|
|
|
|
my $reslut = getTriggers($z); |
144
|
0
|
|
|
|
|
|
$info = "\nWarning info of Triggers \n\n"; |
145
|
0
|
|
|
|
|
|
for ( sort { $b <=> $a } keys %{$reslut} ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$info .= "$reslut->{$_}"; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
0
|
|
|
|
|
|
return $info; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
##### 获取给定主机和key值的所有监控项以及当前值 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub getItem { |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
0
|
0
|
|
my ( $z, $host, $key ) = @_; |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
|
return unless gethostID( $z, $host ); |
159
|
0
|
|
|
|
|
|
my $hostid = gethostID( $z, $host ); |
160
|
0
|
|
|
|
|
|
my $r = $z->get( |
161
|
|
|
|
|
|
|
"item", |
162
|
|
|
|
|
|
|
{ |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
output => [ "name", "key_", "prevvalue" ], |
165
|
|
|
|
|
|
|
search => { "key_" => $key }, |
166
|
|
|
|
|
|
|
hostids => $hostid, |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# limit => 10, |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
}, |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
my $result = $r->{'result'}; |
174
|
0
|
|
|
|
|
|
my $sresult; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$sresult .= "$_->{'name'} - { $_->{'key_'} } : $_->{'prevvalue'} \n" |
177
|
0
|
|
|
|
|
|
for ( @{$result} ); |
|
0
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
return $sresult; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub getItemID { |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
0
|
0
|
|
my ( $z, $hostid, $key ) = @_; |
185
|
0
|
0
|
|
|
|
|
print "DEBUG-function(getItemID): $z, $key \n" if $DEBUG; |
186
|
0
|
|
|
|
|
|
my $r = $z->get( |
187
|
|
|
|
|
|
|
"item", |
188
|
|
|
|
|
|
|
{ |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
output => [ "itemids", "name" ], |
191
|
|
|
|
|
|
|
search => { "key_" => $key }, |
192
|
|
|
|
|
|
|
hostids => $hostid, |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
}, |
195
|
|
|
|
|
|
|
); |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
my $result = $r->{'result'}; |
198
|
0
|
|
|
|
|
|
my $sresult; |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
$sresult = $result->[0]->{'itemid'}; |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
return ( $result->[0]->{'name'}, $result->[0]->{'itemid'} ); |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub getHisv { |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
0
|
0
|
|
my ( $z, $hostid, $itemid, $btime, $ltime ) = @_; |
208
|
0
|
0
|
|
|
|
|
print "DEBUG-function(-getHist): $z, $hostid, $itemid, $btime, $ltime \n" |
209
|
|
|
|
|
|
|
if $DEBUG; |
210
|
0
|
|
|
|
|
|
my $r = $z->get( |
211
|
|
|
|
|
|
|
"history", |
212
|
|
|
|
|
|
|
{ |
213
|
|
|
|
|
|
|
# history => 0, |
214
|
|
|
|
|
|
|
itemids => $itemid, |
215
|
|
|
|
|
|
|
time_from => $btime, |
216
|
|
|
|
|
|
|
time_till => $ltime, |
217
|
|
|
|
|
|
|
output => "extend", |
218
|
|
|
|
|
|
|
hostids => $hostid, |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
}, |
221
|
|
|
|
|
|
|
); |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
my $result = $r->{'result'}; |
224
|
0
|
|
|
|
|
|
my $sresult; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
#$sresult.="$_->{'name'} - $_->{'_key'} : $_->{'prevvalue'} \n" for(@{$result}); |
227
|
|
|
|
|
|
|
#print Dumper($result); |
228
|
0
|
|
|
|
|
|
for ( @{$result} ) { |
|
0
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
push @{$sresult}, [ $_->{'clock'}, $_->{'value'} ]; |
|
0
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
} |
233
|
0
|
|
|
|
|
|
return $sresult; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
#### 获取给定主机(ip)的主机号 |
237
|
|
|
|
|
|
|
sub gethostID { |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
0
|
0
|
|
my ( $z, $host ) = @_; |
240
|
0
|
|
|
|
|
|
my $ckey = $host; |
241
|
0
|
0
|
|
|
|
|
unless ( exists $HTcache{$ckey} ) { |
242
|
0
|
0
|
|
|
|
|
print "DEBUG-function(gethostID): $z, $host \n" if $DEBUG; |
243
|
0
|
|
|
|
|
|
my $r = $z->get( |
244
|
|
|
|
|
|
|
"host", |
245
|
|
|
|
|
|
|
{ |
246
|
|
|
|
|
|
|
filter => { |
247
|
|
|
|
|
|
|
host => $host, |
248
|
|
|
|
|
|
|
}, |
249
|
|
|
|
|
|
|
output => ["hostid"], |
250
|
|
|
|
|
|
|
}, |
251
|
|
|
|
|
|
|
); |
252
|
0
|
0
|
|
|
|
|
$HTcache{$ckey} = $r->{'result'}->[0]->{'hostid'} if $r->{'result'}; |
253
|
|
|
|
|
|
|
} |
254
|
0
|
|
|
|
|
|
return $HTcache{$ckey}; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub getname { |
258
|
|
|
|
|
|
|
|
259
|
0
|
|
|
0
|
0
|
|
my ( $z, $host ) = @_; |
260
|
0
|
0
|
|
|
|
|
print "DEBUG-function(gethostname): $z, $host \n" if $DEBUG; |
261
|
0
|
|
|
|
|
|
my $r = $z->get( |
262
|
|
|
|
|
|
|
"host", |
263
|
|
|
|
|
|
|
{ |
264
|
|
|
|
|
|
|
filter => { |
265
|
|
|
|
|
|
|
host => $host, |
266
|
|
|
|
|
|
|
}, |
267
|
|
|
|
|
|
|
output => ["name"], |
268
|
|
|
|
|
|
|
}, |
269
|
|
|
|
|
|
|
); |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
#use Data::Dumper; |
272
|
0
|
0
|
|
|
|
|
return $r->{'result'}->[0]->{'name'} if $r->{'result'}; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
#### 获取所有的主机列表 |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub getAllhost { |
277
|
|
|
|
|
|
|
|
278
|
0
|
|
|
0
|
0
|
|
my $z = shift; |
279
|
0
|
|
|
|
|
|
my $r = $z->get( |
280
|
|
|
|
|
|
|
"host", |
281
|
|
|
|
|
|
|
{ |
282
|
|
|
|
|
|
|
filter => undef, |
283
|
|
|
|
|
|
|
search => undef, |
284
|
|
|
|
|
|
|
output => [ "host", "name" ], |
285
|
|
|
|
|
|
|
}, |
286
|
|
|
|
|
|
|
); |
287
|
|
|
|
|
|
|
|
288
|
0
|
|
|
|
|
|
my $hresult; |
289
|
0
|
|
|
|
|
|
my $host = $r->{'result'}; |
290
|
0
|
|
|
|
|
|
for (@$host) { |
291
|
0
|
|
|
|
|
|
$hresult .= $_->{'host'} . ": $_->{'name'}" . "\n"; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
0
|
|
|
|
|
|
return $hresult; |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
####获取所有的有问题触发警告信息,返回一个包含时间、主机ip和描述的哈希引用 |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub getTriggers { |
300
|
0
|
|
|
0
|
0
|
|
my $z = shift; |
301
|
0
|
|
|
|
|
|
my $ysterday = time() - 24 * 3600; |
302
|
0
|
|
|
|
|
|
my $r = $z->get( |
303
|
|
|
|
|
|
|
"trigger", |
304
|
|
|
|
|
|
|
{ |
305
|
|
|
|
|
|
|
filter => { |
306
|
|
|
|
|
|
|
value => 1, |
307
|
|
|
|
|
|
|
only_true => 1, |
308
|
|
|
|
|
|
|
withUnacknowledgedEvents => 1, |
309
|
|
|
|
|
|
|
}, |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
# lastChangeSince => $ysterday, |
312
|
|
|
|
|
|
|
output => [ "triggerid", "description", "priority" ], |
313
|
|
|
|
|
|
|
sortfield => "triggerid", |
314
|
|
|
|
|
|
|
sortorder => "DESC", |
315
|
|
|
|
|
|
|
expandData => "host", |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
}, |
318
|
|
|
|
|
|
|
); |
319
|
0
|
|
|
|
|
|
my $hresult; |
320
|
0
|
|
|
|
|
|
my $host = $r->{'result'}; |
321
|
0
|
|
|
|
|
|
for (@$host) { |
322
|
0
|
|
|
|
|
|
my $etime = getTgtime( $z, $_->{'triggerid'}, $_->{'host'} ); |
323
|
0
|
0
|
|
|
|
|
next unless $etime; |
324
|
0
|
|
|
|
|
|
my $time = strftime( "%Y-%m-%d %H:%M:%S", localtime($etime) ); |
325
|
|
|
|
|
|
|
$hresult->{$etime} = |
326
|
0
|
|
|
|
|
|
"$time : $_->{'host'}: " . $_->{'description'} . "\n"; |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
0
|
|
|
|
|
|
return $hresult; |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
### 给定触发器,触发器处罚时间(限制24小时候内的). |
333
|
|
|
|
|
|
|
sub getTgtime { |
334
|
|
|
|
|
|
|
|
335
|
0
|
|
|
0
|
0
|
|
my ( $z, $tgid, $host ) = @_; |
336
|
|
|
|
|
|
|
|
337
|
0
|
|
|
|
|
|
my $hostid = gethostID( $z, $host ); |
338
|
0
|
|
|
|
|
|
my $ysterday = time() - 24 * 3600; |
339
|
0
|
|
|
|
|
|
my $vkey = $tgid . $hostid; |
340
|
0
|
0
|
|
|
|
|
unless ( exists $EVcache{$vkey} ) { |
341
|
0
|
|
|
|
|
|
my $r = $z->get( |
342
|
|
|
|
|
|
|
"event", |
343
|
|
|
|
|
|
|
{ |
344
|
|
|
|
|
|
|
filter => { |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
# value => 1, |
347
|
|
|
|
|
|
|
# objectids => '19011' , |
348
|
|
|
|
|
|
|
# triggerids => '19011' , |
349
|
|
|
|
|
|
|
#source => 0, |
350
|
|
|
|
|
|
|
}, |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
objectids => $tgid, |
353
|
|
|
|
|
|
|
triggerids => $tgid, |
354
|
|
|
|
|
|
|
time_from => $ysterday, |
355
|
|
|
|
|
|
|
hostids => $hostid, |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
#select_acknowledges => "extend", |
358
|
|
|
|
|
|
|
output => "extend", |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
sortfield => "eventid", |
361
|
|
|
|
|
|
|
sortorder => "DESC", |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
# expandData=>"host", |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
}, |
366
|
|
|
|
|
|
|
); |
367
|
0
|
0
|
|
|
|
|
$EVcache{$vkey} = $r->{'result'}->[0]->{'clock'} if $r->{'result'}; |
368
|
|
|
|
|
|
|
} |
369
|
0
|
|
|
|
|
|
return $EVcache{$vkey}; |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
sub getEvent { |
373
|
0
|
|
|
0
|
0
|
|
my $z = shift; |
374
|
0
|
|
|
|
|
|
my $ysterday = time() - 1 * 3600; |
375
|
0
|
|
|
|
|
|
my $r = $z->get( |
376
|
|
|
|
|
|
|
"event", |
377
|
|
|
|
|
|
|
{ |
378
|
|
|
|
|
|
|
filter => { |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
# value => 1, |
381
|
|
|
|
|
|
|
acknowledged => 0, |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
#time_from=> "$ysterday", |
384
|
|
|
|
|
|
|
}, |
385
|
|
|
|
|
|
|
time_from => "$ysterday", |
386
|
|
|
|
|
|
|
output => "extend", |
387
|
|
|
|
|
|
|
source => 0, |
388
|
|
|
|
|
|
|
select_acknowledges => "extend", |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
#sortfield =>["clock", "eventid"], |
391
|
|
|
|
|
|
|
#sortorder => "DESC", |
392
|
|
|
|
|
|
|
# expandData=>"host", |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
}, |
395
|
|
|
|
|
|
|
); |
396
|
0
|
|
|
|
|
|
my $host = $r; |
397
|
0
|
|
|
|
|
|
my $hresult = Dumper($r); |
398
|
0
|
|
|
|
|
|
return $hresult; |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
sub getAlert { |
402
|
0
|
|
|
0
|
0
|
|
my $z = shift; |
403
|
0
|
|
|
|
|
|
my $ysterday = time() - 24 * 3600; |
404
|
0
|
|
|
|
|
|
my $r = $z->get( |
405
|
|
|
|
|
|
|
"alert", |
406
|
|
|
|
|
|
|
{ |
407
|
|
|
|
|
|
|
output => "extend", |
408
|
|
|
|
|
|
|
sortfield => ["clock"], |
409
|
|
|
|
|
|
|
sortorder => "DESC", |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
}, |
412
|
|
|
|
|
|
|
); |
413
|
0
|
|
|
|
|
|
my $host = $r; |
414
|
0
|
|
|
|
|
|
my $hresult = Dumper($r); |
415
|
0
|
|
|
|
|
|
return $hresult; |
416
|
|
|
|
|
|
|
} |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
=head1 AUTHOR |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
ORANGE, C<< >> |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
=head1 BUGS |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
425
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
426
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
=head1 SUPPORT |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
perldoc Mojo::Zabbix::APP |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
You can also look for information at: |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
=over 4 |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
L |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
L |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=item * CPAN Ratings |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
L |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
=item * Search CPAN |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
L |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
=back |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
465
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
Copyright 2016 ORANGE. |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify |
469
|
|
|
|
|
|
|
it under the same terms as the Perl 5 programming language system itself. |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
=cut |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
1; |
474
|
|
|
|
|
|
|
|