| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Zabbix::Check::RabbitMQ; |
|
2
|
|
|
|
|
|
|
=head1 NAME |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Zabbix::Check::RabbitMQ - Zabbix check for RabbitMQ service |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
version 1.10 |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Zabbix check for RabbitMQ service |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.installed,/usr/bin/perl -MZabbix::Check::RabbitMQ -e_installed |
|
15
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.running,/usr/bin/perl -MZabbix::Check::RabbitMQ -e_running |
|
16
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.vhost_discovery[*],/usr/bin/perl -MZabbix::Check::RabbitMQ -e_vhost_discovery -- $1 |
|
17
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.queue_discovery[*],/usr/bin/perl -MZabbix::Check::RabbitMQ -e_queue_discovery -- $1 |
|
18
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.rabbitmq.queue_status[*],/usr/bin/perl -MZabbix::Check::RabbitMQ -e_queue_status -- $1 $2 $3 |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head3 installed |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
checks RabbitMQ is installed: 0 | 1 |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head3 running |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
checks RabbitMQ is installed and running: 0 | 1 | 2 = not installed |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head3 vhost_discovery $1 |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
discovers RabbitMQ vhosts |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$1: I |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head3 queue_discovery $1 |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
discovers RabbitMQ queues |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$1: I |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head3 queue_status $1 $2 $3 |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
gets RabbitMQ queue status using queue discovery cache |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$1: I |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$2: I |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$3: I |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
1
|
|
|
1
|
|
745
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
24
|
|
|
52
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
53
|
1
|
|
|
1
|
|
2
|
no warnings qw(qw utf8); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
20
|
|
|
54
|
1
|
|
|
1
|
|
7
|
use v5.14; |
|
|
1
|
|
|
|
|
2
|
|
|
55
|
1
|
|
|
1
|
|
3
|
use utf8; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
3
|
|
|
56
|
1
|
|
|
1
|
|
19
|
use Lazy::Utils; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
95
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
1
|
|
|
1
|
|
5
|
use Zabbix::Check; |
|
|
1
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
|
114
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
BEGIN |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
1
|
|
|
1
|
|
4
|
require Exporter; |
|
64
|
|
|
|
|
|
|
# set the version for version checking |
|
65
|
1
|
|
|
|
|
1
|
our $VERSION = '1.10'; |
|
66
|
|
|
|
|
|
|
# Inherit from Exporter to export functions and variables |
|
67
|
1
|
|
|
|
|
6
|
our @ISA = qw(Exporter); |
|
68
|
|
|
|
|
|
|
# Functions and variables which are exported by default |
|
69
|
1
|
|
|
|
|
2
|
our @EXPORT = qw(_installed _running _vhost_discovery _queue_discovery _queue_status); |
|
70
|
|
|
|
|
|
|
# Functions and variables which can be optionally exported |
|
71
|
1
|
|
|
|
|
789
|
our @EXPORT_OK = qw(); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
our ($rabbitmqctl) = whereisBin('rabbitmqctl'); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub getVhosts |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
0
|
0
|
|
0
|
0
|
|
return unless $rabbitmqctl; |
|
81
|
0
|
|
|
|
|
|
my ($expiry) = @_; |
|
82
|
0
|
0
|
|
|
|
|
$expiry = -1 unless defined($expiry); |
|
83
|
|
|
|
|
|
|
my $result = fileCache("all", $expiry, sub |
|
84
|
|
|
|
|
|
|
{ |
|
85
|
0
|
|
|
0
|
|
|
my $result = {}; |
|
86
|
0
|
|
|
|
|
|
my $first = 1; |
|
87
|
0
|
|
|
|
|
|
for my $line (`$rabbitmqctl list_vhosts 2>/dev/null`) |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
0
|
|
|
|
|
|
chomp $line; |
|
90
|
0
|
0
|
|
|
|
|
if ($first) |
|
91
|
|
|
|
|
|
|
{ |
|
92
|
0
|
|
|
|
|
|
$first = 0; |
|
93
|
0
|
|
|
|
|
|
next; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
0
|
|
|
|
|
|
my ($name) = $line =~ /^(.*)/; |
|
96
|
0
|
|
|
|
|
|
$result->{$name} = { 'name' => $name }; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
0
|
|
|
|
|
|
return $result; |
|
99
|
0
|
|
|
|
|
|
}); |
|
100
|
0
|
|
|
|
|
|
return $result; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub getQueues |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
0
|
0
|
|
0
|
0
|
|
return unless $rabbitmqctl; |
|
106
|
0
|
|
|
|
|
|
my ($vhost, $expiry) = @_; |
|
107
|
0
|
|
|
|
|
|
my $vhostS = shellmeta($vhost); |
|
108
|
0
|
0
|
|
|
|
|
$expiry = -1 unless defined($expiry); |
|
109
|
|
|
|
|
|
|
my $result = fileCache($vhost, $expiry, sub |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
0
|
|
|
0
|
|
|
my $result = {}; |
|
112
|
0
|
|
|
|
|
|
my $first = 1; |
|
113
|
0
|
|
|
|
|
|
for my $line (`$rabbitmqctl list_queues -p \"$vhostS\" name messages_ready messages_unacknowledged messages 2>/dev/null`) |
|
114
|
|
|
|
|
|
|
{ |
|
115
|
0
|
|
|
|
|
|
chomp $line; |
|
116
|
0
|
0
|
|
|
|
|
if ($first) |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
0
|
|
|
|
|
|
$first = 0; |
|
119
|
0
|
|
|
|
|
|
next; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
0
|
|
|
|
|
|
my ($name, $ready, $unacked, $total) = $line =~ m/^([^\t]+)\t+([^\t]+)\t+([^\t]+)\t+([^\t]+)\t*/; |
|
122
|
0
|
|
|
|
|
|
$result->{$name} = {'ready' => $ready, 'unacked' => $unacked, 'total' => $total}; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
0
|
|
|
|
|
|
return $result; |
|
125
|
0
|
|
|
|
|
|
}); |
|
126
|
0
|
|
|
|
|
|
return $result; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _installed |
|
130
|
|
|
|
|
|
|
{ |
|
131
|
0
|
0
|
|
0
|
|
|
my $result = $rabbitmqctl? 1: 0; |
|
132
|
0
|
|
|
|
|
|
print $result; |
|
133
|
0
|
|
|
|
|
|
return $result; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _running |
|
137
|
|
|
|
|
|
|
{ |
|
138
|
0
|
|
|
0
|
|
|
my $result = 2; |
|
139
|
0
|
0
|
|
|
|
|
if ($rabbitmqctl) |
|
140
|
|
|
|
|
|
|
{ |
|
141
|
0
|
|
|
|
|
|
system "$rabbitmqctl cluster_status >/dev/null 2>&1"; |
|
142
|
0
|
0
|
|
|
|
|
$result = ($? == 0)? 1: 0; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
0
|
|
|
|
|
|
print $result; |
|
145
|
0
|
|
|
|
|
|
return $result; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub _vhost_discovery |
|
149
|
|
|
|
|
|
|
{ |
|
150
|
0
|
|
|
0
|
|
|
my ($expiry) = map(zbxDecode($_), @ARGV); |
|
151
|
0
|
0
|
|
|
|
|
$expiry = 0 unless defined($expiry); |
|
152
|
0
|
|
|
|
|
|
my @items; |
|
153
|
0
|
|
|
|
|
|
my $vhosts = getVhosts($expiry); |
|
154
|
0
|
0
|
|
|
|
|
$vhosts = {} unless $vhosts; |
|
155
|
0
|
|
|
|
|
|
for my $vhost (keys %$vhosts) |
|
156
|
|
|
|
|
|
|
{ |
|
157
|
0
|
|
|
|
|
|
push @items, { vhost => $vhost }; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
0
|
|
|
|
|
|
return printDiscovery(@items); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _queue_discovery |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
0
|
|
|
0
|
|
|
my ($expiry) = map(zbxDecode($_), @ARGV); |
|
165
|
0
|
0
|
|
|
|
|
$expiry = 0 unless defined($expiry); |
|
166
|
0
|
|
|
|
|
|
my @items; |
|
167
|
0
|
|
|
|
|
|
my $vhosts = getVhosts($expiry); |
|
168
|
0
|
0
|
|
|
|
|
$vhosts = {} unless $vhosts; |
|
169
|
0
|
|
|
|
|
|
for my $vhost (keys %$vhosts) |
|
170
|
|
|
|
|
|
|
{ |
|
171
|
0
|
|
|
|
|
|
my $queues = getQueues($vhost, $expiry); |
|
172
|
0
|
0
|
|
|
|
|
$queues = {} unless $queues; |
|
173
|
0
|
|
|
|
|
|
for my $queue (keys %$queues) |
|
174
|
|
|
|
|
|
|
{ |
|
175
|
0
|
|
|
|
|
|
push @items, { vhost => $vhost, queue => $queue }; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
} |
|
178
|
0
|
|
|
|
|
|
return printDiscovery(@items); |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub _queue_status |
|
182
|
|
|
|
|
|
|
{ |
|
183
|
0
|
|
|
0
|
|
|
my ($vhost, $queue, $type) = map(zbxDecode($_), @ARGV); |
|
184
|
0
|
0
|
0
|
|
|
|
return unless $vhost and $queue and $type and $type =~ /^ready|unacked|total$/; |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
my $result = ""; |
|
186
|
0
|
|
|
|
|
|
my $queues = getQueues($vhost); |
|
187
|
0
|
0
|
|
|
|
|
$result = $queues->{$queue}->{$type} if defined($queues->{$queue}->{$type}); |
|
188
|
0
|
|
|
|
|
|
print $result; |
|
189
|
0
|
|
|
|
|
|
return $result; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |
|
194
|
|
|
|
|
|
|
__END__ |