1Monitoring::Plugin::FunUcsteironCso(n3t)ributed Perl DocMuomneinttoartiinogn::Plugin::Functions(3)
2
3
4

NAME

6       Monitoring::Plugin::Functions - functions to simplify the creation of
7       Nagios plugins
8

SYNOPSIS

10           # Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default
11           use Monitoring::Plugin::Functions;
12
13           # plugin_exit( CODE, $message ) - exit with error code CODE,
14           # and message "PLUGIN CODE - $message"
15           plugin_exit( CRITICAL, $critical_error ) if $critical_error;
16           plugin_exit( WARNING, $warning_error )   if $warning_error;
17           plugin_exit( OK, $result );
18
19           # plugin_die( $message, [$CODE] ) - just like plugin_exit(),
20           # but CODE is optional, defaulting to UNKNOWN
21           do_something()
22             or plugin_die("do_something() failed horribly");
23           do_something_critical()
24             or plugin_die("do_something_critical() failed", CRITICAL);
25
26           # check_messages - check a set of message arrays, returning a
27           # CODE and/or a result message
28           $code = check_messages(critical => \@crit, warning => \@warn);
29           ($code, $message) = check_messages(
30             critical => \@crit, warning => \@warn,
31             ok => \@ok );
32
33           # get_shortname - return the default short name for this plugin
34           #   (as used by plugin_exit/die; not exported by default)
35           $shortname = get_shortname();
36

DESCRIPTION

38       This module is part of the Monitoring::Plugin family, a set of modules
39       for simplifying the creation of Nagios plugins. This module exports
40       convenience functions for the class methods provided by
41       Monitoring::Plugin. It is intended for those who prefer a simpler
42       functional interface, and who do not need the additional functionality
43       of Monitoring::Plugin.
44
45   EXPORTS
46       Nagios status code constants are exported by default:
47
48           OK
49           WARNING
50           CRITICAL
51           UNKNOWN
52           DEPENDENT
53
54       as are the following functions:
55
56           plugin_exit
57           plugin_die
58           check_messages
59
60       The following variables and functions are exported only on request:
61
62           %ERRORS
63           %STATUS_TEXT
64           get_shortname
65           max_state
66           max_state_alt
67
68   FUNCTIONS
69       The following functions are supported:
70
71       plugin_exit( <CODE>, $message )
72           Exit with return code CODE, and a standard nagios message of the
73           form "PLUGIN CODE - $message".
74
75       plugin_die( $message, [CODE] )
76           Same as plugin_exit(), except that CODE is optional, defaulting to
77           UNKNOWN.  NOTE: exceptions are not raised by default to calling
78           code.  Set $_use_die flag if this functionality is required (see
79           test code).
80
81       check_messages( critical => \@crit, warning => \@warn )
82           Convenience function to check a set of message arrays and return an
83           appropriate nagios return code and/or a result message. Returns
84           only a return code in scalar context; returns a return code and an
85           error message in list context i.e.
86
87               # Scalar context
88               $code = check_messages(critical => \@crit, warning => \@warn);
89               # List context
90               ($code, $msg) = check_messages(critical => \@crit, warning => \@warn);
91
92           check_messages() accepts the following named arguments:
93
94           critical => ARRAYREF
95               An arrayref of critical error messages - check_messages()
96               returns CRITICAL if this arrayref is non-empty. Mandatory.
97
98           warning => ARRAYREF
99               An arrayref of warning error messages - check_messages()
100               returns WARNING if this arrayref is non-empty ('critical' is
101               checked first). Mandatory.
102
103           ok => ARRAYREF | SCALAR
104               An arrayref of informational messages (or a single scalar
105               message), used in list context if both the 'critical' and
106               'warning' arrayrefs are empty. Optional.
107
108           join => SCALAR
109               A string used to join the relevant array to generate the
110               message string returned in list context i.e. if the 'critical'
111               array @crit is non-empty, check_messages would return:
112
113                   join( $join, @crit )
114
115               as the result message. Optional; default: ' ' (space).
116
117           join_all => SCALAR
118               By default, only one set of messages are joined and returned in
119               the result message i.e. if the result is CRITICAL, only the
120               'critical' messages are included in the result; if WARNING,
121               only the 'warning' messages are included; if OK, the 'ok'
122               messages are included (if supplied) i.e. the default is to
123               return an 'errors-only' type message.
124
125               If join_all is supplied, however, it will be used as a string
126               to join the resultant critical, warning, and ok messages
127               together i.e.  all messages are joined and returned.
128
129       get_shortname
130           Return the default shortname used for this plugin i.e. the first
131           token reported by plugin_exit/plugin_die. The default is basically
132
133               uc basename( $ENV{PLUGIN_NAME} || $ENV{NAGIOS_PLUGIN} || $0 )
134
135           with any leading 'CHECK_' and trailing file suffixes removed.
136
137           get_shortname is not exported by default, so must be explicitly
138           imported.
139
140       max_state(@a)
141           Returns the worst state in the array. Order is: CRITICAL, WARNING,
142           OK, UNKNOWN, DEPENDENT
143
144           The typical usage of max_state is to initialise the state as
145           UNKNOWN and use it on the result of various test. If no test were
146           performed successfully the state will still be UNKNOWN.
147
148       max_state_alt(@a)
149           Returns the worst state in the array. Order is: CRITICAL, WARNING,
150           UNKNOWN, DEPENDENT, OK
151
152           This is a true definition of a max state (OK last) and should be
153           used if the internal tests performed can return UNKNOWN.
154

SEE ALSO

156       Monitoring::Plugin; the nagios plugin developer guidelines at
157       https://www.monitoring-plugins.org/doc/guidelines.html.
158

AUTHOR

160       This code is maintained by the Monitoring Plugin Development Team: see
161       https://monitoring-plugins.org
162
164       Copyright (C) 2014      by Monitoring Plugin Team Copyright (C)
165       2006-2014 by Nagios Plugin Development Team
166
167       This library is free software; you can redistribute it and/or modify it
168       under the same terms as Perl itself.
169
170
171
172perl v5.32.0                      2020-07-28  Monitoring::Plugin::Functions(3)
Impressum