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.11 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Zabbix check for RabbitMQ service |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
1
|
|
|
1
|
|
1722
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
16
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
17
|
1
|
|
|
1
|
|
17
|
use v5.10.1; |
|
1
|
|
|
|
|
5
|
|
18
|
1
|
|
|
1
|
|
7
|
use Lazy::Utils; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
160
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
9
|
use Zabbix::Check; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
157
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BEGIN |
24
|
|
|
|
|
|
|
{ |
25
|
1
|
|
|
1
|
|
10
|
require Exporter; |
26
|
1
|
|
|
|
|
4
|
our $VERSION = '1.11'; |
27
|
1
|
|
|
|
|
13
|
our @ISA = qw(Exporter); |
28
|
1
|
|
|
|
|
5
|
our @EXPORT = qw(_installed _running _vhost_discovery _queue_discovery _queue_status); |
29
|
1
|
|
|
|
|
1067
|
our @EXPORT_OK = qw(); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our ($rabbitmqctl) = whereis('rabbitmqctl'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_vhosts |
37
|
|
|
|
|
|
|
{ |
38
|
0
|
0
|
|
0
|
0
|
|
return unless $rabbitmqctl; |
39
|
0
|
|
|
|
|
|
my ($expiry) = @_; |
40
|
|
|
|
|
|
|
my $result = file_cache("all", $expiry, sub |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
0
|
|
|
my $result = {}; |
43
|
0
|
|
|
|
|
|
my $first = 1; |
44
|
0
|
|
|
|
|
|
for my $line (`$rabbitmqctl list_vhosts 2>/dev/null`) |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
|
|
|
chomp $line; |
47
|
0
|
0
|
|
|
|
|
if ($first) |
48
|
|
|
|
|
|
|
{ |
49
|
0
|
|
|
|
|
|
$first = 0; |
50
|
0
|
|
|
|
|
|
next; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
my ($name) = $line =~ /^(.*)/; |
53
|
0
|
|
|
|
|
|
$result->{$name} = { 'name' => $name }; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
return $result; |
56
|
0
|
|
|
|
|
|
}); |
57
|
0
|
|
|
|
|
|
return $result; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub get_queues |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
0
|
|
0
|
0
|
|
return unless $rabbitmqctl; |
63
|
0
|
|
|
|
|
|
my ($vhost, $expiry) = @_; |
64
|
0
|
|
|
|
|
|
my $vhost_s = shellmeta($vhost); |
65
|
|
|
|
|
|
|
my $result = file_cache($vhost, $expiry, sub |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
0
|
|
|
my $result = {}; |
68
|
0
|
|
|
|
|
|
my $first = 1; |
69
|
0
|
|
|
|
|
|
for my $line (`$rabbitmqctl list_queues -p \"$vhost_s\" name messages_ready messages_unacknowledged messages 2>/dev/null`) |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
|
chomp $line; |
72
|
0
|
0
|
|
|
|
|
if ($first) |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
|
|
|
$first = 0; |
75
|
0
|
|
|
|
|
|
next; |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
my ($name, $ready, $unacked, $total) = $line =~ m/^([^\t]+)\t+([^\t]+)\t+([^\t]+)\t+([^\t]+)\t*/; |
78
|
0
|
|
|
|
|
|
$result->{$name} = {'ready' => $ready, 'unacked' => $unacked, 'total' => $total}; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
return $result; |
81
|
0
|
|
|
|
|
|
}); |
82
|
0
|
|
|
|
|
|
return $result; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _installed |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
0
|
|
0
|
|
|
my $result = $rabbitmqctl? 1: 0; |
88
|
0
|
|
|
|
|
|
print $result; |
89
|
0
|
|
|
|
|
|
return $result; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _running |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
0
|
|
|
my $result = 2; |
95
|
0
|
0
|
|
|
|
|
if ($rabbitmqctl) |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
|
|
|
system "$rabbitmqctl cluster_status >/dev/null 2>&1"; |
98
|
0
|
0
|
|
|
|
|
$result = ($? == 0)? 1: 0; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
print $result; |
101
|
0
|
|
|
|
|
|
return $result; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _vhost_discovery |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
0
|
|
|
my ($expiry) = map(zbx_decode($_), @ARGV); |
107
|
0
|
0
|
|
|
|
|
$expiry = 0 unless defined($expiry); |
108
|
0
|
|
|
|
|
|
my @items; |
109
|
0
|
|
|
|
|
|
my $vhosts = get_vhosts($expiry); |
110
|
0
|
0
|
|
|
|
|
$vhosts = {} unless $vhosts; |
111
|
0
|
|
|
|
|
|
for my $vhost (keys %$vhosts) |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
|
|
|
push @items, { vhost => $vhost }; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
return print_discovery(@items); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _queue_discovery |
119
|
|
|
|
|
|
|
{ |
120
|
0
|
|
|
0
|
|
|
my ($expiry) = map(zbx_decode($_), @ARGV); |
121
|
0
|
0
|
|
|
|
|
$expiry = 0 unless defined($expiry); |
122
|
0
|
|
|
|
|
|
my @items; |
123
|
0
|
|
|
|
|
|
my $vhosts = get_vhosts($expiry); |
124
|
0
|
0
|
|
|
|
|
$vhosts = {} unless $vhosts; |
125
|
0
|
|
|
|
|
|
for my $vhost (keys %$vhosts) |
126
|
|
|
|
|
|
|
{ |
127
|
0
|
|
|
|
|
|
my $queues = get_queues($vhost, $expiry); |
128
|
0
|
0
|
|
|
|
|
$queues = {} unless $queues; |
129
|
0
|
|
|
|
|
|
for my $queue (keys %$queues) |
130
|
|
|
|
|
|
|
{ |
131
|
0
|
|
|
|
|
|
push @items, { vhost => $vhost, queue => $queue }; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
|
return print_discovery(@items); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _queue_status |
138
|
|
|
|
|
|
|
{ |
139
|
0
|
|
|
0
|
|
|
my ($vhost, $queue, $type) = map(zbx_decode($_), @ARGV); |
140
|
0
|
0
|
0
|
|
|
|
return "" unless $vhost and $queue and $type and $type =~ /^ready|unacked|total$/; |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $result = ""; |
142
|
0
|
|
|
|
|
|
my $queues = get_queues($vhost); |
143
|
0
|
0
|
|
|
|
|
$result = $queues->{$queue}->{$type} if defined($queues->{$queue}->{$type}); |
144
|
0
|
|
|
|
|
|
print $result; |
145
|
0
|
|
|
|
|
|
return $result; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
__END__ |