.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Monitoring::Plugin 3pm" .TH Monitoring::Plugin 3pm "2018-07-26" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Monitoring::Plugin \- A family of perl modules to streamline writing Naemon, Nagios, Icinga or Shinken (and compatible) plugins. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& # Constants OK, WARNING, CRITICAL, and UNKNOWN are exported by default \& # See also Monitoring::Plugin::Functions for a functional interface \& use Monitoring::Plugin; \& \& # Constructor \& $np = Monitoring::Plugin\->new; # OR \& $np = Monitoring::Plugin\->new( shortname => "PAGESIZE" ); # OR \& \& \& # use Monitoring::Plugin::Getopt to process the @ARGV command line options: \& # \-\-verbose, \-\-help, \-\-usage, \-\-timeout and \-\-host are defined automatically. \& $np = Monitoring::Plugin\->new( \& usage => "Usage: %s [ \-v|\-\-verbose ] [\-H ] [\-t ] " \& . "[ \-c|\-\-critical= ] [ \-w|\-\-warning= ]", \& ); \& \& # add valid command line options and build them into your usage/help documentation. \& $np\->add_arg( \& spec => \*(Aqwarning|w=s\*(Aq, \& help => \*(Aq\-w, \-\-warning=INTEGER:INTEGER . See \*(Aq \& . \*(Aqhttps://www.monitoring\-plugins.org/doc/guidelines.html#THRESHOLDFORMAT \*(Aq \& . \*(Aqfor the threshold format. \*(Aq, \& ); \& \& # Parse @ARGV and process standard arguments (e.g. usage, help, version) \& $np\->getopts; \& \& \& # Exit/return value methods \- plugin_exit( CODE, MESSAGE ), \& # plugin_die( MESSAGE, [CODE]) \& $page = retrieve_page($page1) \& or $np\->plugin_exit( UNKNOWN, "Could not retrieve page" ); \& # Return code: 3; \& # output: PAGESIZE UNKNOWN \- Could not retrieve page \& test_page($page) \& or $np\->plugin_exit( CRITICAL, "Bad page found" ); \& \& # plugin_die() is just like plugin_exit(), but return code defaults \& # to UNKNOWN \& $page = retrieve_page($page2) \& or $np\->plugin_die( "Could not retrieve page" ); \& # Return code: 3; \& # output: PAGESIZE UNKNOWN \- Could not retrieve page \& \& # Threshold methods \& $code = $np\->check_threshold( \& check => $value, \& warning => $warning_threshold, \& critical => $critical_threshold, \& ); \& $np\->plugin_exit( $code, "Threshold check failed" ) if $code != OK; \& \& # Message methods \& # add_message( CODE, $message ); check_messages() \& for (@collection) { \& if (m/Error/) { \& $np\->add_message( CRITICAL, $_ ); \& } else { \& $np\->add_message( OK, $_ ); \& } \& } \& ($code, $message) = $np\->check_messages(); \& plugin_exit( $code, $message ); \& # If any items in collection matched m/Error/, returns CRITICAL and \& # the joined set of Error messages; otherwise returns OK and the \& # joined set of ok messages \& \& \& # Perfdata methods \& $np\->add_perfdata( \& label => "size", \& value => $value, \& uom => "kB", \& threshold => $threshold, \& ); \& $np\->add_perfdata( label => "time", ... ); \& $np\->plugin_exit( OK, "page size at http://... was ${value}kB" ); \& # Return code: 0; \& # output: PAGESIZE OK \- page size at http://... was 36kB \e \& # | size=36kB;10:25;25: time=... .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Monitoring::Plugin and its associated Monitoring::Plugin::* modules are a family of perl modules to streamline writing Monitoring plugins. The main end user modules are Monitoring::Plugin, providing an object-oriented interface to the entire Monitoring::Plugin::* collection, and Monitoring::Plugin::Functions, providing a simpler functional interface to a useful subset of the available functionality. .PP The purpose of the collection is to make it as simple as possible for developers to create plugins that conform the Monitoring Plugin guidelines (https://www.monitoring\-plugins.org/doc/guidelines.html). .SS "\s-1EXPORTS\s0" .IX Subsection "EXPORTS" Nagios status code constants are exported by default: .PP .Vb 5 \& OK \& WARNING \& CRITICAL \& UNKNOWN \& DEPENDENT .Ve .PP The following variables are also exported on request: .ie n .IP "%ERRORS" 4 .el .IP "\f(CW%ERRORS\fR" 4 .IX Item "%ERRORS" A hash mapping error strings (\*(L"\s-1CRITICAL\*(R", \*(L"UNKNOWN\*(R",\s0 etc.) to the corresponding status code. .ie n .IP "%STATUS_TEXT" 4 .el .IP "\f(CW%STATUS_TEXT\fR" 4 .IX Item "%STATUS_TEXT" A hash mapping status code constants (\s-1OK, WARNING, CRITICAL,\s0 etc.) to the corresponding error string (\*(L"\s-1OK\*(R", \*(L"WARNING, \*(R"CRITICAL",\s0 etc.) i.e. the reverse of \f(CW%ERRORS\fR. .SS "\s-1CONSTRUCTOR\s0" .IX Subsection "CONSTRUCTOR" .Vb 1 \& Monitoring::Plugin\->new; \& \& Monitoring::Plugin\->new( shortname => \*(AqPAGESIZE\*(Aq ); \& \& Monitoring::Plugin\->new( \& usage => "Usage: %s [ \-v|\-\-verbose ] [\-H ] [\-t ] \& [ \-c|\-\-critical= ] [ \-w|\-\-warning= ] ", \& version => $VERSION, \& blurb => $blurb, \& extra => $extra, \& url => $url, \& license => $license, \& plugin => basename $0, \& timeout => 15, \& ); .Ve .PP Instantiates a new Monitoring::Plugin object. Accepts the following named arguments: .IP "shortname" 4 .IX Item "shortname" The 'shortname' for this plugin, used as the first token in the plugin output by the various exit methods. Default: uc basename \f(CW$0\fR. .ie n .IP "usage (""Usage: %s \-\-foo \-\-bar"")" 4 .el .IP "usage (``Usage: \f(CW%s\fR \-\-foo \-\-bar'')" 4 .IX Item "usage (Usage: %s --foo --bar)" Passing a value for the \fIusage()\fR argument makes Monitoring::Plugin instantiate its own \f(CW\*(C`Monitoring::Plugin::Getopt\*(C'\fR object so you can start doing command line argument processing. See \&\*(L"\s-1CONSTRUCTOR\*(R"\s0 in Monitoring::Plugin::Getopt for more about \*(L"usage\*(R" and the following options: .IP "version" 4 .IX Item "version" .PD 0 .IP "url" 4 .IX Item "url" .IP "blurb" 4 .IX Item "blurb" .IP "license" 4 .IX Item "license" .IP "extra" 4 .IX Item "extra" .IP "plugin" 4 .IX Item "plugin" .IP "timeout" 4 .IX Item "timeout" .PD .SS "\s-1GETTER/SETTER\s0" .IX Subsection "GETTER/SETTER" The following internal variables can be retrieved or set by calling a method with the respective name. Expect for \f(CW\*(C`shortname\*(C'\fR, don't change values unless you know what you're doing. .PP Examples: .PP .Vb 3 \& use Data::Dumper; \& print Dumper($plugin\->perfdata); \& $plugin\->shortname(\*(AqDifferentName\*(Aq); .Ve .IP "shortname" 4 .IX Item "shortname" .PD 0 .IP "perfdata" 4 .IX Item "perfdata" .IP "messages" 4 .IX Item "messages" .IP "opts" 4 .IX Item "opts" .IP "threshold" 4 .IX Item "threshold" .PD .SS "\s-1OPTION HANDLING METHODS\s0" .IX Subsection "OPTION HANDLING METHODS" \&\f(CW\*(C`Monitoring::Plugin\*(C'\fR provides these methods for accessing the functionality in \f(CW\*(C`Monitoring::Plugin::Getopt\*(C'\fR. .IP "add_arg" 4 .IX Item "add_arg" Examples: .Sp .Vb 6 \& # Define \-\-hello argument (named parameters) \& $plugin\->add_arg( \& spec => \*(Aqhello=s\*(Aq, \& help => "\-\-hello\en Hello string", \& required => 1, \& ); \& \& # Define \-\-hello argument (positional parameters) \& # Parameter order is \*(Aqspec\*(Aq, \*(Aqhelp\*(Aq, \*(Aqdefault\*(Aq, \*(Aqrequired?\*(Aq \& $plugin\->add_arg(\*(Aqhello=s\*(Aq, "\-\-hello\en Hello string", undef, 1); .Ve .Sp See \*(L"\s-1ARGUMENTS\*(R"\s0 in Monitoring::Plugin::Getopt for more details. .IP "\fIgetopts()\fR" 4 .IX Item "getopts()" Parses and processes the command line options you've defined, automatically doing the right thing with help/usage/version arguments. .Sp See \*(L"\s-1GETOPTS\*(R"\s0 in Monitoring::Plugin::Getopt for more details. .IP "\fIopts()\fR" 4 .IX Item "opts()" Assuming you've instantiated it by passing 'usage' to \fInew()\fR, \fIopts()\fR returns the Monitoring::Plugin object's \f(CW\*(C`Monitoring::Plugin::Getopt\*(C'\fR object, with which you can do lots of great things. .Sp E.g. .Sp .Vb 3 \& if ( $plugin\->opts\->verbose ) { \& print "yah yah YAH YAH YAH!!!"; \& } \& \& # start counting down to timeout \& alarm $plugin\->opts\->timeout; \& your_long_check_step_that_might_time_out(); \& \& # access any of your custom command line options, \& # assuming you\*(Aqve done these steps above: \& # $plugin\->add_arg(\*(Aqmy_argument=s\*(Aq, \*(Aq\-\-my_argument [STRING]\*(Aq); \& # $plugin\->getopts; \& print $plugin\->opts\->my_argument; .Ve .Sp Again, see Monitoring::Plugin::Getopt. .SS "\s-1EXIT METHODS\s0" .IX Subsection "EXIT METHODS" .ie n .IP "plugin_exit( <\s-1CODE\s0>, $message )" 4 .el .IP "plugin_exit( <\s-1CODE\s0>, \f(CW$message\fR )" 4 .IX Item "plugin_exit( , $message )" Exit with return code \s-1CODE,\s0 and a standard nagios message of the form \*(L"\s-1SHORTNAME CODE\s0 \- \f(CW$message\fR\*(R". .ie n .IP "nagios_exit( <\s-1CODE\s0>, $message )" 4 .el .IP "nagios_exit( <\s-1CODE\s0>, \f(CW$message\fR )" 4 .IX Item "nagios_exit( , $message )" Alias for \fIplugin_exit()\fR. Deprecated. .ie n .IP "plugin_die( $message, [<\s-1CODE\s0>] )" 4 .el .IP "plugin_die( \f(CW$message\fR, [<\s-1CODE\s0>] )" 4 .IX Item "plugin_die( $message, [] )" Same as \fIplugin_exit()\fR, except that \s-1CODE\s0 is optional, defaulting to \s-1UNKNOWN.\s0 \s-1NOTE:\s0 exceptions are not raised by default to calling code. Set \f(CW$_use_die\fR flag if this functionality is required (see test code). .ie n .IP "nagios_die( $message, [<\s-1CODE\s0>] )" 4 .el .IP "nagios_die( \f(CW$message\fR, [<\s-1CODE\s0>] )" 4 .IX Item "nagios_die( $message, [] )" Alias for \fIplugin_die()\fR. Deprecated. .ie n .IP "die( $message, [<\s-1CODE\s0>] )" 4 .el .IP "die( \f(CW$message\fR, [<\s-1CODE\s0>] )" 4 .IX Item "die( $message, [] )" Alias for \fIplugin_die()\fR. Deprecated. .IP "max_state, max_state_alt" 4 .IX Item "max_state, max_state_alt" These are wrapper function for Monitoring::Plugin::Functions::max_state and Monitoring::Plugin::Functions::max_state_alt. .SS "\s-1THRESHOLD METHODS\s0" .IX Subsection "THRESHOLD METHODS" These provide a top level interface to the \&\f(CW\*(C`Monitoring::Plugin::Threshold\*(C'\fR module; for more details, see Monitoring::Plugin::Threshold and Monitoring::Plugin::Range. .ie n .IP "check_threshold( $value )" 4 .el .IP "check_threshold( \f(CW$value\fR )" 4 .IX Item "check_threshold( $value )" .PD 0 .ie n .IP "check_threshold( check => $value, warning => $warn, critical => $crit )" 4 .el .IP "check_threshold( check => \f(CW$value\fR, warning => \f(CW$warn\fR, critical => \f(CW$crit\fR )" 4 .IX Item "check_threshold( check => $value, warning => $warn, critical => $crit )" .PD Evaluates \f(CW$value\fR against the thresholds and returns \s-1OK, CRITICAL,\s0 or \&\s-1WARNING\s0 constant. The thresholds may be: .Sp 1. explicitly set by passing 'warning' and/or 'critical' parameters to \f(CW\*(C`check_threshold()\*(C'\fR, or, .Sp 2. explicitly set by calling \f(CW\*(C`set_thresholds()\*(C'\fR before \f(CW\*(C`check_threshold()\*(C'\fR, or, .Sp 3. implicitly set by command-line parameters \-w, \-c, \-\-critical or \-\-warning, if you have run \f(CW\*(C`$plugin\->getopts()\*(C'\fR. .Sp You can specify \f(CW$value\fR as an array of values and each will be checked against the thresholds. .Sp The return value is ready to pass to C , e . g ., .Sp .Vb 4 \& $p\->plugin_exit( \& return_code => $p\->check_threshold($result), \& message => " sample result was $result" \& ); .Ve .ie n .IP "set_thresholds(warning => ""10:25"", critical => ""~:25"")" 4 .el .IP "set_thresholds(warning => ``10:25'', critical => ``~:25'')" 4 .IX Item "set_thresholds(warning => 10:25, critical => ~:25)" Sets the acceptable ranges and creates the plugin's Monitoring::Plugins::Threshold object. See https://www.monitoring\-plugins.org/doc/guidelines.html#THRESHOLDFORMAT for details and examples of the threshold format. .IP "\fIthreshold()\fR" 4 .IX Item "threshold()" Returns the object's \f(CW\*(C`Monitoring::Plugin::Threshold\*(C'\fR object, if it has been defined by calling \fIset_thresholds()\fR. You can pass a new Threshold object to it to replace the old one too, but you shouldn't need to do that from a plugin script. .SS "\s-1MESSAGE METHODS\s0" .IX Subsection "MESSAGE METHODS" add_messages and check_messages are higher-level convenience methods to add and then check a set of messages, returning an appropriate return code and/or result message. They are equivalent to maintaining a set of \f(CW@critical\fR, \&\f(CW@warning\fR, and and \f(CW@ok\fR message arrays (add_message), and then doing a final if test (check_messages) like this: .PP .Vb 9 \& if (@critical) { \& plugin_exit( CRITICAL, join(\*(Aq \*(Aq, @critical) ); \& } \& elsif (@warning) { \& plugin_exit( WARNING, join(\*(Aq \*(Aq, @warning) ); \& } \& else { \& plugin_exit( OK, join(\*(Aq \*(Aq, @ok) ); \& } .Ve .ie n .IP "add_message( <\s-1CODE\s0>, $message )" 4 .el .IP "add_message( <\s-1CODE\s0>, \f(CW$message\fR )" 4 .IX Item "add_message( , $message )" Add a message with \s-1CODE\s0 status to the object. May be called multiple times. The messages added are checked by check_messages, following. .Sp Only \s-1CRITICAL, WARNING,\s0 and \s-1OK\s0 are accepted as valid codes. .IP "\fIcheck_messages()\fR" 4 .IX Item "check_messages()" Check the current set of messages and return an appropriate nagios return code and/or a result message. In scalar context, returns only a return code; in list context returns both a return code and an output message, suitable for passing directly to \fIplugin_exit()\fR e.g. .Sp .Vb 2 \& $code = $np\->check_messages; \& ($code, $message) = $np\->check_messages; .Ve .Sp check_messages returns \s-1CRITICAL\s0 if any critical messages are found, \s-1WARNING\s0 if any warning messages are found, and \s-1OK\s0 otherwise. The message returned in list context defaults to the joined set of error messages; this may be customised using the arguments below. .Sp check_messages accepts the following named arguments (none are required): .RS 4 .IP "join => \s-1SCALAR\s0" 4 .IX Item "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 \f(CW@crit\fR is non-empty, check_messages would return: .Sp .Vb 1 \& join( $join, @crit ) .Ve .Sp as the result message. Default: ' ' (space). .IP "join_all => \s-1SCALAR\s0" 4 .IX Item "join_all => SCALAR" By default, only one set of messages are joined and returned in the result message i.e. if the result is \s-1CRITICAL,\s0 only the 'critical' messages are included in the result; if \s-1WARNING,\s0 only the 'warning' messages are included; if \s-1OK,\s0 the 'ok' messages are included (if supplied) i.e. the default is to return an 'errors\-only' type message. .Sp 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. .IP "critical => \s-1ARRAYREF\s0" 4 .IX Item "critical => ARRAYREF" Additional critical messages to supplement any passed in via \fIadd_message()\fR. .IP "warning => \s-1ARRAYREF\s0" 4 .IX Item "warning => ARRAYREF" Additional warning messages to supplement any passed in via \fIadd_message()\fR. .IP "ok => \s-1ARRAYREF\s0 | \s-1SCALAR\s0" 4 .IX Item "ok => ARRAYREF | SCALAR" Additional ok messages to supplement any passed in via \fIadd_message()\fR. .RE .RS 4 .RE .SS "\s-1PERFORMANCE DATA METHODS\s0" .IX Subsection "PERFORMANCE DATA METHODS" .ie n .IP "add_perfdata( label => ""size"", value => $value, uom => ""kB"", threshold => $threshold )" 4 .el .IP "add_perfdata( label => ``size'', value => \f(CW$value\fR, uom => ``kB'', threshold => \f(CW$threshold\fR )" 4 .IX Item "add_perfdata( label => size, value => $value, uom => kB, threshold => $threshold )" Add a set of performance data to the object. May be called multiple times. The performance data is included in the standard plugin output messages by the various exit methods. .Sp See the Monitoring::Plugin::Performance documentation for more information on performance data and the various field definitions, as well as the relevant section of the Monitoring Plugin guidelines (https://www.monitoring\-plugins.org/doc/guidelines.html#AEN202). .SH "EXAMPLES" .IX Header "EXAMPLES" \&\*(L"Enough talk! Show me some examples!\*(R" .PP See the file 'check_stuff.pl' in the 't' directory included with the Monitoring::Plugin distribution for a complete working example of a plugin script. .SH "VERSIONING" .IX Header "VERSIONING" The Monitoring::Plugin::* modules are currently experimental and so the interfaces may change up until Monitoring::Plugin hits version 1.0, although every attempt will be made to keep them as backwards compatible as possible. .SH "SEE ALSO" .IX Header "SEE ALSO" See Monitoring::Plugin::Functions for a simple functional interface to a subset of the available Monitoring::Plugin functionality. .PP See also Monitoring::Plugin::Getopt, Monitoring::Plugin::Range, Monitoring::Plugin::Performance, Monitoring::Plugin::Range, and Monitoring::Plugin::Threshold. .PP The Monitoring Plugin project page is at http://monitoring\-plugins.org. .SH "BUGS" .IX Header "BUGS" Please report bugs in these modules to the Monitoring Plugin development team: devel@monitoring\-plugins.org. .SH "AUTHOR" .IX Header "AUTHOR" Maintained by the Monitoring Plugin development team \- https://www.monitoring\-plugins.org. .PP Originally by Ton Voon, . .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2014 by Monitoring Plugin Team Copyright (C) 2006\-2014 by Nagios Plugin Development Team .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.