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