line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Zabbix::Check::Supervisor; |
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Zabbix::Check::Supervisor - Zabbix check for Supervisor service |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
version 1.10 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Zabbix check for Supervisor service |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.supervisor.installed,/usr/bin/perl -MZabbix::Check::Supervisor -e_installed |
15
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.supervisor.running,/usr/bin/perl -MZabbix::Check::Supervisor -e_running |
16
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.supervisor.worker_discovery,/usr/bin/perl -MZabbix::Check::Supervisor -e_worker_discovery |
17
|
|
|
|
|
|
|
UserParameter=cpan.zabbix.check.supervisor.worker_status[*],/usr/bin/perl -MZabbix::Check::Supervisor -e_worker_status -- $1 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head3 installed |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
checks Supervisor is installed: 0 | 1 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head3 running |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
checks Supervisor is installed and running: 0 | 1 | 2 = not installed |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head3 worker_discovery |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
discovers Supervisor workers |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head3 worker_status $1 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
gets Supervisor worker status: RUNNING | STOPPED | ... |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$1: I |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
1
|
|
|
1
|
|
727
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
39
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
40
|
1
|
|
|
1
|
|
3
|
no warnings qw(qw utf8); |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
27
|
|
41
|
1
|
|
|
1
|
|
10
|
use v5.14; |
|
1
|
|
|
|
|
3
|
|
42
|
1
|
|
|
1
|
|
3
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
43
|
1
|
|
|
1
|
|
26
|
use Lazy::Utils; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
85
|
|
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
1
|
|
4
|
use Zabbix::Check; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
99
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
BEGIN |
49
|
|
|
|
|
|
|
{ |
50
|
1
|
|
|
1
|
|
4
|
require Exporter; |
51
|
|
|
|
|
|
|
# set the version for version checking |
52
|
1
|
|
|
|
|
18
|
our $VERSION = '1.10'; |
53
|
|
|
|
|
|
|
# Inherit from Exporter to export functions and variables |
54
|
1
|
|
|
|
|
7
|
our @ISA = qw(Exporter); |
55
|
|
|
|
|
|
|
# Functions and variables which are exported by default |
56
|
1
|
|
|
|
|
2
|
our @EXPORT = qw(_installed _running _worker_discovery _worker_status); |
57
|
|
|
|
|
|
|
# Functions and variables which can be optionally exported |
58
|
1
|
|
|
|
|
371
|
our @EXPORT_OK = qw(); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
our ($supervisorctl) = whereisBin('supervisorctl'); |
63
|
|
|
|
|
|
|
our ($supervisord) = whereisBin('supervisord'); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub getStatuses |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
0
|
|
0
|
0
|
|
return unless $supervisorctl; |
69
|
|
|
|
|
|
|
my $result = fileCache("all", 30, sub |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
0
|
|
|
my $result = {}; |
72
|
0
|
|
|
|
|
|
for (`$supervisorctl status 2>/dev/null`) |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
|
|
|
chomp; |
75
|
0
|
|
|
|
|
|
my ($name, $status) = /^(\S+)\s+(\S+)\s*/; |
76
|
0
|
|
|
|
|
|
$result->{$name} = $status; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
return $result; |
79
|
0
|
|
|
|
|
|
}); |
80
|
0
|
|
|
|
|
|
return $result; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _installed |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
0
|
|
0
|
|
|
my $result = $supervisorctl? 1: 0; |
86
|
0
|
|
|
|
|
|
print $result; |
87
|
0
|
|
|
|
|
|
return $result; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _running |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
|
|
0
|
|
|
my $result = 2; |
93
|
0
|
0
|
|
|
|
|
if ($supervisorctl) |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
|
|
|
system "pgrep -f '/usr/bin/python $supervisord' >/dev/null 2>&1"; |
96
|
0
|
0
|
|
|
|
|
$result = ($? == 0)? 1: 0; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
print $result; |
99
|
0
|
|
|
|
|
|
return $result; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _worker_discovery |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
|
|
0
|
|
|
my @items; |
105
|
0
|
|
|
|
|
|
my $statuses = getStatuses(); |
106
|
0
|
0
|
|
|
|
|
@items = map({ name => $_}, keys %$statuses) if $statuses; |
107
|
0
|
|
|
|
|
|
return printDiscovery(@items); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _worker_status |
111
|
|
|
|
|
|
|
{ |
112
|
0
|
|
|
0
|
|
|
my ($name) = map(zbxDecode($_), @ARGV); |
113
|
0
|
0
|
|
|
|
|
return unless $name; |
114
|
0
|
|
|
|
|
|
my $result = ""; |
115
|
0
|
|
|
|
|
|
my $statuses = getStatuses(); |
116
|
0
|
0
|
|
|
|
|
$result = $statuses->{$name} if $statuses->{$name}; |
117
|
0
|
|
|
|
|
|
print $result; |
118
|
0
|
|
|
|
|
|
return $result; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
__END__ |