From c128d293b015291c5e45637d9e3d5b1e1fb36c12 Mon Sep 17 00:00:00 2001 From: Thomas Guyot-Sionnest Date: Wed, 10 Mar 2010 01:54:06 -0500 Subject: shortname enhancement This patch makes shortname use the defined plugin's name if set, otherwise the normal method should prevail. To do so I had to generate shortname during np initialization instead of at use time. --- lib/Nagios/Plugin/Functions.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/Nagios/Plugin') diff --git a/lib/Nagios/Plugin/Functions.pm b/lib/Nagios/Plugin/Functions.pm index 4ff6118..65200ec 100644 --- a/lib/Nagios/Plugin/Functions.pm +++ b/lib/Nagios/Plugin/Functions.pm @@ -54,12 +54,15 @@ my $_use_die = 0; sub _use_die { @_ ? $_use_die = shift : $_use_die }; sub get_shortname { - my %arg = @_; + my $arg = shift; - return $arg{plugin}->shortname if $arg{plugin}; + my $shortname = undef; - my $shortname = uc basename($ENV{NAGIOS_PLUGIN} || $0); - $shortname =~ s/^CHECK_//; # Remove any leading CHECK_ + return $arg->{shortname} if (defined($arg->{shortname})); + $shortname = $arg->{plugin} if (defined( $arg->{plugin})); + + $shortname = uc basename($shortname || $ENV{NAGIOS_PLUGIN} || $0); + $shortname =~ s/^CHECK_(?:BY_)?//; # Remove any leading CHECK_[BY_] $shortname =~ s/\..*$//; # Remove any trailing suffix return $shortname; } @@ -116,7 +119,8 @@ sub nagios_exit { # Setup output my $output = "$STATUS_TEXT{$code}"; $output .= " - $message" if defined $message && $message ne ''; - my $shortname = get_shortname(plugin => $arg->{plugin}); + my $shortname = ($arg->{plugin} ? $arg->{plugin}->shortname : undef); + $shortname ||= get_shortname(); # Should happen only if funnctions are called directly $output = "$shortname $output" if $shortname; if ($arg->{plugin}) { my $plugin = $arg->{plugin}; -- cgit v1.2.3-74-g34f1