summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Nagios/Plugin/Functions.pm21
-rw-r--r--t/Nagios-Plugin-Functions-01.t5
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm
index 41ec27a..9983456 100644
--- a/lib/Nagios/Plugin/Functions.pm
+++ b/lib/Nagios/Plugin/Functions.pm
@@ -18,7 +18,7 @@ our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT);
18require Exporter; 18require Exporter;
19our @ISA = qw(Exporter); 19our @ISA = qw(Exporter);
20our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); 20our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages));
21our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES); 21our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname);
22our %EXPORT_TAGS = ( 22our %EXPORT_TAGS = (
23 all => [ @EXPORT, @EXPORT_OK ], 23 all => [ @EXPORT, @EXPORT_OK ],
24 codes => [ @STATUS_CODES ], 24 codes => [ @STATUS_CODES ],
@@ -224,6 +224,10 @@ Nagios plugins.
224 critical => \@crit, warning => \@warn, 224 critical => \@crit, warning => \@warn,
225 ok => \@ok ); 225 ok => \@ok );
226 226
227 # get_shortname - return the default short name for this plugin
228 # (as used by nagios_exit/die; not exported by default)
229 $shortname = get_shortname();
230
227 231
228=head1 DESCRIPTION 232=head1 DESCRIPTION
229 233
@@ -250,10 +254,11 @@ as are the following functions:
250 nagios_die 254 nagios_die
251 check_messages 255 check_messages
252 256
253The following variables are exported only on request: 257The following variables and functions are exported only on request:
254 258
255 %ERRORS 259 %ERRORS
256 %STATUS_TEXT 260 %STATUS_TEXT
261 get_shortname
257 262
258 263
259=head2 FUNCTIONS 264=head2 FUNCTIONS
@@ -330,6 +335,18 @@ all messages are joined and returned.
330 335
331=back 336=back
332 337
338=item get_shortname
339
340Return the default shortname used for this plugin i.e. the first
341token reported by nagios_exit/nagios_die. The default is basically
342
343 uc basename( $ENV{NAGIOS_PLUGIN} || $0 )
344
345with any leading 'CHECK_' and trailing file suffixes removed.
346
347get_shortname is not exported by default, so must be explicitly
348imported.
349
333=back 350=back
334 351
335 352
diff --git a/t/Nagios-Plugin-Functions-01.t b/t/Nagios-Plugin-Functions-01.t
index 7401945..70db221 100644
--- a/t/Nagios-Plugin-Functions-01.t
+++ b/t/Nagios-Plugin-Functions-01.t
@@ -1,6 +1,6 @@
1 1
2use strict; 2use strict;
3use Test::More tests => 111; 3use Test::More tests => 112;
4 4
5BEGIN { use_ok("Nagios::Plugin::Functions", ":all"); } 5BEGIN { use_ok("Nagios::Plugin::Functions", ":all"); }
6Nagios::Plugin::Functions::_fake_exit(1); 6Nagios::Plugin::Functions::_fake_exit(1);
@@ -15,6 +15,9 @@ foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) {
15 is($a, $this_version, "Version number for $mod the same as Functions: $this_version"); 15 is($a, $this_version, "Version number for $mod the same as Functions: $this_version");
16} 16}
17 17
18# check get_shortname
19is(get_shortname, "NAGIOS-PLUGIN-FUNCTIONS-01", "get_shortname ok");
20
18# Hardcoded checks of constants 21# Hardcoded checks of constants
19ok(defined %ERRORS, '%ERRORS defined'); 22ok(defined %ERRORS, '%ERRORS defined');
20is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}"); 23is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");