Nagios:...unctions(3)
πΈ NAME πΈ
okay bestie, welcome to the Nagios::Plugin::Functions(3) page β manual name: User Contributed Perl Documentation. The actual NAME vibe is: Nagios::Plugin::Functions β functions to simplify the creation of Nagios plugins. slay π
β¨ SYNOPSIS β¨
here's the whole starter pack, bestie:
# Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default
use Nagios::Plugin::Functions;
# nagios_exit( CODE, $message ) - exit with error code CODE,
# and message "PLUGIN CODE - $message"
nagios_exit( CRITICAL, $critical_error ) if $critical_error;
nagios_exit( WARNING, $warning_error ) if $warning_error;
nagios_exit( OK, $result );
# nagios_die( $message, [$CODE] ) - just like nagios_exit(),
# but CODE is optional, defaulting to UNKNOWN
do_something()
or nagios_die("do_something() failed horribly");
do_something_critical()
or nagios_die("do_something_critical() failed", CRITICAL);
# check_messages - check a set of message arrays, returning a
# CODE and/or a result message
$code = check_messages(critical => \@crit, warning => \@warn);
($code, $message) = check_messages(
critical => \@crit, warning => \@warn,
ok => \@ok );
# get_shortname - return the default short name for this plugin
# (as used by nagios_exit/die; not exported by default)
$shortname = get_shortname();
π DESCRIPTION π
This module is part of the Nagios::Plugin family, a set of modules for simplifying the creation of Nagios plugins. It's giving "less ceremony, more plugin." This module exports convenience functions for the class methods provided by Nagios::Plugin. It is intended for those who prefer a simpler functional interface, and who do not need the additional functionality of Nagios::Plugin. periodt π
π EXPORTS π
Nagios status code constants are exported by default:
OKWARNINGCRITICALUNKNOWNDEPENDENT
as are the following functions:
nagios_exitnagios_diecheck_messages
The following variables and functions are exported only on request:
%ERRORS%STATUS_TEXTget_shortnamemax_statemax_state_alt
π οΈ FUNCTIONS π οΈ
The following functions are supported:
nagios_exit( <CODE>, $message )
Exit with return code CODE, and a standard nagios message of the form "PLUGIN CODE - $message". clean, loud, and on brand. β¨
nagios_die( $message, [CODE] )
Same as nagios_exit(), except that CODE is optional, defaulting to UNKNOWN. NOTE: exceptions are not raised by default to calling code. Set $_use_die flag if this functionality is required (see test code). π
check_messages( critical => \@crit, warning => \@warn )
Convenience function to check a set of message arrays and return an appropriate nagios return code and/or a result message. Returns only a return code in scalar context; returns a return code and an error message in list context i.e.
# Scalar context
$code = check_messages(critical => \@crit, warning => \@warn);
# List context
($code, $msg) = check_messages(critical => \@crit, warning => \@warn);
check_messages() accepts the following named arguments:
critical => ARRAYREFβ an arrayref of critical error messages βcheck_messages()returnsCRITICALif this arrayref is non-empty. Mandatory.warning => ARRAYREFβ an arrayref of warning error messages βcheck_messages()returnsWARNINGif this arrayref is non-empty ('critical'is checked first). Mandatory.ok => ARRAYREF | SCALARβ an arrayref of informational messages (or a single scalar message), used in list context if both the'critical'and'warning'arrayrefs are empty. Optional.join => SCALARβ a string used to join the relevant array to generate the message string returned in list context i.e. if the'critical'array@critis non-empty,check_messageswould returnjoin( $join, @crit )as the result message. Optional; default:' '(space).join_all => SCALARβ by default, only one set of messages are joined and returned in the result message i.e. if the result isCRITICAL, only the'critical'messages are included in the result; ifWARNING, only the'warning'messages are included; ifOK, the'ok'messages are included (if supplied) i.e. the default is to return an'errors-only'type message.
If join_all is supplied, however, it will be used as a string to join the resultant critical, warning, and ok messages together i.e. all messages are joined and returned. one big group chat of errors, iconic. π
get_shortname
Return the default shortname used for this plugin i.e. the first token reported by nagios_exit/nagios_die. The default is basically
uc basename( $ENV{NAGIOS_PLUGIN} || $0 )
with any leading 'CHECK_' and trailing file suffixes removed.
get_shortname is not exported by default, so must be explicitly imported. iykyk β¨
max_state(@a)
Returns the worst state in the array. Order is: CRITICAL, WARNING, OK, UNKNOWN, DEPENDENT.
The typical usage of max_state is to initialise the state as UNKNOWN and use it on the result of various test. If no test were performed successfully the state will still be UNKNOWN. lowkey a safety net.
max_state_alt(@a)
Returns the worst state in the array. Order is: CRITICAL, WARNING, UNKNOWN, DEPENDENT, OK.
This is a true definition of a max state (OK last) and should be used if the internal tests performed can return UNKNOWN. main character state logic. π
π SEE ALSO π
Nagios::Plugin; the nagios plugin developer guidelines at http://nagiosplug.sourceforge.net/developer-guidelines.html. go read, bestie.
π«Ά AUTHORS π«Ά
This code is maintained by the Nagios Plugin Development Team: http://nagiosplug.sourceforge.net
π COPYRIGHT AND LICENSE π
Copyright (C) 2006 by Nagios Plugin Development Team
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the page bestie β footer vibes say perl v5.42.0 and 2024-03-04, so that's the source/version and date. bye slay πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Nagios-Plugin 0.36-bp160.1.8 Β· Artistic-1.0 or GPL-2.0+
- opensuse-leap 16.0: perl-Nagios-Plugin 0.36-bp160.1.8 Β· Artistic-1.0 or GPL-2.0+
- opensuse-leap 16.0: perl-Nagios-Plugin 0.36-bp160.1.8 Β· Artistic-1.0 or GPL-2.0+
- opensuse-leap 16.0: perl-Nagios-Plugin 0.36-bp160.1.8 Β· Artistic-1.0 or GPL-2.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms