Check/Supervisor.pm

filter: Statementstmt 49.1% 28 / 57 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 8 / 14 Podpod 0.0% 0 / 1 totaltotal 41.8% 36 / 86 CC 9 SCAR 17.6
CC
9
Cov
39%
_running
12.0
_worker_status
12.0
getStatuses
6.0
CRAP 5.8
« Check/Time.pm ↑ Summary
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<worker name>
36  
37 =cut
38 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶no warnings qw(qw utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use Lazy::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 1 ▶use Zabbix::Check;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47  
48 BEGIN
49 {
50 1 ▶ require Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 # set the version for version checking
52 1 our $VERSION = '1.10';
53 # Inherit from Exporter to export functions and variables
54 1 our @ISA = qw(Exporter);
55 # Functions and variables which are exported by default
56 1 our @EXPORT = qw(_installed _running _worker_discovery _worker_status);
57 # Functions and variables which can be optionally exported
58 1 our @EXPORT_OK = qw();
59 }
60  
61  
62 1 our ($supervisorctl) = whereisBin('supervisorctl');
63 1 our ($supervisord) = whereisBin('supervisord');
64  
65  
66 sub getStatuses
67 {
68 0 ▶ return unless $supervisorctl;
Subroutine getStatuses: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless $Zabbix::Check::Supervisor::supervisorctl 0 0 0
69 my $result = fileCache("all", 30, sub
70 {
71 0 ▶ my $result = {};
Subroutine __ANON__: not called CC=2 SCAR=17.9
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 ▶ my $result = $supervisorctl? 1: 0;
Subroutine _installed: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$Zabbix::Check::Supervisor::supervisorctl ? : 0 0 0
86 0 print $result;
87 0 return $result;
88 }
89  
90 sub _running
91 {
92 0 ▶ my $result = 2;
Subroutine _running: not called CC=3 SCAR=24.8
93 0 ▶ if ($supervisorctl)
Branch: 1 branch
BranchTrueFalseTotal
if ($Zabbix::Check::Supervisor::supervisorctl) 0 0 0
94 {
95 0 system "pgrep -f '/usr/bin/python $supervisord' >/dev/null 2>&1";
96 0 ▶ $result = ($? == 0)? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
$? == 0 ? : 0 0 0
97 }
98 0 print $result;
99 0 return $result;
100 }
101  
102 sub _worker_discovery
103 {
104 0 ▶ my @items;
Subroutine _worker_discovery: not called CC=2 SCAR=17.9
105 0 my $statuses = getStatuses();
106 0 ▶ @items = map({ name => $_}, keys %$statuses) if $statuses;
Branch: 1 branch
BranchTrueFalseTotal
if $statuses 0 0 0
107 0 return printDiscovery(@items);
108 }
109  
110 sub _worker_status
111 {
112 0 ▶ my ($name) = map(zbxDecode($_), @ARGV);
Subroutine _worker_status: not called CC=3 SCAR=24.8
113 0 ▶ return unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
114 0 my $result = "";
115 0 my $statuses = getStatuses();
116 0 ▶ $result = $statuses->{$name} if $statuses->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $statuses->{$name} 0 0 0
117 0 print $result;
118 0 return $result;
119 }
120  
121  
122 1 1;
123 __END__
« Check/Time.pm ↑ Summary