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.11 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Zabbix check for Supervisor service |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
1
|
|
|
1
|
|
1701
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
43
|
|
16
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
17
|
1
|
|
|
1
|
|
19
|
use v5.10.1; |
|
1
|
|
|
|
|
4
|
|
18
|
1
|
|
|
1
|
|
8
|
use Lazy::Utils; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
185
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
9
|
use Zabbix::Check; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
152
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BEGIN |
24
|
|
|
|
|
|
|
{ |
25
|
1
|
|
|
1
|
|
8
|
require Exporter; |
26
|
1
|
|
|
|
|
10
|
our $VERSION = '1.11'; |
27
|
1
|
|
|
|
|
16
|
our @ISA = qw(Exporter); |
28
|
1
|
|
|
|
|
5
|
our @EXPORT = qw(_installed _running _worker_discovery _worker_status); |
29
|
1
|
|
|
|
|
581
|
our @EXPORT_OK = qw(); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our ($supervisorctl) = whereis('supervisorctl'); |
34
|
|
|
|
|
|
|
our ($supervisord) = whereis('supervisord'); |
35
|
|
|
|
|
|
|
our ($python) = whereis('python'); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_statuses |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
0
|
|
0
|
0
|
|
return unless $supervisorctl; |
41
|
|
|
|
|
|
|
my $result = file_cache("all", 30, sub |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
0
|
|
|
my $result = {}; |
44
|
0
|
|
|
|
|
|
for (`$supervisorctl status 2>/dev/null`) |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
|
|
|
chomp; |
47
|
0
|
|
|
|
|
|
my ($name, $status) = /^(\S+)\s+(\S+)\s*/; |
48
|
0
|
|
|
|
|
|
$result->{$name} = $status; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
|
return $result; |
51
|
0
|
|
|
|
|
|
}); |
52
|
0
|
|
|
|
|
|
return $result; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _installed |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
0
|
|
0
|
|
|
my $result = $supervisorctl? 1: 0; |
58
|
0
|
|
|
|
|
|
print $result; |
59
|
0
|
|
|
|
|
|
return $result; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _running |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
|
|
my $result = 2; |
65
|
0
|
0
|
|
|
|
|
if ($supervisorctl) |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
|
system "pgrep -f '$python $supervisord' >/dev/null 2>&1"; |
68
|
0
|
0
|
|
|
|
|
$result = ($? == 0)? 1: 0; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
print $result; |
71
|
0
|
|
|
|
|
|
return $result; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _worker_discovery |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
0
|
|
|
my @items; |
77
|
0
|
|
|
|
|
|
my $statuses = get_statuses(); |
78
|
0
|
0
|
|
|
|
|
@items = map({ name => $_}, keys %$statuses) if $statuses; |
79
|
0
|
|
|
|
|
|
return print_discovery(@items); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _worker_status |
83
|
|
|
|
|
|
|
{ |
84
|
0
|
|
|
0
|
|
|
my ($name) = map(zbx_decode($_), @ARGV); |
85
|
0
|
0
|
|
|
|
|
return "" unless $name; |
86
|
0
|
|
|
|
|
|
my $result = ""; |
87
|
0
|
|
|
|
|
|
my $statuses = get_statuses(); |
88
|
0
|
0
|
|
|
|
|
$result = $statuses->{$name} if defined($statuses->{$name}); |
89
|
0
|
|
|
|
|
|
print $result; |
90
|
0
|
|
|
|
|
|
return $result; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |