line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix::Check; |
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Zabbix::Check - System and service checks for Zabbix |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
version 1.12 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
System and service checks for Zabbix |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.installed,/usr/bin/env bash -c "/usr/bin/env perl -MZabbix::Check 2>/dev/null; if [ \$? -eq 0 ]; then echo 1; else echo 0; fi" |
15
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.version,/usr/bin/env perl -MZabbix::Check -e_version |
16
|
|
|
|
|
|
|
# Disk |
17
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.disk.discovery,/usr/bin/env perl -MZabbix::Check::Disk -e_discovery |
18
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.disk.bps[*],/usr/bin/env perl -MZabbix::Check::Disk -e_bps -- $1 $2 |
19
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.disk.iops[*],/usr/bin/env perl -MZabbix::Check::Disk -e_iops -- $1 $2 |
20
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.disk.ioutil[*],/usr/bin/env perl -MZabbix::Check::Disk -e_ioutil -- $1 |
21
|
|
|
|
|
|
|
# Supervisor |
22
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.supervisor.installed,/usr/bin/env perl -MZabbix::Check::Supervisor -e_installed |
23
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.supervisor.running,/usr/bin/env perl -MZabbix::Check::Supervisor -e_running |
24
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.supervisor.worker_discovery,/usr/bin/env perl -MZabbix::Check::Supervisor -e_worker_discovery |
25
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.supervisor.worker_status[*],/usr/bin/env perl -MZabbix::Check::Supervisor -e_worker_status -- $1 |
26
|
|
|
|
|
|
|
# RabbitMQ |
27
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.installed,/usr/bin/env perl -MZabbix::Check::RabbitMQ -e_installed |
28
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.running,/usr/bin/env perl -MZabbix::Check::RabbitMQ -e_running |
29
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.vhost_discovery[*],/usr/bin/env perl -MZabbix::Check::RabbitMQ -e_vhost_discovery -- $1 |
30
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.queue_discovery[*],/usr/bin/env perl -MZabbix::Check::RabbitMQ -e_queue_discovery -- $1 |
31
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.queue_status[*],/usr/bin/env perl -MZabbix::Check::RabbitMQ -e_queue_status -- $1 $2 $3 |
32
|
|
|
|
|
|
|
# Systemd |
33
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.systemd.installed,/usr/bin/env perl -MZabbix::Check::Systemd -e_installed |
34
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.systemd.system_status,/usr/bin/env perl -MZabbix::Check::Systemd -e_system_status |
35
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.systemd.service_discovery[*],/usr/bin/env perl -MZabbix::Check::Systemd -e_service_discovery -- $1 |
36
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.systemd.service_status[*],/usr/bin/env perl -MZabbix::Check::Systemd -e_service_status -- $1 |
37
|
|
|
|
|
|
|
# Time |
38
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.time.epoch,/usr/bin/env perl -MZabbix::Check::Time -e_epoch |
39
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.time.zone,/usr/bin/env perl -MZabbix::Check::Time -e_zone |
40
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.time.ntp_offset[*],/usr/bin/env perl -MZabbix::Check::Time -e_ntp_offset -- $1 $2 |
41
|
|
|
|
|
|
|
# Redis |
42
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.redis.installed,/usr/bin/env perl -MZabbix::Check::Redis -e_installed |
43
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.redis.discovery,/usr/bin/env perl -MZabbix::Check::Redis -e_discovery |
44
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.redis.running[*],/usr/bin/env perl -MZabbix::Check::Redis -e_running -- $1 |
45
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.redis.info[*],/usr/bin/env perl -MZabbix::Check::Redis -e_info -- $1 $2 |
46
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.redis.resptime[*],/usr/bin/env perl -MZabbix::Check::Redis -e_resptime -- $1 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DISK |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Zabbix check for disk |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 discovery |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
discovers disks |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 bps $1 $2 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
gets disk I/O traffic in bytes per second |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$1: I |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$2: I |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 iops $1 $2 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
gets disk I/O transaction speed in transactions per second |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$1: I |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$2: I |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 ioutil $1 |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
gets disk I/O utilization in percentage |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$1: I |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SUPERVISOR |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Zabbix check for Supervisor service |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 installed |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
checks Supervisor is installed: 0 | 1 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 running |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
checks Supervisor is installed and running: 0 | 1 | 2 = not installed |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 worker_discovery |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
discovers Supervisor workers |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 worker_status $1 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
gets Supervisor worker status: RUNNING | STOPPED | ... |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$1: I |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 RABBITMQ |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Zabbix check for RabbitMQ service |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 installed |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
checks RabbitMQ is installed: 0 | 1 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 running |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
checks RabbitMQ is installed and running: 0 | 1 | 2 = not installed |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 vhost_discovery $1 |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
discovers RabbitMQ vhosts |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$1: I |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 queue_discovery $1 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
discovers RabbitMQ queues |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$1: I |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 queue_status $1 $2 $3 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
gets RabbitMQ queue status using queue discovery cache |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
$1: I |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$2: I |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$3: I |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SYSTEMD |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Zabbix check for Systemd services |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 installed |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
checks Systemd is installed: 0 | 1 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 system_status |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
gets Systemd system status: initializing | starting | running | degraded | maintenance | stopping | offline | unknown |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 service_discovery |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
discovers Systemd enabled services |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$1: I |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 service_status $1 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
gets Systemd enabled service status: active | inactive | failed | unknown | ... |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
$1: I |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 TIME |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Zabbix check for system time |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 epoch |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
gets system time epoch in seconds |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 zone |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
gets system time zone, eg: +0200 |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 ntp_offset $1 $2 |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
gets system time difference by NTP server |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
$1: I |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$2: I |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 REDIS |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Zabbix check for Redis service |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 installed |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
checks Redis is installed: 0 | 1 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 discovery |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
discovers Redis instances |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 running $1 |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
checks Redis is installed and instance is running: 0 | 1 | 2 = not installed |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
$1: I |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 info $1 $2 |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
gets info |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
$1: I |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
$2: I |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 resptime $1 |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
gets single GET command response time from Redis |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
$1: I |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
1
|
|
|
1
|
|
73007
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
212
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
213
|
1
|
|
|
1
|
|
18
|
use v5.10.1; |
|
1
|
|
|
|
|
10
|
|
214
|
1
|
|
|
1
|
|
824
|
use JSON; |
|
1
|
|
|
|
|
14005
|
|
|
1
|
|
|
|
|
10
|
|
215
|
1
|
|
|
1
|
|
661
|
use Net::NTP; |
|
1
|
|
|
|
|
25880
|
|
|
1
|
|
|
|
|
62
|
|
216
|
1
|
|
|
1
|
|
318
|
use Lazy::Utils; |
|
1
|
|
|
|
|
39867
|
|
|
1
|
|
|
|
|
220
|
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
BEGIN |
220
|
|
|
|
|
|
|
{ |
221
|
1
|
|
|
1
|
|
10
|
require Exporter; |
222
|
1
|
|
|
|
|
2
|
our $VERSION = '1.12'; |
223
|
1
|
|
|
|
|
9
|
our @ISA = qw(Exporter); |
224
|
1
|
|
|
|
|
3
|
our @EXPORT = qw(zbx_encode zbx_decode print_discovery _version); |
225
|
1
|
|
|
|
|
457
|
our @EXPORT_OK = qw(); |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
our @zbx_specials = split(" ", q%\ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | \# @%); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub zbx_encode |
233
|
|
|
|
|
|
|
{ |
234
|
0
|
|
|
0
|
0
|
|
my $result = ""; |
235
|
0
|
|
|
|
|
|
my ($str) = @_; |
236
|
0
|
0
|
|
|
|
|
return $result unless defined($str); |
237
|
0
|
|
|
|
|
|
for (my $i = 0; $i < length $str; $i++) |
238
|
|
|
|
|
|
|
{ |
239
|
0
|
|
|
|
|
|
my $chr = substr $str, $i, 1; |
240
|
0
|
0
|
0
|
|
|
|
if (not $chr =~ /[ -~]/g or grep($_ eq $chr, (@zbx_specials, '%', ','))) |
241
|
|
|
|
|
|
|
{ |
242
|
0
|
|
|
|
|
|
$result .= uc sprintf("%%%x", ord($chr)); |
243
|
|
|
|
|
|
|
} else |
244
|
|
|
|
|
|
|
{ |
245
|
0
|
|
|
|
|
|
$result .= $chr; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
} |
248
|
0
|
|
|
|
|
|
return $result; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub zbx_decode |
252
|
|
|
|
|
|
|
{ |
253
|
0
|
|
|
0
|
0
|
|
my $result = ""; |
254
|
0
|
|
|
|
|
|
my ($str) = @_; |
255
|
0
|
0
|
|
|
|
|
return $result unless defined($str); |
256
|
0
|
|
|
|
|
|
my ($i, $len) = (0, length $str); |
257
|
0
|
|
|
|
|
|
while ($i < $len) |
258
|
|
|
|
|
|
|
{ |
259
|
0
|
|
|
|
|
|
my $chr = substr $str, $i, 1; |
260
|
0
|
0
|
|
|
|
|
if ($chr eq '%') |
261
|
|
|
|
|
|
|
{ |
262
|
0
|
0
|
|
|
|
|
return $result if $len-$i-1 < 2; |
263
|
0
|
|
|
|
|
|
$result .= chr(hex(substr($str, $i+1, 2))); |
264
|
0
|
|
|
|
|
|
$i += 2; |
265
|
|
|
|
|
|
|
} else |
266
|
|
|
|
|
|
|
{ |
267
|
0
|
|
|
|
|
|
$result .= $chr; |
268
|
|
|
|
|
|
|
} |
269
|
0
|
|
|
|
|
|
$i++; |
270
|
|
|
|
|
|
|
} |
271
|
0
|
|
|
|
|
|
return $result; |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
sub print_discovery |
275
|
|
|
|
|
|
|
{ |
276
|
0
|
|
|
0
|
0
|
|
my @items = @_; |
277
|
|
|
|
|
|
|
my $discovery = { |
278
|
|
|
|
|
|
|
data => [ |
279
|
|
|
|
|
|
|
map({ |
280
|
0
|
|
|
|
|
|
my $item = $_; |
|
0
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
my %newitem = map({ |
282
|
0
|
|
|
|
|
|
my $key = $_; |
|
0
|
|
|
|
|
|
|
283
|
0
|
|
|
|
|
|
my $val = $item->{$key}; |
284
|
0
|
|
|
|
|
|
my $newkey = zbx_encode($key); |
285
|
0
|
|
|
|
|
|
$newkey = uc("{#$newkey}"); |
286
|
0
|
|
|
|
|
|
my $newval = zbx_encode($val); |
287
|
0
|
|
|
|
|
|
$newkey => $newval; |
288
|
|
|
|
|
|
|
} keys(%$item)); |
289
|
0
|
|
|
|
|
|
\%newitem; |
290
|
|
|
|
|
|
|
} @items), |
291
|
|
|
|
|
|
|
], |
292
|
|
|
|
|
|
|
}; |
293
|
0
|
|
|
|
|
|
my $result = to_json($discovery, {pretty => 1}); |
294
|
0
|
|
|
|
|
|
print $result; |
295
|
0
|
|
|
|
|
|
return $result; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
sub _version |
299
|
|
|
|
|
|
|
{ |
300
|
0
|
|
|
0
|
|
|
my $result = ""; |
301
|
0
|
|
|
|
|
|
$result = $Zabbix::Check::VERSION; |
302
|
0
|
|
|
|
|
|
print $result; |
303
|
0
|
|
|
|
|
|
return $result; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
1; |
308
|
|
|
|
|
|
|
__END__ |