Fix #1435
This commit is contained in:
parent
d09f6d3fbc
commit
a354a0e913
|
@ -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>
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue