1Nagios::Plugin::FunctioUnsse(r3)Contributed Perl DocumenNtaagtiioosn::Plugin::Functions(3)
2
3
4
6 Nagios::Plugin::Functions - functions to simplify the creation of
7 Nagios plugins
8
10 # Constants OK, WARNING, CRITICAL, and UNKNOWN exported by default
11 use Nagios::Plugin::Functions;
12
13 # nagios_exit( CODE, $message ) - exit with error code CODE,
14 # and message "PLUGIN CODE - $message"
15 nagios_exit( CRITICAL, $critical_error ) if $critical_error;
16 nagios_exit( WARNING, $warning_error ) if $warning_error;
17 nagios_exit( OK, $result );
18
19 # nagios_die( $message, [$CODE] ) - just like nagios_exit(),
20 # but CODE is optional, defaulting to UNKNOWN
21 do_something()
22 or nagios_die("do_something() failed horribly");
23 do_something_critical()
24 or nagios_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 nagios_exit/die; not exported by default)
35 $shortname = get_shortname();
36
38 This module is part of the Nagios::Plugin family, a set of modules for
39 simplifying the creation of Nagios plugins. This module exports
40 convenience functions for the class methods provided by Nagios::Plugin.
41 It is intended for those who prefer a simpler functional interface, and
42 who do not need the additional functionality of Nagios::Plugin.
43
44 EXPORTS
45 Nagios status code constants are exported by default:
46
47 OK
48 WARNING
49 CRITICAL
50 UNKNOWN
51 DEPENDENT
52
53 as are the following functions:
54
55 nagios_exit
56 nagios_die
57 check_messages
58
59 The following variables and functions are exported only on request:
60
61 %ERRORS
62 %STATUS_TEXT
63 get_shortname
64 max_state
65 max_state_alt
66
67 FUNCTIONS
68 The following functions are supported:
69
70 nagios_exit( <CODE>, $message )
71 Exit with return code CODE, and a standard nagios message of the
72 form "PLUGIN CODE - $message".
73
74 nagios_die( $message, [CODE] )
75 Same as nagios_exit(), except that CODE is optional, defaulting to
76 UNKNOWN. NOTE: exceptions are not raised by default to calling
77 code. Set $_use_die flag if this functionality is required (see
78 test code).
79
80 check_messages( critical => \@crit, warning => \@warn )
81 Convenience function to check a set of message arrays and return an
82 appropriate nagios return code and/or a result message. Returns
83 only a return code in scalar context; returns a return code and an
84 error message in list context i.e.
85
86 # Scalar context
87 $code = check_messages(critical => \@crit, warning => \@warn);
88 # List context
89 ($code, $msg) = check_messages(critical => \@crit, warning => \@warn);
90
91 check_messages() accepts the following named arguments:
92
93 critical => ARRAYREF
94 An arrayref of critical error messages - check_messages()
95 returns CRITICAL if this arrayref is non-empty. Mandatory.
96
97 warning => ARRAYREF
98 An arrayref of warning error messages - check_messages()
99 returns WARNING if this arrayref is non-empty ('critical' is
100 checked first). Mandatory.
101
102 ok => ARRAYREF | SCALAR
103 An arrayref of informational messages (or a single scalar
104 message), used in list context if both the 'critical' and
105 'warning' arrayrefs are empty. Optional.
106
107 join => SCALAR
108 A string used to join the relevant array to generate the
109 message string returned in list context i.e. if the 'critical'
110 array @crit is non-empty, check_messages would return:
111
112 join( $join, @crit )
113
114 as the result message. Optional; default: ' ' (space).
115
116 join_all => SCALAR
117 By default, only one set of messages are joined and returned in
118 the result message i.e. if the result is CRITICAL, only the
119 'critical' messages are included in the result; if WARNING,
120 only the 'warning' messages are included; if OK, the 'ok'
121 messages are included (if supplied) i.e. the default is to
122 return an 'errors-only' type message.
123
124 If join_all is supplied, however, it will be used as a string
125 to join the resultant critical, warning, and ok messages
126 together i.e. all messages are joined and returned.
127
128 get_shortname
129 Return the default shortname used for this plugin i.e. the
130 first token reported by nagios_exit/nagios_die. The default is
131 basically
132
133 uc basename( $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,
142 WARNING, 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
146 were 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,
150 WARNING, UNKNOWN, DEPENDENT, OK
151
152 This is a true definition of a max state (OK last) and should
153 be used if the internal tests performed can return UNKNOWN.
154
156 Nagios::Plugin; the nagios plugin developer guidelines at
157 http://nagiosplug.sourceforge.net/developer-guidelines.html.
158
160 This code is maintained by the Nagios Plugin Development Team:
161 http://nagiosplug.sourceforge.net
162
164 Copyright (C) 2006 by Nagios Plugin Development Team
165
166 This library is free software; you can redistribute it and/or modify it
167 under the same terms as Perl itself.
168
170 Hey! The above document had some coding errors, which are explained
171 below:
172
173 Around line 426:
174 You forgot a '=back' before '=head1'
175
176
177
178perl v5.12.1 2010-04-15 Nagios::Plugin::Functions(3)