diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-03-10 01:54:06 -0500 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-03-12 08:09:11 -0500 |
commit | c128d293b015291c5e45637d9e3d5b1e1fb36c12 (patch) | |
tree | 4b406d48f9d21b59a2aa4600b6d52ac11b7da4fd /lib/Nagios/Plugin/Functions.pm | |
parent | 58a1764446e5a1a30db360ee7a69555d7f2e8f1a (diff) | |
download | monitoring-plugin-perl-c128d293b015291c5e45637d9e3d5b1e1fb36c12.tar.gz |
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.
Diffstat (limited to 'lib/Nagios/Plugin/Functions.pm')
-rw-r--r-- | lib/Nagios/Plugin/Functions.pm | 14 |
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; | |||
54 | sub _use_die { @_ ? $_use_die = shift : $_use_die }; | 54 | sub _use_die { @_ ? $_use_die = shift : $_use_die }; |
55 | 55 | ||
56 | sub get_shortname { | 56 | sub 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}; |