From c03cf36354eb7bee62442549d9ce8bc549da99a0 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 8 Jul 2019 10:48:26 +0200 Subject: [PATCH] add output class method + openmetrics timestamp --- .../centreon/plugins/alternative/Getopt.pm | 2 +- centreon-plugins/centreon/plugins/output.pm | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/centreon-plugins/centreon/plugins/alternative/Getopt.pm b/centreon-plugins/centreon/plugins/alternative/Getopt.pm index 3253010ea..f31603bf5 100644 --- a/centreon-plugins/centreon/plugins/alternative/Getopt.pm +++ b/centreon-plugins/centreon/plugins/alternative/Getopt.pm @@ -55,7 +55,7 @@ sub get_assigned_value { sub GetOptions { my (%opts) = @_; - + my $search_str = ',' . join(',', keys %opts) . ','; my $num_args = scalar(@ARGV); for (my $i = 0; $i < $num_args;) { diff --git a/centreon-plugins/centreon/plugins/output.pm b/centreon-plugins/centreon/plugins/output.pm index 2795d08da..a71f122c8 100644 --- a/centreon-plugins/centreon/plugins/output.pm +++ b/centreon-plugins/centreon/plugins/output.pm @@ -58,6 +58,9 @@ sub new { %{$self->{option_results}} = (); $self->{option_msg} = []; + + $self->{nodisplay} = 0; + $self->{noexit_die} = 0; $self->{is_output_xml} = 0; $self->{is_output_json} = 0; @@ -376,6 +379,12 @@ sub output_xml { sub output_openmetrics { my ($self, %options) = @_; + centreon::plugins::misc::mymodule_load( + output => $self->{output}, module => 'Time::HiRes', + error_msg => "Cannot load module 'Time::HiRes'." + ); + + my $time_ms = int(Time::HiRes::time() * 1000); $self->change_perfdata(); foreach my $perf (@{$self->{perfdatas}}) { next if (defined($self->{option_results}->{filter_perfdata}) && @@ -396,7 +405,7 @@ sub output_openmetrics { } $bucket .= '}'; - print $label . $bucket . ' ' . $perf->{value} . "\n"; + print $label . $bucket . ' ' . $perf->{value} . ' ' . $time_ms . "\n"; } } @@ -448,6 +457,7 @@ sub output_txt { 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; + return if ($self->{nodisplay} == 1); 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}); } @@ -573,8 +583,10 @@ sub option_exit { sub exit { my ($self, %options) = @_; - # $options{exit_litteral} = exit + if ($self->{noexit_die} == 1) { + die 'exit'; + } if (defined($options{exit_litteral})) { exit $self->{errors}->{uc($options{exit_litteral})}; } @@ -770,6 +782,15 @@ sub to_utf8 { return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, $self->{perlqq})); } +sub parameter { + my ($self, %options) = @_; + + if (defined($options{attr})) { + $self->{$options{attr}} = $options{value}; + } + return $self->{$options{attr}}; +} + sub add_disco_entry { my ($self, %options) = @_;