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(),
nolabel => $nolabel,
force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output);
$self->output_txt(
exit_litteral => $self->get_litteral_status(),
nolabel => $nolabel,
force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output
);
}
sub die_exit {
@ -531,7 +565,7 @@ sub option_exit {
$self->output_json(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1);
$self->exit(exit_litteral => $exit_litteral);
}
}
}
$self->output_txt(exit_litteral => $exit_litteral, nolabel => $nolabel, force_ignore_perfdata => 1, force_long_output => 1);
$self->exit(exit_litteral => $exit_litteral);
@ -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

@ -99,15 +99,15 @@ sub get_plugin {
$self->{options}->set_output(output => $self->{output});
$self->{options}->add_options(arguments => {
'plugin:s' => { name => 'plugin' },
'list-plugin' => { name => 'list_plugin' },
'help' => { name => 'help' },
'ignore-warn-msg' => { name => 'ignore_warn_msg' },
'version' => { name => 'version' },
'runas:s' => { name => 'runas' },
'environment:s%' => { name => 'environment' },
'convert-args:s' => { name => 'convert_args' },
} );
'plugin:s' => { name => 'plugin' },
'list-plugin' => { name => 'list_plugin' },
'help' => { name => 'help' },
'ignore-warn-msg' => { name => 'ignore_warn_msg' },
'version' => { name => 'version' },
'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

@ -35,16 +35,16 @@ sub new {
$self->{output} = $options{output};
$self->{options}->add_options(
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'custommode:s' => { name => 'custommode_name' },
'list-custommode' => { name => 'list_custommode' },
'multiple' => { name => 'multiple' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
}
);
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'custommode:s' => { name => 'custommode_name' },
'list-custommode' => { name => 'list_custommode' },
'multiple' => { name => 'multiple' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
}
);
$self->{version} = '1.0';
%{$self->{modes}} = ();
%{$self->{custom_modes}} = ();
@ -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

@ -34,14 +34,14 @@ sub new {
$self->{output} = $options{output};
$self->{options}->add_options(
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
}
);
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
}
);
$self->{version} = '1.0';
%{$self->{modes}} = ();
$self->{default} = undef;
@ -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

@ -36,15 +36,15 @@ sub new {
$self->{output} = $options{output};
$self->{options}->add_options(
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
'pass-manager:s' => { name => 'pass_manager' },
}
);
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
'pass-manager:s' => { name => 'pass_manager' },
}
);
$self->{version} = '1.0';
%{$self->{modes}} = ();
$self->{default} = undef;
@ -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

@ -35,17 +35,17 @@ sub new {
$self->{output} = $options{output};
$self->{options}->add_options(
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' },
'list-sqlmode' => { name => 'list_sqlmode' },
'multiple' => { name => 'multiple' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
}
);
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' },
'list-sqlmode' => { name => 'list_sqlmode' },
'multiple' => { name => 'multiple' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
}
);
$self->{version} = '1.0';
%{$self->{modes}} = ();
%{$self->{sql_modes}} = ('dbi' => 'centreon::plugins::dbi');
@ -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

@ -36,14 +36,14 @@ sub new {
$self->{output} = $options{output};
$self->{options}->add_options(
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
}
);
arguments => {
'mode:s' => { name => 'mode_name' },
'dyn-mode:s' => { name => 'dynmode_name' },
'list-mode' => { name => 'list_mode' },
'mode-version:s' => { name => 'mode_version' },
'sanity-options' => { name => 'sanity_options' }, # keep it for 6 month before remove it
}
);
$self->{version} = '1.0';
%{$self->{modes}} = ();
$self->{default} = undef;
@ -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;
}