|
NAMEMonitoring::Plugin - A family of perl modules to streamline writing Naemon, Nagios, Icinga or Shinken (and compatible) plugins.SYNOPSIS# 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 <host>] [-t <timeout>] " . "[ -c|--critical=<threshold> ] [ -w|--warning=<threshold> ]", ); # add valid command line options and build them into your usage/help documentation. $np->add_arg( spec => 'warning|w=s', help => '-w, --warning=INTEGER:INTEGER . See ' . 'https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT ' . 'for the threshold format. ', ); # 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 \ # | size=36kB;10:25;25: time=... DESCRIPTIONMonitoring::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.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). EXPORTSNagios status code constants are exported by default:OK WARNING CRITICAL UNKNOWN DEPENDENT The following variables are also exported on request:
CONSTRUCTORMonitoring::Plugin->new; Monitoring::Plugin->new( shortname => 'PAGESIZE' ); Monitoring::Plugin->new( usage => "Usage: %s [ -v|--verbose ] [-H <host>] [-t <timeout>] [ -c|--critical=<critical threshold> ] [ -w|--warning=<warning threshold> ] ", version => $VERSION, blurb => $blurb, extra => $extra, url => $url, license => $license, plugin => basename $0, timeout => 15, ); Instantiates a new Monitoring::Plugin object. Accepts the following named arguments:
GETTER/SETTERThe following internal variables can be retrieved or set by calling a method with the respective name. Expect for "shortname", don't change values unless you know what you're doing.Examples: use Data::Dumper; print Dumper($plugin->perfdata); $plugin->shortname('DifferentName');
OPTION HANDLING METHODS"Monitoring::Plugin" provides these methods for accessing the functionality in "Monitoring::Plugin::Getopt".
EXIT METHODS
THRESHOLD METHODSThese provide a top level interface to the "Monitoring::Plugin::Threshold" module; for more details, see Monitoring::Plugin::Threshold and Monitoring::Plugin::Range.
MESSAGE METHODSadd_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 @critical, @warning, and and @ok message arrays (add_message), and then doing a final if test (check_messages) like this:if (@critical) { plugin_exit( CRITICAL, join(' ', @critical) ); } elsif (@warning) { plugin_exit( WARNING, join(' ', @warning) ); } else { plugin_exit( OK, join(' ', @ok) ); }
PERFORMANCE DATA METHODS
EXAMPLES"Enough talk! Show me some examples!"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. VERSIONINGThe 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.SEE ALSOSee Monitoring::Plugin::Functions for a simple functional interface to a subset of the available Monitoring::Plugin functionality.See also Monitoring::Plugin::Getopt, Monitoring::Plugin::Range, Monitoring::Plugin::Performance, Monitoring::Plugin::Range, and Monitoring::Plugin::Threshold. The Monitoring Plugin project page is at http://monitoring-plugins.org. BUGSPlease report bugs in these modules to the Monitoring Plugin development team: devel@monitoring-plugins.org.AUTHORMaintained by the Monitoring Plugin development team - https://www.monitoring-plugins.org.Originally by Ton Voon, <ton.voon@altinity.com>. COPYRIGHT AND LICENSECopyright (C) 2014 by Monitoring Plugin Team Copyright (C) 2006-2014 by Nagios Plugin Development TeamThis 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.
Visit the GSP FreeBSD Man Page Interface. |