[monitoring-plugin-perl] Fixed regex in plugin_exit() that handles hyphen ...
Paul Dugas
git at monitoring-plugins.org
Sat Apr 2 17:50:05 CEST 2016
Module: monitoring-plugin-perl
Branch: master
Commit: f02cb4e0cce374d92e6c2702fe113a3b6c81e304
Author: Paul Dugas <paul at dugas.cc>
Date: Sat Apr 2 10:06:25 2016 -0400
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugin-perl/commit/?id=f02cb4e
Fixed regex in plugin_exit() that handles hyphen for LONGOUTPUT.
Added tests.
---
lib/Monitoring/Plugin/Functions.pm | 2 +-
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 {
# Setup output
my $output = "$STATUS_TEXT{$code}";
if (defined $message && $message ne '') {
- $output .= " - " unless $message =~ /^[ \f\r\t\w]*\n/;
+ $output .= " - " unless $message =~ /^\h*\R/;
$output .= $message;
}
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 @@
use strict;
-use Test::More tests => 113;
+use Test::More tests => 116;
BEGIN { use_ok("Monitoring::Plugin::Functions", ":all"); }
Monitoring::Plugin::Functions::_fake_exit(1);
@@ -88,6 +88,19 @@ for (@ugly2) {
$display1, "CRITICAL.*$display2"));
}
+# plugin_exit message with longoutput
+my @ugly3 = (
+ [ "MSG\nLONGOUTPUT", " - MSG\nLONGOUTPUT" ],
+ [ "\nLONGOUTPUT", "\nLONGOUTPUT" ],
+ [ " \nLONGOUTPUT", " \nLONGOUTPUT" ],
+);
+for (@ugly3) {
+ $r = plugin_exit(CRITICAL, $_->[0]);
+ like($r->message, qr/CRITICAL$_->[1]$/,
+ sprintf('plugin_exit(CRITICAL, $msg) output matched "%s"',
+ "CRITICAL$_->[1]"));
+}
+
# Test plugin_die( $msg )
my @msg = (
[ 'die you dog' ],
More information about the Commits
mailing list