diff options
author | Ton Voon <ton.voon@opsview.com> | 2021-02-02 18:21:22 +0000 |
---|---|---|
committer | Ton Voon <ton.voon@opsview.com> | 2021-02-02 18:21:22 +0000 |
commit | 7fe1e44fb792626c17f373d785d9ee0e49eb1eb6 (patch) | |
tree | 2734b29c26d5100ce5757a43e0ff4b1af5a46309 | |
parent | 3035ed03d86da7f36ba873e0027d7d3a30504256 (diff) | |
download | monitoring-plugin-perl-refs/heads/fix_munged_hyphen.tar.gz |
Fix an incorrect hyphen removal due to a double linefeedfix_munged_hyphen
-rw-r--r-- | lib/Monitoring/Plugin/Functions.pm | 2 | ||||
-rw-r--r-- | t/Monitoring-Plugin-Functions-01.t | 13 |
2 files changed, 7 insertions, 8 deletions
diff --git a/lib/Monitoring/Plugin/Functions.pm b/lib/Monitoring/Plugin/Functions.pm index 3eaf9e3..cc938e5 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 =~ /^\s*\n/mxs; | 122 | $output .= " - " unless $message =~ /^\s*[\n\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 3f1ab75..acce176 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 => 116; | 3 | use Test::More tests => 117; |
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); |
@@ -90,15 +90,14 @@ for (@ugly2) { | |||
90 | 90 | ||
91 | # plugin_exit message with longoutput | 91 | # plugin_exit message with longoutput |
92 | my @ugly3 = ( | 92 | my @ugly3 = ( |
93 | [ "MSG\nLONGOUTPUT", " - MSG\nLONGOUTPUT" ], | 93 | [ "MSG\nLONGOUTPUT", "MONITORING-PLUGIN-FUNCTIONS-01 CRITICAL - MSG\nLONGOUTPUT\n" ], |
94 | [ "\nLONGOUTPUT", "\nLONGOUTPUT" ], | 94 | [ "\nLONGOUTPUT", "MONITORING-PLUGIN-FUNCTIONS-01 CRITICAL\nLONGOUTPUT\n" ], |
95 | [ " \nLONGOUTPUT", " \nLONGOUTPUT" ], | 95 | [ " \nLONGOUTPUT", "MONITORING-PLUGIN-FUNCTIONS-01 CRITICAL \nLONGOUTPUT\n" ], |
96 | [ "LONGOUTPUT\n\n blah.", "MONITORING-PLUGIN-FUNCTIONS-01 CRITICAL - LONGOUTPUT\n\n blah.\n" ], | ||
96 | ); | 97 | ); |
97 | for (@ugly3) { | 98 | for (@ugly3) { |
98 | $r = plugin_exit(CRITICAL, $_->[0]); | 99 | $r = plugin_exit(CRITICAL, $_->[0]); |
99 | like($r->message, qr/CRITICAL$_->[1]$/, | 100 | is($r->message, $_->[1], "plugin_exit() output as expected"); |
100 | sprintf('plugin_exit(CRITICAL, $msg) output matched "%s"', | ||
101 | "CRITICAL$_->[1]")); | ||
102 | } | 101 | } |
103 | 102 | ||
104 | # Test plugin_die( $msg ) | 103 | # Test plugin_die( $msg ) |