WIP: centreon-vmware connector 3.0.0

This commit is contained in:
garnier-quentin 2019-02-01 14:10:34 +01:00
parent 22f96b2af1
commit 208e93d3fb
4 changed files with 373 additions and 152 deletions

View File

@ -20,10 +20,108 @@
package apps::vmware::connector::mode::cpuhost;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status ' . $self->{result_values}->{status};
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_state'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'host', type => 3, cb_prefix_output => 'prefix_host_output', cb_long_output => 'host_long_output', message_multiple => 'All hosts are ok',
group => [
{ name => 'global', type => 0, skipped_code => { -11 => 1 } },
{ name => 'global_cpu', cb_prefix_output => 'prefix_global_cpu_output', type => 0, skipped_code => { -11 => 1 } },
{ name => 'cpu', display_long => 0, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok', type => 1, skipped_code => { -11 => 1 } },
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'state' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
}
},
];
$self->{maps_counters}->{global_cpu} = [
{ label => 'total-cpu', set => {
key_values => [ { name => 'cpu_average' } ],
output_template => '%s %%',
perfdatas => [
{ label => 'cpu_total', value => 'cpu_average_absolute', template => '%s', unit => '%',
min => 0, max => 100, label_extra_instance => 1 },
],
}
},
{ label => 'total-cpu-mhz', set => {
key_values => [ { name => 'cpu_average_mhz' }, { name => 'cpu_average_mhz_max' } ],
output_template => '%s MHz',
perfdatas => [
{ label => 'cpu_total_MHz', value => 'cpu_average_mhz_absolute', template => '%s', unit => 'MHz',
min => 0, max => 'cpu_average_mhz_max_absolute', label_extra_instance => 1 },
],
}
},
];
$self->{maps_counters}->{cpu} = [
{ label => 'cpu', set => {
key_values => [ { name => 'cpu_usage' }, { name => 'display' } ],
output_template => 'usage : %s',
perfdatas => [
{ label => 'cpu', value => 'cpu_usage_absolute', template => '%s', unit => '%',
min => 0, max => 100, label_extra_instance => 1 },
],
}
},
];
}
sub prefix_host_output {
my ($self, %options) = @_;
return "Host '" . $options{instance_value}->{display} . "' : ";
}
sub host_long_output {
my ($self, %options) = @_;
return "checking host '" . $options{instance_value}->{display} . "'";
}
sub prefix_global_cpu_output {
my ($self, %options) = @_;
return "cpu total average : ";
}
sub prefix_cpu_output {
my ($self, %options) = @_;
return "cpu '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
@ -31,44 +129,51 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"esx-hostname:s" => { name => 'esx_hostname' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"scope-cluster:s" => { name => 'scope_cluster' },
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$options{options}->add_options(arguments => {
"esx-hostname:s" => { name => 'esx_hostname' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"scope-cluster:s" => { name => 'scope_cluster' },
"unknown-status:s" => { name => 'unknown_status', default => '%{status} !~ /^connected$/' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->SUPER::check_options(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
if ($self->{output}->is_litteral_status(status => $self->{option_results}->{disconnect_status}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong disconnect-status status option '" . $self->{option_results}->{disconnect_status} . "'.");
$self->{output}->option_exit();
}
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
}
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{connector}->add_params(params => $self->{option_results},
command => 'cpuhost');
$self->{connector}->run();
sub manage_selection {
my ($self, %options) = @_;
$self->{host} = {};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'cpuhost');
foreach my $host_id (keys %{$response->{data}}) {
my $host_name = $response->{data}->{$host_id}->{name};
$self->{host}->{$host_name} = { display => $host_name,
cpu => {},
global => {
state => $response->{data}->{$host_id}->{state},
},
global_cpu => {
cpu_average => $response->{data}->{$host_id}->{'cpu.usage.average'},
cpu_average_mhz => $response->{data}->{$host_id}->{'cpu.usagemhz.average'},
cpu_average_mhz_max => $response->{data}->{$host_id}->{numCpuCores} * $response->{data}->{$host_id}->{cpuMhz},
},
};
foreach my $cpu_id (sort keys %{$response->{data}->{$host_id}->{cpu}}) {
$self->{host}->{$host_name}->{cpu}->{$cpu_id} = { display => $cpu_id, cpu_usage => $response->{data}->{$host_id}->{cpu}->{$cpu_id} };
}
}
}
1;
@ -98,17 +203,30 @@ Search in following datacenter(s) (can be a regexp).
Search in following cluster(s) (can be a regexp).
=item B<--disconnect-status>
=item B<--unknown-status>
Status if ESX host disconnected (default: 'unknown').
Set warning threshold for status (Default: '%{status} !~ /^connected$/').
Can used special variables like: %{status}
=item B<--warning>
=item B<--warning-status>
Threshold warning in percent.
Set warning threshold for status (Default: '').
Can used special variables like: %{status}
=item B<--critical>
=item B<--critical-status>
Threshold critical in percent.
Set critical threshold for status (Default: '').
Can used special variables like: %{status}
=item B<--warning-*>
Threshold warning.
Can be: 'total-cpu', 'total-cpu-mhz', 'cpu'.
=item B<--critical-*>
Threshold critical.
Can be: 'total-cpu', 'total-cpu-mhz', 'cpu'.
=back

View File

@ -154,7 +154,7 @@ sub output_add {
separator => ' - ',
debug => 0,
short_msg => undef,
long_msg => undef
long_msg => undef,
);
my $options = {%args, %params};

View File

@ -144,72 +144,79 @@ sub run_global {
my ($self, %options) = @_;
return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1);
my $resume = defined($options{resume}) && $options{resume} == 1 ? 1 : 0;
# Can be set when it comes from type 3 counters
my $called_multiple = defined($options{called_multiple}) && $options{called_multiple} == 1 ? 1 : 0;
my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? 1 : 0;
my $force_instance = defined($options{force_instance}) ? $options{force_instance} : undef;
my $message_separator = defined($options{config}->{message_separator}) ? $options{config}->{message_separator} : ', ';
my $message_separator = defined($options{config}->{message_separator}) ?
$options{config}->{message_separator}: ', ';
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
my $multiple = 0;
foreach (@{$self->{maps_counters}->{$options{config}->{name}}}) {
my $obj = $_->{obj};
next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' &&
$_->{label} !~ /$self->{option_results}->{filter_counters}/);
my $value_check;
if (defined($options{instance}) && $options{instance} ne '') {
$obj->set(instance => $options{instance});
if (scalar(keys %{$self->{$options{counter_name}}}) > 1) {
$multiple = 1;
}
$value_check = $obj->execute(new_datas => $self->{new_datas}, values => $self->{$options{counter_name}}->{$options{instance}}->{$options{config}->{name}});
} else {
$obj->set(instance => $options{config}->{name});
$value_check = $obj->execute(new_datas => $self->{new_datas}, values => $self->{$options{config}->{name}});
}
$obj->set(instance => defined($force_instance) ? $force_instance : $options{config}->{name});
my ($value_check) = $obj->execute(new_datas => $self->{new_datas}, values => $self->{$options{config}->{name}});
next if (defined($options{config}->{skipped_code}) && defined($options{config}->{skipped_code}->{$value_check}));
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = $message_separator;
next;
}
my $exit = $obj->threshold_check();
push @exits, $exit;
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = $message_separator;
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = $message_separator;
}
$obj->perfdata(level => 1, extra_instance => $multiple);
$obj->perfdata(extra_instance => $multiple_parent);
}
my ($prefix_output, $suffix_output);
if (defined($options{config}->{cb_prefix_output})) {
if (defined($options{instance}) && $options{instance} ne '') {
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output},
instance_value => $self->{$options{counter_name}}->{$options{instance}});
} else {
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}) if (defined($options{config}->{cb_prefix_output}));
}
}
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output})
if (defined($options{config}->{cb_prefix_output}));
$prefix_output = '' if (!defined($prefix_output));
$suffix_output = $self->call_object_callback(method_name => $options{config}->{cb_suffix_output}) if (defined($options{config}->{cb_suffix_output}));
$suffix_output = $self->call_object_callback(method_name => $options{config}->{cb_suffix_output})
if (defined($options{config}->{cb_suffix_output}));
$suffix_output = '' if (!defined($suffix_output));
if ($called_multiple == 1) {
$self->{output}->output_add(long_msg => "${prefix_output}${long_msg}${suffix_output}");
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => $prefix_output . $short_msg . $suffix_output
);
if ($called_multiple == 0) {
$self->{output}->output_add(severity => $exit,
short_msg => "${prefix_output}${short_msg}${suffix_output}"
);
} else {
$self->run_multiple_prefix_output(severity => $exit,
short_msg => "${prefix_output}${short_msg}${suffix_output}");
}
} else {
$self->{output}->output_add(short_msg => $prefix_output . $long_msg . $suffix_output) if ($long_msg ne '' && $multiple == 0);
if ($long_msg ne '' && $multiple_parent == 0) {
if ($called_multiple == 0) {
$self->{output}->output_add(short_msg => "${prefix_output}${long_msg}${suffix_output}") ;
} else {
$self->run_multiple_prefix_output(severity => 'ok',
short_msg => "${prefix_output}${long_msg}${suffix_output}");
}
}
}
}
@ -217,89 +224,71 @@ sub run_instances {
my ($self, %options) = @_;
return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1);
my $message_separator = defined($options{config}->{message_separator}) ? $options{config}->{message_separator} : ', ';
my $display_status_long_output = defined($options{display_status_long_output}) && $options{display_status_long_output} == 1 ? 1 : 0;
my $display_status_lo = defined($options{display_status_long_output}) && $options{display_status_long_output} == 1 ? 1 : 0;
my $resume = defined($options{resume}) && $options{resume} == 1 ? 1 : 0;
$self->{problems} = 0;
my $level = 1;
my $multiple_lvl2 = 0;
my $instances = $self->{$options{config}->{name}};
my $no_message_multiple = 1;
if (defined($options{instance}) && $options{instance} ne '') {
$level = 2;
if (scalar(keys %{$self->{$options{counter_name}}->{$options{instance}}->{$options{config}->{name}}}) > 1) {
$multiple_lvl2 = 1;
}
$instances = $self->{$options{counter_name}}->{$options{instance}}->{$options{config}->{name}};
} else {
$self->{multiple_lvl1} = 0;
if (scalar(keys %{$self->{$options{config}->{name}}}) > 1) {
$self->{multiple_lvl1} = 1;
}
$self->{lproblems} = 0;
$self->{multiple} = 1;
if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) {
$self->{multiple} = 0;
}
foreach my $instance (sort keys %{$instances}) {
if ($self->{multiple} == 1 && $resume == 0) {
$self->{output}->output_add(severity => 'OK',
short_msg => $options{config}->{message_multiple});
}
my $message_separator = defined($options{config}->{message_separator}) ?
$options{config}->{message_separator}: ', ';
foreach my $id (sort keys %{$self->{$options{config}->{name}}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
my @exits = ();
foreach (@{$self->{maps_counters}->{$options{config}->{name}}}) {
my $obj = $_->{obj};
next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' &&
$_->{label} !~ /$self->{option_results}->{filter_counters}/);
$no_message_multiple = 0;
$obj->set(instance => $instance);
if (defined($options{instance}) && $options{instance} ne '') {
$obj->set(instance => $options{instance} . '_' . $instance);
}
my $value_check = $obj->execute(new_datas => $self->{new_datas}, values => $instances->{$instance});
$obj->set(instance => $id);
my ($value_check) = $obj->execute(new_datas => $self->{new_datas},
values => $self->{$options{config}->{name}}->{$id});
next if (defined($options{config}->{skipped_code}) && defined($options{config}->{skipped_code}->{$value_check}));
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = $message_separator;
next;
}
my $exit = $obj->threshold_check();
push @exits, $exit;
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = $message_separator;
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{problems}++;
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$self->{lproblems}++;
$short_msg .= $short_msg_append . $output;
$short_msg_append = $message_separator;
}
$obj->perfdata(level => $level, extra_instance => $self->{multiple_lvl1}, extra_instance_lvl2 => $multiple_lvl2);
$obj->perfdata(extra_instance => $self->{multiple});
}
my ($prefix_output, $suffix_output);
if (defined($options{config}->{cb_prefix_output})) {
if (defined($options{instance}) && $options{instance} ne '') {
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output},
instance_value => $self->{$options{counter_name}}->{$options{instance}}->{$options{config}->{name}}->{$instance});
} else {
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$instance}) if (defined($options{config}->{cb_prefix_output}));
}
}
$prefix_output = '' if (!defined($prefix_output));
$suffix_output = $self->call_object_callback(method_name => $options{config}->{cb_suffix_output}) if (defined($options{config}->{cb_suffix_output}));
$suffix_output = '' if (!defined($suffix_output));
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$id})
if (defined($options{config}->{cb_prefix_output}));
$prefix_output = '' if (!defined($prefix_output));
$suffix_output = $self->call_object_callback(method_name => $options{config}->{cb_suffix_output})
if (defined($options{config}->{cb_suffix_output}));
$suffix_output = '' if (!defined($suffix_output));
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
# in mode grouped, we don't display 'ok'
my $debug = 0;
$debug = 1 if ($display_status_long_output == 1 && $self->{output}->is_status(value => $exit, compare => 'OK', litteral => 1));
if (scalar @{$self->{maps_counters}->{$options{config}->{name}}} > 0 && $long_msg ne '') {
$self->{output}->output_add(long_msg => ($display_status_long_output == 1 ? lc($exit) . ': ' : '') . $prefix_output . $long_msg . $suffix_output, debug => $debug);
}
$debug = 1 if ($display_status_lo == 1 && $self->{output}->is_status(value => $exit, compare => 'OK', litteral => 1));
$self->{output}->output_add(long_msg => ($display_status_lo == 1 ? lc($exit) . ': ' : '') . "${prefix_output}${long_msg}${suffix_output}", debug => $debug);
if ($resume == 1) {
$self->{most_critical_instance} = $self->{output}->get_most_critical(status => [ $self->{most_critical_instance}, $exit ]);
next;
@ -307,26 +296,14 @@ sub run_instances {
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => $prefix_output . $short_msg . $suffix_output
short_msg => "${prefix_output}${short_msg}${suffix_output}"
);
}
$self->{output}->output_add(short_msg => $prefix_output . $long_msg . $suffix_output) unless ($self->{multiple_lvl1} == 1 || ($multiple_lvl2 == 1 && !defined($options{multi})) || $long_msg eq '');
if ($options{multi}) {
foreach my $counter (@{$options{config}->{counters}}) {
if ($counter->{type} == 0) {
$self->run_global(config => $counter, counter_name => $options{config}->{name}, instance => $instance);
} elsif ($counter->{type} == 1) {
$self->run_instances(config => $counter, counter_name => $options{config}->{name}, instance => $instance);
}
}
if ($self->{multiple} == 0) {
$self->{output}->output_add(short_msg => "${prefix_output}${long_msg}${suffix_output}");
}
}
if ($no_message_multiple == 0 && ($self->{multiple_lvl1} > 0 && $resume == 0 && !defined($options{instance})) || ($self->{multiple_lvl1} == 0 && $multiple_lvl2 > 0)) {
$self->{output}->output_add(short_msg => $options{config}->{message_multiple});
}
}
sub run_group {
@ -343,30 +320,30 @@ sub run_group {
}
my ($global_exit, $total_problems) = ([], 0);
foreach my $instance (sort keys %{$self->{$options{config}->{name}}}) {
foreach my $id (sort keys %{$self->{$options{config}->{name}}}) {
$self->{most_critical_instance} = 'ok';
if (defined($options{config}->{cb_long_output})) {
$self->{output}->output_add(long_msg => $self->call_object_callback(method_name => $options{config}->{cb_long_output},
instance_value => $self->{$options{config}->{name}}->{$instance}));
instance_value => $self->{$options{config}->{name}}->{$id}));
}
foreach my $group (@{$options{config}->{group}}) {
$self->{$group->{name}} = $self->{$options{config}->{name}}->{$instance}->{$group->{name}};
$self->{$group->{name}} = $self->{$options{config}->{name}}->{$id}->{$group->{name}};
# we resume datas
$self->run_instances(config => $group, display_status_long_output => 1, resume => 1);
push @{$global_exit}, $self->{most_critical_instance};
$total_problems += $self->{problems};
$total_problems += $self->{lproblems};
my $prefix_output;
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$instance})
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$id})
if (defined($options{config}->{cb_prefix_output}));
$prefix_output = '' if (!defined($prefix_output));
if ($multiple == 0 && (!defined($group->{display}) || $group->{display} != 0)) {
$self->{output}->output_add(severity => $self->{most_critical_instance},
short_msg => $prefix_output . $self->{problems} . " problem(s) detected");
short_msg => "${prefix_output}$self->{lproblems} problem(s) detected");
}
}
}
@ -386,6 +363,137 @@ sub run_group {
}
}
sub run_multiple_instances {
my ($self, %options) = @_;
return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1);
my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? $options{multiple_parent} : 0;
$self->{multiple} = 1;
if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) {
$self->{multiple} = 0;
}
if ($self->{multiple} == 1 && $multiple_parent == 0) {
$self->{output}->output_add(short_msg => $options{config}->{message_multiple});
}
my $message_separator = defined($options{config}->{message_separator}) ?
$options{config}->{message_separator}: ', ';
foreach my $id (sort keys %{$self->{$options{config}->{name}}}) {
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits = ();
foreach (@{$self->{maps_counters}->{$options{config}->{name}}}) {
my $obj = $_->{obj};
next if (defined($self->{option_results}->{filter_counters}) && $self->{option_results}->{filter_counters} ne '' &&
$_->{label} !~ /$self->{option_results}->{filter_counters}/);
my $instance = $id;
if ($multiple_parent == 1) {
$instance = $options{instance_parent} . "_" . $id;
}
$obj->set(instance => $instance);
my ($value_check) = $obj->execute(new_datas => $self->{new_datas},
values => $self->{$options{config}->{name}}->{$id});
next if (defined($options{config}->{skipped_code}) && defined($options{config}->{skipped_code}->{$value_check}));
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = $message_separator;
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = $message_separator;
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = $message_separator;
}
$obj->perfdata(extra_instance => $self->{multiple});
}
my ($prefix_output, $suffix_output);
$prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$id})
if (defined($options{config}->{cb_prefix_output}));
$prefix_output = '' if (!defined($prefix_output));
$suffix_output = $self->call_object_callback(method_name => $options{config}->{cb_suffix_output})
if (defined($options{config}->{cb_suffix_output}));
$suffix_output = '' if (!defined($suffix_output));
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
$self->{output}->output_add(long_msg => "${prefix_output}${long_msg}${suffix_output}")
if (!defined($options{config}->{display_long}) || $options{config}->{display_long} != 0);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->run_multiple_prefix_output(severity => $exit,
short_msg => "${prefix_output}${short_msg}${suffix_output}"
);
}
if ($self->{multiple} == 0) {
$self->run_multiple_prefix_output(severity => 'ok', short_msg => "${prefix_output}${long_msg}${suffix_output}");
}
}
}
sub run_multiple_prefix_output {
my ($self, %options) = @_;
my %separator;
if ($self->{prefix_multiple_output_done}->{lc($options{severity})} == 0) {
$self->{output}->output_add(severity => $options{severity}, short_msg => $self->{prefix_multiple_output});
$self->{prefix_multiple_output_done}->{lc($options{severity})} = 1;
$separator{separator} = '';
}
$self->{output}->output_add(severity => $options{severity}, short_msg => "$options{short_msg}", %separator);
}
sub run_multiple {
my ($self, %options) = @_;
my $multiple = 1;
if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) {
$multiple = 0;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => $options{config}->{message_multiple});
}
foreach my $instance (sort keys %{$self->{$options{config}->{name}}}) {
if (defined($options{config}->{cb_long_output})) {
$self->{output}->output_add(long_msg => $self->call_object_callback(method_name => $options{config}->{cb_long_output},
instance_value => $self->{$options{config}->{name}}->{$instance}));
}
$self->{prefix_multiple_output} = '';
$self->{prefix_multiple_output_done} = { ok => 0, warning => 0, critical => 0, unknown => 0 };
if ($multiple == 0) {
$self->{prefix_multiple_output} = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$instance})
if (defined($options{config}->{cb_prefix_output}));
}
foreach my $group (@{$options{config}->{group}}) {
$self->{$group->{name}} = $self->{$options{config}->{name}}->{$instance}->{$group->{name}};
if ($group->{type} == 1) {
$self->run_multiple_instances(config => $group, multiple_parent => $multiple, instance_parent => $instance);
} elsif ($group->{type} == 0) {
$self->run_global(config => $group, multiple_parent => $multiple, called_multiple => 1, force_instance => $instance);
}
}
}
}
sub run {
my ($self, %options) = @_;
@ -406,7 +514,7 @@ sub run {
} elsif ($entry->{type} == 2) {
$self->run_group(config => $entry);
} elsif ($entry->{type} == 3) {
$self->run_instances(config => $entry, multi => 1);
$self->run_multiple(config => $entry);
}
}

View File

@ -186,15 +186,10 @@ sub perfdata {
if (defined($perf->{threshold_total})) {
$th_total = ($perf->{threshold_total} =~ /[^0-9]/) ? $self->{result_values}->{$perf->{threshold_total}} : $perf->{threshold_total};
}
if (defined($perf->{label_multi_instances}) && $perf->{label_multi_instances} == 1 && (defined($options{level}) && $options{level} == 2 && defined($options{extra_instance}) && $options{extra_instance} == 1)) {
if (defined($perf->{multi_use})) {
$extra_label .= '_' . $self->{result_values}->{$perf->{multi_use}};
}
}
if (defined($perf->{label_extra_instance}) && $perf->{label_extra_instance} == 1 && (defined($options{level}) && $options{level} == 1 && defined($options{extra_instance}) && $options{extra_instance} == 1) ||
(defined($options{level}) && $options{level} == 2 && defined($options{extra_instance_lvl2}) && $options{extra_instance_lvl2} == 1)) {
if (defined($perf->{label_extra_instance}) && $perf->{label_extra_instance} == 1 &&
(!defined($options{extra_instance}) || $options{extra_instance} != 0)) {
if (defined($perf->{instance_use})) {
$extra_label .= '_' . $self->{result_values}->{$perf->{instance_use}};
} else {