summaryrefslogtreecommitdiffstats
path: root/lib/Nagios/Plugin/Functions.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Nagios/Plugin/Functions.pm')
-rw-r--r--lib/Nagios/Plugin/Functions.pm14
1 files changed, 9 insertions, 5 deletions
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;
54sub _use_die { @_ ? $_use_die = shift : $_use_die }; 54sub _use_die { @_ ? $_use_die = shift : $_use_die };
55 55
56sub get_shortname { 56sub get_shortname {
57 my %arg = @_; 57 my $arg = shift;
58 58
59 return $arg{plugin}->shortname if $arg{plugin}; 59 my $shortname = undef;
60 60
61 my $shortname = uc basename($ENV{NAGIOS_PLUGIN} || $0); 61 return $arg->{shortname} if (defined($arg->{shortname}));
62 $shortname =~ s/^CHECK_//; # Remove any leading CHECK_ 62 $shortname = $arg->{plugin} if (defined( $arg->{plugin}));
63
64 $shortname = uc basename($shortname || $ENV{NAGIOS_PLUGIN} || $0);
65 $shortname =~ s/^CHECK_(?:BY_)?//; # Remove any leading CHECK_[BY_]
63 $shortname =~ s/\..*$//; # Remove any trailing suffix 66 $shortname =~ s/\..*$//; # Remove any trailing suffix
64 return $shortname; 67 return $shortname;
65} 68}
@@ -116,7 +119,8 @@ sub nagios_exit {
116 # Setup output 119 # Setup output
117 my $output = "$STATUS_TEXT{$code}"; 120 my $output = "$STATUS_TEXT{$code}";
118 $output .= " - $message" if defined $message && $message ne ''; 121 $output .= " - $message" if defined $message && $message ne '';
119 my $shortname = get_shortname(plugin => $arg->{plugin}); 122 my $shortname = ($arg->{plugin} ? $arg->{plugin}->shortname : undef);
123 $shortname ||= get_shortname(); # Should happen only if funnctions are called directly
120 $output = "$shortname $output" if $shortname; 124 $output = "$shortname $output" if $shortname;
121 if ($arg->{plugin}) { 125 if ($arg->{plugin}) {
122 my $plugin = $arg->{plugin}; 126 my $plugin = $arg->{plugin};