From e0cf866970087e91d8bd00ad9465eb21e46ca204 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 7 Feb 2019 14:50:17 +0100 Subject: [PATCH] add change output short format --- centreon-plugins/centreon/plugins/output.pm | 53 +++++++++++++++++---- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/centreon-plugins/centreon/plugins/output.pm b/centreon-plugins/centreon/plugins/output.pm index 509e3b597..624b52e4b 100644 --- a/centreon-plugins/centreon/plugins/output.pm +++ b/centreon-plugins/centreon/plugins/output.pm @@ -40,6 +40,7 @@ sub new { "filter-perfdata:s" => { name => 'filter_perfdata' }, "change-perfdata:s@" => { name => 'change_perfdata' }, "extend-perfdata:s@" => { name => 'extend_perfdata' }, + "change-short-output:s@" => { name => 'change_short_output' }, "filter-uom:s" => { name => 'filter_uom' }, "verbose" => { name => 'verbose' }, "debug" => { name => 'debug' }, @@ -350,15 +351,9 @@ sub output_xml { print $self->{xml_output}->toString(1); } -sub output_txt { +sub output_txt_short_display { my ($self, %options) = @_; - my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; - my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; - - if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) { - $self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET}); - } - + if (defined($self->{global_short_concat_outputs}->{CRITICAL})) { print (($options{nolabel} == 0 ? 'CRITICAL: ' : '') . $self->{global_short_concat_outputs}->{CRITICAL} . " "); } @@ -371,6 +366,44 @@ sub output_txt { if (uc($options{exit_litteral}) eq 'OK') { print (($options{nolabel} == 0 ? 'OK: ' : '') . (defined($self->{global_short_concat_outputs}->{OK}) ? $self->{global_short_concat_outputs}->{OK} : '') . " "); } +} + +sub output_txt_short { + my ($self, %options) = @_; + + if (!defined($self->{option_results}->{change_short_output})) { + $self->output_txt_short_display(%options); + return ; + } + + my $stdout = ''; + { + local *STDOUT; + open STDOUT, '>', \$stdout; + $self->output_txt_short_display(%options); + } + + foreach (@{$self->{option_results}->{change_short_output}}) { + my ($pattern, $replace, $modifier) = split /~/; + next if (!defined($pattern)); + $replace = '' if (!defined($replace)); + $modifier = '' if (!defined($modifier)); + eval "\$stdout =~ s{$pattern}{$replace}$modifier"; + } + + print $stdout; +} + +sub output_txt { + my ($self, %options) = @_; + my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; + my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; + + if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) { + $self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET}); + } + + $self->output_txt_short(%options); if ($force_ignore_perfdata == 1) { print "\n"; @@ -1049,6 +1082,10 @@ Change traffic values in percent: --change-perfdata=traffic_in,,percent() =back +=item B<--change-short-output> + +Change short output display. --change-short-output=pattern~replace~modifier + =item B<--range-perfdata> Change perfdata range thresholds display: