diff options
author | Paul Dugas <paul@dugas.cc> | 2016-04-02 10:06:25 -0400 |
---|---|---|
committer | Paul Dugas <paul@dugas.cc> | 2016-04-02 10:06:25 -0400 |
commit | f02cb4e0cce374d92e6c2702fe113a3b6c81e304 (patch) | |
tree | 741c716b3ec1eb452fd1a6a1527abe4ff7081355 | |
parent | 471fef88ab046a055df95f607704557e07d56874 (diff) | |
download | monitoring-plugin-perl-f02cb4e0cce374d92e6c2702fe113a3b6c81e304.tar.gz |
Fixed regex in plugin_exit() that handles hyphen for LONGOUTPUT.
Added tests.
-rw-r--r-- | lib/Monitoring/Plugin/Functions.pm | 2 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Functions-01.t | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/Monitoring/Plugin/Functions.pm b/lib/Monitoring/Plugin/Functions.pm index a19db49..5946c7d 100644 --- a/lib/Monitoring/Plugin/Functions.pm +++ b/lib/Monitoring/Plugin/Functions.pm | |||
@@ -119,7 +119,7 @@ sub plugin_exit { | |||
119 | # Setup output | 119 | # Setup output |
120 | my $output = "$STATUS_TEXT{$code}"; | 120 | my $output = "$STATUS_TEXT{$code}"; |
121 | if (defined $message && $message ne '') { | 121 | if (defined $message && $message ne '') { |
122 | $output .= " - " unless $message =~ /^[ \f\r\t\w]*\n/; | 122 | $output .= " - " unless $message =~ /^\h*\R/; |
123 | $output .= $message; | 123 | $output .= $message; |
124 | } | 124 | } |
125 | my $shortname = ($arg->{plugin} ? $arg->{plugin}->shortname : undef); | 125 | my $shortname = ($arg->{plugin} ? $arg->{plugin}->shortname : undef); |
diff --git a/t/Monitoring-Plugin-Functions-01.t b/t/Monitoring-Plugin-Functions-01.t index 084ad28..3f1ab75 100644 --- a/t/Monitoring-Plugin-Functions-01.t +++ b/t/Monitoring-Plugin-Functions-01.t | |||
@@ -1,6 +1,6 @@ | |||
1 | 1 | ||
2 | use strict; | 2 | use strict; |
3 | use Test::More tests => 113; | 3 | use Test::More tests => 116; |
4 | 4 | ||
5 | BEGIN { use_ok("Monitoring::Plugin::Functions", ":all"); } | 5 | BEGIN { use_ok("Monitoring::Plugin::Functions", ":all"); } |
6 | Monitoring::Plugin::Functions::_fake_exit(1); | 6 | Monitoring::Plugin::Functions::_fake_exit(1); |
@@ -88,6 +88,19 @@ for (@ugly2) { | |||
88 | $display1, "CRITICAL.*$display2")); | 88 | $display1, "CRITICAL.*$display2")); |
89 | } | 89 | } |
90 | 90 | ||
91 | # plugin_exit message with longoutput | ||
92 | my @ugly3 = ( | ||
93 | [ "MSG\nLONGOUTPUT", " - MSG\nLONGOUTPUT" ], | ||
94 | [ "\nLONGOUTPUT", "\nLONGOUTPUT" ], | ||
95 | [ " \nLONGOUTPUT", " \nLONGOUTPUT" ], | ||
96 | ); | ||
97 | for (@ugly3) { | ||
98 | $r = plugin_exit(CRITICAL, $_->[0]); | ||
99 | like($r->message, qr/CRITICAL$_->[1]$/, | ||
100 | sprintf('plugin_exit(CRITICAL, $msg) output matched "%s"', | ||
101 | "CRITICAL$_->[1]")); | ||
102 | } | ||
103 | |||
91 | # Test plugin_die( $msg ) | 104 | # Test plugin_die( $msg ) |
92 | my @msg = ( | 105 | my @msg = ( |
93 | [ 'die you dog' ], | 106 | [ 'die you dog' ], |