This commit is contained in:
garnier-quentin 2019-04-16 17:01:22 +02:00
parent d09f6d3fbc
commit a354a0e913
7 changed files with 106 additions and 65 deletions

View File

@ -20,9 +20,9 @@
package centreon::plugins::output;
use centreon::plugins::misc;
use strict;
use warnings;
use centreon::plugins::misc;
sub new {
my ($class, %options) = @_;
@ -48,6 +48,7 @@ sub new {
"opt-exit:s" => { name => 'opt_exit', default => 'unknown' },
"output-xml" => { name => 'output_xml' },
"output-json" => { name => 'output_json' },
"output-openmetrics" => { name => 'output_openmetrics' },
"output-file:s" => { name => 'output_file' },
"disco-format" => { name => 'disco_format' },
"disco-show" => { name => 'disco_show' },
@ -371,6 +372,34 @@ sub output_xml {
print $self->{xml_output}->toString(1);
}
sub output_openmetrics {
my ($self, %options) = @_;
$self->change_perfdata();
foreach my $perf (@{$self->{perfdatas}}) {
next if (defined($self->{option_results}->{filter_perfdata}) &&
$perf->{label} !~ /$self->{option_results}->{filter_perfdata}/);
$perf->{unit} = '' if (defined($self->{option_results}->{filter_uom}) &&
$perf->{unit} !~ /$self->{option_results}->{filter_uom}/);
$self->range_perfdata(ranges => [\$perf->{warning}, \$perf->{critical}]);
my $label = $perf->{label};
my $instance;
if ($label =~ /^(.*?)#(.*)$/) {
($perf->{instance}, $label) = ($1, $2);
}
my ($bucket, $append) = ('{plugin="' . $self->{plugin} . '",mode="' . $self->{mode} . '"', '');
foreach ('unit', 'warning', 'critical', 'min', 'max', 'instance') {
if (defined($perf->{$_}) && $perf->{$_} ne '') {
$bucket .= ',' . $_ . '="' . $perf->{$_} . '"';
}
}
$bucket .= '}';
print $label . $bucket . ' ' . $perf->{value};
}
print "\n";
}
sub output_txt_short_display {
my ($self, %options) = @_;
@ -478,11 +507,16 @@ sub display {
force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output);
return ;
}
} elsif (defined($self->{option_results}->{output_openmetrics})) {
$self->output_openmetrics();
return ;
}
$self->output_txt(exit_litteral => $self->get_litteral_status(),
$self->output_txt(
exit_litteral => $self->get_litteral_status(),
nolabel => $nolabel,
force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output);
force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output
);
}
sub die_exit {
@ -1288,11 +1322,15 @@ SSH connection refused, timeout, etc)
=item B<--output-xml>
Display output in XML Format.
Display output in XML format.
=item B<--output-json>
Display output in JSON Format.
Display output in JSON format.
=item B<--output-openmetrics>
Display metrics in OpenMetrics format.
=item B<--output-file>

View File

@ -107,7 +107,7 @@ sub get_plugin {
'runas:s' => { name => 'runas' },
'environment:s%' => { name => 'environment' },
'convert-args:s' => { name => 'convert_args' },
} );
});
$self->{options}->parse_options();
@ -120,7 +120,6 @@ sub get_plugin {
$self->{ignore_warn_msg} = $self->{options}->get_option(argument => 'ignore_warn_msg' );
$self->{convert_args} = $self->{options}->get_option(argument => 'convert_args' );
$self->{output}->mode(name => $self->{mode});
$self->{output}->plugin(name => $self->{plugin});
$self->{output}->check_options(option_results => $self->{options}->get_options());

View File

@ -62,6 +62,7 @@ sub new {
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
$self->{options}->add_help(package => __PACKAGE__, sections => 'GLOBAL OPTIONS');
$self->{output}->mode(name => $self->{mode_name});
return $self;
}

View File

@ -55,6 +55,7 @@ sub new {
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
$self->{options}->add_help(package => __PACKAGE__, sections => 'GLOBAL OPTIONS');
$self->{output}->mode(name => $self->{mode_name});
return $self;
}

View File

@ -58,6 +58,7 @@ sub new {
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
$self->{options}->add_help(package => __PACKAGE__, sections => 'GLOBAL OPTIONS');
$self->{output}->mode(name => $self->{mode_name});
return $self;
}
@ -87,7 +88,6 @@ sub init {
# SNMP
$self->{snmp} = centreon::plugins::snmp->new(options => $self->{options}, output => $self->{output});
# Load mode
if (defined($self->{mode_name}) && $self->{mode_name} ne '') {
$self->is_mode(mode => $self->{mode_name});

View File

@ -63,6 +63,7 @@ sub new {
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
$self->{options}->add_help(package => __PACKAGE__, sections => 'GLOBAL OPTIONS');
$self->{output}->mode(name => $self->{mode_name});
return $self;
}

View File

@ -57,6 +57,7 @@ sub new {
$self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION');
$self->{options}->add_help(package => __PACKAGE__, sections => 'GLOBAL OPTIONS');
$self->{output}->mode(name => $self->{mode_name});
return $self;
}