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