NAME

Check::supervisorctl - Check the status of supervisorctl to see if it is okay.

VERSION

Version 0.2.0

SYNOPSIS

use Check::supervisorctl;

my $check_supervisorctl = Check::supervisorctl->new();
my $results = $check_supervisorctl->run;
print join( "\n", @{ $results->{results} } ) . "\n";
exit( $results->{exit} );

SUBROUTINES/METHODS

new

Initiates the object.

- status_mapping :: A hash of status mapping values.
    default :: {
            stopped  => 2,
            starting => 0,
            running  => 0,
            backoff  => 2,
            stopping => 2,
            exited   => 2,
            fatal    => 2,
            unknown  => 2,
        }

- not_running_val :: Value for if it a config is not running.
    default :: 2

- config_missing_val :: Value for if it a config is missing for a running item.
    default :: 2

- config_dir_missing_val :: Value for if it the config dir is not present.
    default :: 3

- config_dir_nonreadable_val :: Value for if it the config dir is not readable.
    default :: 3

- status_error_val :: Value for if supervisorctl status could not be run or
        returned a line that is not a item and status, such as when it can not
        talk to supervisord.
    default :: 3

- config_check :: Boolean for if it should check the configs or not.
    default :: 0

- ignore :: A array of running items to ignore.
    default :: []

- config_ignore :: A array of configs to ignore.
    default :: []

- config_dir :: Config dir path.
    default :: /usr/local/etc/supervisor/conf.d
    default Linux :: /etc/supervisor/conf.d

- restart :: Boolean for if items that are stopped, exited, fatal, or
        backoff should be restarted. Ignored items are not touched.
    default :: 0

- add_configs :: Boolean for if configs that are not running should be
        added via 'supervisorctl reread' and 'supervisorctl add'. Requires
        config_check. Ignored configs and ignored items are not touched.
    default :: 0

Restarting or adding does not change the exit value. It is worked out from how things were before, so a stopped item that was restarted is still alerted on, letting what is monitoring it know it was restarted.

parse_mappings

Parses a list of status=value strings, as taken by -s for check_supervisorctl, into a hash of options for "new". Whitespace is removed.

The names may be any of the statuses for status_mapping, or not_running, config_missing, config_dir_missing, config_dir_nonreadable, or status_error for the matching *_val options.

Dies if one is not in the form of name=value or the name is not known. The values are checked by "new".

my %mapping_opts = Check::supervisorctl->parse_mappings( 'stopped=1', 'config_missing=1' );
my $checker = Check::supervisorctl->new( config_check => 1, %mapping_opts );

run

This runs it.

my $results=$check_supervisorctl->run;

use Data::Dumper;
print Dumper($results);
exit($results->{exit});

It optionally takes the output of 'supervisorctl status', for when it has already been ran by something else. If not given, 'supervisorctl status' is ran.

- status_output :: The output of 'supervisorctl status'.

- command :: A code ref for running supervisorctl for restart and
        add_configs. It is passed the args for supervisorctl, such as
        ( 'start', 'foo' ), and returns its exit code and its stdout and
        stderr together. If it dies, run dies.
    default :: runs supervisorctl from the path, without a shell

my $results=$check_supervisorctl->run( status_output => $output );

my $results = $check_supervisorctl->run(
    command => sub { return $check->run_command( '/usr/local/bin/supervisorctl', @_ ) },
);

A supervisorctl command is considered to have failed if it exits non-zero or its output contains 'ERROR', as older versions of supervisorctl exit zero on failure.

The returned data is as below.

- .configs[] :: A array of configs found.

- .config_not_running[] :: A array of configs present but not running.

- .config_missing[] :: A array of running items was found, but no matchingly named config was found.

- .config_check :: If it was told to check the configs or not for matching names.

- .config_dir :: The config dir to check.

- .config_ignored[] :: Array of configs ignored.

- .config_ignore :: Configs asked to be ignored.

- .exit :: Nagios style exit value.

- .status.$name :: Status of each item.

- .total :: Number of items found in the status output, not counting ignored ones.

- .ignored[] :: A array of ignored items.

- .ignore :: A array of items asked to be ignored.

- .config_dir_missing :: If the config dir is missing.

- .config_dir_readable :: If the config dir is readable.

- .status_list.$status :: A hash of the various statuses with keys being arrays of items for that status.

- .status_errors[] :: Lines from 'supervisorctl status' that were not a item and status,
        such as when it can not talk to supervisord.

- .restart :: If it was told to restart items.

- .restarted[] :: A array of items restarted.

- .restart_failed[] :: A array of items that restarting failed for.

- .add_configs :: If it was told to add configs that are not running.

- .added[] :: A array of configs added.

- .add_failed[] :: A array of configs that adding failed for, including
        all of them if 'supervisorctl reread' failed.

- .results[] :: A descriptive a array of the results of the check.

AUTHOR

Zane C. Bowers-Hadley, <vvelox at vvelox.net>

BUGS

Please report any bugs or feature requests to bug-check-supervisorctl at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Check-supervisorctl. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Check::supervisorctl

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2025 by Zane C. Bowers-Hadley.

This is free software, licensed under:

The GNU General Public License, Version 3, June 2007