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