Monitoring/Sneck/Checks/supervisorctl.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 95 CC 12 SCAR 46.0
CC
12
Cov
0%
check
156.0
option_spec
2.0
defaults
2.0
CRAP 99.3
1 package Monitoring::Sneck::Checks::supervisorctl;
2  
3 use 5.014;
4 use strict;
5 use warnings;
6 use parent 'Monitoring::Sneck::Checks::base';
7 use Check::supervisorctl ();
8  
9 =head1 NAME
10  
11 Monitoring::Sneck::Checks::supervisorctl - checks supervisorctl status, and optionally the configs, through Check::supervisorctl
12  
13 =head1 VERSION
14  
15 Version 0.1.0
16  
17 =cut
18  
19 our $VERSION = '0.1.0';
20  
21 =head1 SYNOPSIS
22  
23 supervisor|perl:supervisorctl
24 supervisor|perl:supervisorctl -c
25 supervisor|perl:supervisorctl -c -f /etc/supervisor/conf.d -i foo -d bar -s stopped=1
26  
27 =head1 DESCRIPTION
28  
29 A L<Monitoring::Sneck::Checks> check, for running L<Check::supervisorctl>
30 in process from sneck, or through sneck_check. It is only of use if
31 L<Monitoring::Sneck::Checks> is installed, which this distribution
32 does not require.
33  
34 It takes the same options as check_supervisorctl and works out the
35 status the same way, see L<Check::supervisorctl>. 'supervisorctl status'
36 is ran through run_command, so it is stopped if the check times out.
37 If it can not be ran, or returns anything that is not a item and its
38 status, such as when it can not talk to supervisord, that is UNKNOWN
39 by default, changeable via -s status_error=$value.
40  
41 The status line has the counts of the items in each status, followed by
42 the same lines check_supervisorctl prints. Perfdata is the count for
43 each status, the count of ignored items, and if -c is given, the counts
44 of configs not running and running items missing a config.
45  
46 =head1 OPTIONS
47  
48 - -c :: Check the configs as well.
49  
50 - -f <config_dir> :: The directory to look for configs under if -c is set.
51 Default :: /usr/local/etc/supervisor/conf.d
52 Default Linux :: /etc/supervisor/conf.d
53  
54 - -d <ignore_config> :: A config to ignore. May be given more than once.
55  
56 - -i <ignore> :: A item from status to ignore. May be given more than once.
57  
58 - -s <status=value> :: Maps a status to a exit value. May be given more
59 than once. See check_supervisorctl for what may be mapped.
60  
61 - -p <supervisorctl> :: The supervisorctl to run.
62 Default :: supervisorctl
63  
64 =cut
65  
66 sub option_spec {
67 return ( 'c', 'f=s', 'd=s@', 'i=s@', 's=s@', 'p=s' );
68 }
69  
70 sub defaults { return { p => 'supervisorctl' } }
71  
72 =head1 METHODS
73  
74 =head2 check
75  
76 Does the check.
77  
78 =cut
79  
80 sub check {
81 my ($self) = @_;
82  
83 # both die on bad options, which is UNKNOWN
84 my %mapping_opts = Check::supervisorctl->parse_mappings( @{ $self->opt('s') // [] } );
85 my $checker = Check::supervisorctl->new(
86 config_check => $self->opt('c') ? 1 : 0,
87 config_dir => $self->opt('f'),
88 config_ignore => $self->opt('d') // [],
89 ignore => $self->opt('i') // [],
90 %mapping_opts,
91 );
92  
93 # the exit is not of use, as it is non-zero if anything is not running, which the output says anyways
94 my ( $exit, $output ) = $self->run_command( $self->opt('p'), 'status' );
95 my $results = $checker->run( status_output => $output );
96  
97 my @statuses = ( 'running', 'starting', 'backoff', 'stopping', 'stopped', 'exited', 'fatal', 'unknown' );
98 my @summary;
99 foreach my $status (@statuses) {
100 my $count = scalar( @{ $results->{status_list}{$status} } );
101 $self->perfdata( label => $status, value => $count, min => 0 );
102 if ($count) {
103 push( @summary, $count . ' ' . $status );
104 }
105 }
106 $self->perfdata( label => 'ignored', value => scalar( @{ $results->{ignored} } ), min => 0 );
107 if ( $results->{config_check} ) {
108 my $not_running = scalar( @{ $results->{config_not_running} } );
109 my $missing = scalar( @{ $results->{config_missing} } );
110 $self->perfdata( label => 'config_not_running', value => $not_running, min => 0 );
111 $self->perfdata( label => 'config_missing', value => $missing, min => 0 );
112 if ($not_running) {
113 push( @summary, $not_running . ' config' . ( $not_running == 1 ? '' : 's' ) . ' not running' );
114 }
115 if ($missing) {
116 push( @summary, $missing . ' missing config' . ( $missing == 1 ? '' : 's' ) );
117 }
118 if ( $results->{config_dir_missing} ) {
119 push( @summary, 'config dir missing' );
120 } elsif ( !$results->{config_dir_readable} ) {
121 push( @summary, 'config dir not readable' );
122 }
123 } ## end if ( $results->{config_check} )
124 if ( defined( $results->{status_errors}[0] ) ) {
125 push( @summary, $results->{status_errors}[0] );
126 }
127 if ( !defined( $summary[0] ) ) {
128 push( @summary, 'no items' );
129 }
130  
131 return $self->finish( $results->{exit}, join( ', ', @summary ), @{ $results->{results} } );
132 } ## end sub check
133  
134 =head1 AUTHOR
135  
136 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
137  
138 =head1 LICENSE AND COPYRIGHT
139  
140 This software is Copyright (c) 2026 by Zane C. Bowers-Hadley.
141  
142 This is free software, licensed under:
143  
144 The GNU General Public License, Version 3, June 2007
145  
146 =cut
147  
148 1;