From 79b36b4d71afeb016a3b4764b6b484754323b011 Mon Sep 17 00:00:00 2001 From: Gavin Carr Date: Sat, 11 Nov 2006 05:18:46 +0000 Subject: Add get_shortname to NP::Functions export_ok list; update perldocs. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1537 f882894a-f735-0410-b71e-b25c423dba1c 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); require Exporter; our @ISA = qw(Exporter); our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages)); -our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES); +our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT @STATUS_CODES get_shortname); our %EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_OK ], codes => [ @STATUS_CODES ], @@ -224,6 +224,10 @@ Nagios plugins. critical => \@crit, warning => \@warn, ok => \@ok ); + # get_shortname - return the default short name for this plugin + # (as used by nagios_exit/die; not exported by default) + $shortname = get_shortname(); + =head1 DESCRIPTION @@ -250,10 +254,11 @@ as are the following functions: nagios_die check_messages -The following variables are exported only on request: +The following variables and functions are exported only on request: %ERRORS %STATUS_TEXT + get_shortname =head2 FUNCTIONS @@ -330,6 +335,18 @@ all messages are joined and returned. =back +=item get_shortname + +Return the default shortname used for this plugin i.e. the first +token reported by nagios_exit/nagios_die. The default is basically + + uc basename( $ENV{NAGIOS_PLUGIN} || $0 ) + +with any leading 'CHECK_' and trailing file suffixes removed. + +get_shortname is not exported by default, so must be explicitly +imported. + =back 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 @@ use strict; -use Test::More tests => 111; +use Test::More tests => 112; BEGIN { use_ok("Nagios::Plugin::Functions", ":all"); } Nagios::Plugin::Functions::_fake_exit(1); @@ -15,6 +15,9 @@ foreach my $m ("", qw(::Threshold ::Getopt ::Performance ::Range)) { is($a, $this_version, "Version number for $mod the same as Functions: $this_version"); } +# check get_shortname +is(get_shortname, "NAGIOS-PLUGIN-FUNCTIONS-01", "get_shortname ok"); + # Hardcoded checks of constants ok(defined %ERRORS, '%ERRORS defined'); is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}"); -- cgit v0.10-9-g596f