From f02cb4e0cce374d92e6c2702fe113a3b6c81e304 Mon Sep 17 00:00:00 2001 From: Paul Dugas Date: Sat, 2 Apr 2016 10:06:25 -0400 Subject: 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' ], -- cgit v1.2.3-74-g34f1