WIP on compat with connector vmware 3.0.0

This commit is contained in:
garnier-quentin 2019-01-31 17:24:40 +01:00
parent 6e7b80df44
commit d7bc059ad8
8 changed files with 627 additions and 94 deletions

View File

@ -57,6 +57,9 @@ sub new {
"timeout:s@" => { name => 'timeout' },
"sampling-period:s@" => { name => 'sampling_period' },
"time-shift:s@" => { name => 'time_shift' },
"unknown-connector-status:s" => { name => 'unknown_connector_status' },
"warning-connector-status:s" => { name => 'warning_connector_status' },
"critical-connector-status:s" => { name => 'critical_connector_status' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'CONNECTOR OPTIONS', once => 1);
@ -65,6 +68,7 @@ sub new {
$self->{mode} = $options{mode};
$self->{json_send} = {};
$self->{result} = undef;
return $self;
}
@ -109,6 +113,9 @@ sub check_options {
$self->{vsphere_password} = (defined($self->{option_results}->{vsphere_password})) ? shift(@{$self->{option_results}->{vsphere_password}}) : undef;
$self->{sampling_period} = (defined($self->{option_results}->{sampling_period})) ? shift(@{$self->{option_results}->{sampling_period}}) : undef;
$self->{time_shift} = (defined($self->{option_results}->{sampling_period})) ? shift(@{$self->{option_results}->{time_shift}}) : 0;
$self->{unknown_connector_status} = (defined($self->{option_results}->{unknown_connector_status})) ? $self->{option_results}->{unknown_connector_status} : '%{code} < 0 || (%{code} > 0 && %{code} < 200)';
$self->{warning_connector_status} = (defined($self->{option_results}->{warning_connector_status})) ? $self->{option_results}->{warning_connector_status} : '';
$self->{critical_connector_status} = (defined($self->{option_results}->{critical_connector_status})) ? $self->{option_results}->{critical_connector_status} : '';
$self->{connector_port} = 5700 if ($self->{connector_port} eq '');
$self->{container} = 'default' if ($self->{container} eq '');
@ -130,12 +137,6 @@ sub check_options {
return 1;
}
sub set_discovery {
my ($self, %options) = @_;
$self->{discovery} = 1;
}
sub add_params {
my ($self, %options) = @_;
@ -159,38 +160,75 @@ sub connector_response {
$self->{output}->option_exit();
}
my $json = $1;
my $result;
my $json = $1;
eval {
$result = JSON->new->utf8->decode($json);
$self->{result} = JSON->new->utf8->decode($json);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json result: $@");
$self->{output}->option_exit();
}
}
sub connector_response_status {
my ($self, %options) = @_;
foreach my $output (@{$result->{plugin}->{outputs}}) {
if ($output->{type} == 1) {
$self->{output}->output_add(severity => $output->{exit},
short_msg => $output->{msg});
} elsif ($output->{type} == 2) {
$self->{output}->output_add(long_msg => $output->{msg});
}
if (!defined($self->{result})) {
$self->{output}->add_option_msg(short_msg => "Cannot get response (timeout received)");
$self->{output}->option_exit();
}
if (!defined($self->{result}->{code})) {
$self->{output}->add_option_msg(short_msg => "response format incorrect");
$self->{output}->option_exit();
}
foreach my $perf (@{$result->{plugin}->{perfdatas}}) {
$self->{output}->perfdata_add(label => $perf->{label}, unit => $perf->{unit},
value => $perf->{value},
warning => $perf->{warning},
critical => $perf->{critical},
min => $perf->{min}, max => $perf->{max});
foreach (('unknown_connector_status', 'warning_connector_status', 'critical_connector_status')) {
$self->{$_} =~ s/%\{(.*?)\}/\$self->{result}->{$1}/g;
}
# Check response
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($self->{critical_connector_status}) && $self->{critical_connector_status} ne '' &&
eval "$self->{critical_connector_status}") {
$status = 'critical';
} elsif (defined($self->{warning_connector_status}) && $self->{warning_connector_status} ne '' &&
eval "$self->{warning_connector_status}") {
$status = 'warning';
} elsif (defined($self->{unknown_connector_status}) && $self->{unknown_connector_status} ne '' &&
eval "$self->{unknown_connector_status}") {
$status = 'unknown';
}
};
if (defined($message)) {
$self->{output}->add_option_msg(short_msg => 'filter connector status issue: ' . $message);
$self->{output}->option_exit();
}
if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(long_msg => $self->{result}->{extra_message}, debug => 1);
$self->{output}->output_add(severity => $status,
short_msg => $self->{result}->{short_message});
$self->{output}->display();
$self->{output}->exit();
}
}
sub run {
sub get_id {
my ($self, %options) = @_;
return $self->{connector_hostname} . '.' . $self->{connector_port} . '.' . $self->{container};
}
sub execute {
my ($self, %options) = @_;
$self->add_params(%options);
# Build request
my $uuid;
UUID::generate($uuid);
@ -227,16 +265,6 @@ sub run {
my $response = zmq_recvmsg($self->{requester});
zmq_close($self->{requester});
$self->connector_response(response => $response);
# We need to remove xml output
if (defined($self->{output}->{option_results}->{output_xml})) {
delete $self->{output}->{option_results}->{output_xml};
}
if (!defined($self->{discovery})) {
$self->{output}->display();
} else {
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
}
$self->{output}->exit();
},
},
);
@ -244,10 +272,9 @@ sub run {
zmq_poll(\@poll, $self->{timeout} * 1000);
zmq_close($self->{requester});
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => sprintf("Cannot get response (timeout received)"));
$self->{output}->display();
$self->{output}->exit();
$self->connector_response_status();
return $self->{result};
}
1;
@ -303,6 +330,21 @@ Should be not different than 300 or 20.
Can shift the time. We the following option you can average X counters values (default: 0).
=item B<--unknown-connector-status>
Set unknown threshold for connector status (Default: '%{code} < 0 || (%{code} > 0 && %{code} < 200)').
Can used special variables like: %{code}, %{short_message}, %{extra_message}.
=item B<--warning-connector-status>
Set warning threshold for connector status (Default: '').
Can used special variables like: %{code}, %{short_message}, %{extra_message}.
=item B<--critical-connector-status>
Set critical threshold for connector status (Default: '').
Can used special variables like: %{code}, %{short_message}, %{extra_message}.
=back
=head1 DESCRIPTION

View File

@ -20,10 +20,171 @@
package apps::vmware::connector::mode::alarmdatacenter;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::statefile;
sub catalog_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
my $label = $self->{label};
$label =~ s/-/_/g;
if (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' &&
eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") {
$self->{instance_mode}->{dc_critical}++;
$status = 'critical';
} elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' &&
eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") {
$self->{instance_mode}->{dc_warning}++;
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("alarm [%s] [%s] [%s] [%s] %s/%s",
$self->{result_values}->{status},
$self->{result_values}->{type},
$self->{result_values}->{entity_name},
$self->{result_values}->{time},
$self->{result_values}->{name},
$self->{result_values}->{description}
);
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{entity_name} = $options{new_datas}->{$self->{instance} . '_entity_name'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
$self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'};
$self->{result_values}->{description} = $options{new_datas}->{$self->{instance} . '_description'};
$self->{result_values}->{time} = $options{new_datas}->{$self->{instance} . '_time'};
return 0;
}
sub custom_dcmetrics_perfdata {
my ($self, %options) = @_;
my $extra_label = '';
# We do it manually. Because we have only 1 instance in group.
if (scalar(keys %{$self->{instance_mode}->{datacenter}}) > 1) {
$extra_label .= '_' . $self->{result_values}->{name};
}
$self->{output}->perfdata_add(label => 'alarm_' . $self->{result_values}->{label_ref} . $extra_label,
value => $self->{result_values}->{alarm_value},
min => 0);
}
sub custom_dcmetrics_calc {
my ($self, %options) = @_;
$self->{result_values}->{label_ref} = $options{extra_options}->{label_ref};
$self->{result_values}->{alarm_value} = $self->{instance_mode}->{'dc_' . $options{extra_options}->{label_ref}};
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'datacenter', type => 2, cb_prefix_output => 'prefix_datacenter_output', cb_long_output => 'datacenter_long_output', message_multiple => 'All datacenters are ok',
group => [
{ name => 'alarm', cb_init => 'alarm_reset', skipped_code => { -11 => 1 } },
{ name => 'dc_metrics', display => 0, skipped_code => { -11 => 1 } },
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'total-alarm-warning', set => {
key_values => [ { name => 'yellow' } ],
output_template => '%s warning alarm(s) found(s)',
perfdatas => [
{ label => 'total_alarm_warning', value => 'yellow_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'total-alarm-critical', set => {
key_values => [ { name => 'red' } ],
output_template => '%s critical alarm(s) found(s)',
perfdatas => [
{ label => 'total_alarm_critical', value => 'red_absolute', template => '%s', min => 0 },
],
}
},
];
$self->{maps_counters}->{alarm} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'entity_name' }, { name => 'status' },
{ name => 'time' }, { name => 'description' }, { name => 'name' }, { name => 'type' }, { name => 'since' } ],
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}->{dc_metrics} = [
{ label => 'alarm-warning', threshold => 0, set => {
key_values => [ { name => 'name' } ],
output_template => '',
closure_custom_calc => $self->can('custom_dcmetrics_calc'), closure_custom_calc_extra_options => { label_ref => 'warning' },
closure_custom_perfdata => $self->can('custom_dcmetrics_perfdata'),
}
},
{ label => 'alarm-critical', threshold => 0, set => {
key_values => [ { name => 'name' } ],
output_template => '',
closure_custom_calc => $self->can('custom_dcmetrics_calc'), closure_custom_calc_extra_options => { label_ref => 'critical' },
closure_custom_perfdata => $self->can('custom_dcmetrics_perfdata'),
}
},
];
}
sub prefix_datacenter_output {
my ($self, %options) = @_;
return "Datacenter '" . $options{instance_value}->{display} . "' ";
}
sub alarm_reset {
my ($self, %options) = @_;
$self->{dc_warning} = 0;
$self->{dc_critical} = 0;
}
sub datacenter_long_output {
my ($self, %options) = @_;
return "checking datacenter '" . $options{instance_value}->{display} . "'";
}
sub new {
my ($class, %options) = @_;
@ -37,22 +198,70 @@ sub new {
"filter" => { name => 'filter' },
"filter-time:s" => { name => 'filter_time', },
"memory" => { name => 'memory', },
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' },
});
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse',
error_msg => "Cannot load module 'Date::Parse'.");
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->check_options(%options);
}
}
sub run {
sub manage_selection {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{connector}->add_params(params => $self->{option_results},
command => 'alarmdatacenter');
$self->{connector}->run();
$self->{global} = { yellow => 0, red => 0 };
$self->{datacenter} = {};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'alarmdatacenter');
my $last_time;
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->read(statefile => "cache_vmware_" . $options{custom}->get_id() . '_' . $self->{mode});
$last_time = $self->{statefile_cache}->get(name => 'last_time');
}
my ($i, $current_time) = (1, time());
foreach my $datacenter_id (keys %{$response->{data}}) {
my $datacenter_name = $response->{data}->{$datacenter_id}->{name};
$self->{datacenter}->{$datacenter_name} = { display => $datacenter_name, alarm => {}, dc_metrics => { 1 => { name => $datacenter_name } } };
foreach (keys %{$response->{data}->{$datacenter_id}->{alarms}}) {
my $create_time = Date::Parse::str2time($response->{data}->{$datacenter_id}->{alarms}->{$_}->{time});
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't Parse date '" . $response->{data}->{$datacenter_id}->{alarms}->{$_}->{time} . "'");
next;
}
next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $create_time);
my $diff_time = $current_time - $create_time;
if (defined($self->{option_results}->{filter_time}) && $self->{option_results}->{filter_time} ne '') {
next if ($diff_time > $self->{option_results}->{filter_time});
}
$self->{datacenter}->{$datacenter_name}->{alarm}->{$i} = { %{$response->{data}->{$datacenter_id}->{alarms}->{$_}}, since => $diff_time };
$self->{global}->{$response->{data}->{$datacenter_id}->{alarms}->{$_}->{status}}++;
$i++;
}
}
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->write(data => { last_time => $current_time });
}
}
1;
@ -82,6 +291,26 @@ Don't check alarm older (value in seconds).
Check new alarms only.
=item B<--warning-status>
Set warning threshold for status (Default: '%{status} =~ /yellow/i).
Can used special variables like: %{status}, %{name}, %{entity}, %{type}.
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /red/i').
Can used special variables like: %{status}, %{name}, %{entity}, %{type}.
=item B<--warning-*>
Threshold warning.
Can be: 'total-alarm-warning', 'total-alarm-critical'.
=item B<--critical-*>
Threshold critical.
Can be: 'total-alarm-warning', 'total-alarm-critical'.
=back
=cut

View File

@ -20,10 +20,171 @@
package apps::vmware::connector::mode::alarmhost;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::statefile;
sub catalog_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
my $label = $self->{label};
$label =~ s/-/_/g;
if (defined($self->{instance_mode}->{option_results}->{'critical_' . $label}) && $self->{instance_mode}->{option_results}->{'critical_' . $label} ne '' &&
eval "$self->{instance_mode}->{option_results}->{'critical_' . $label}") {
$self->{instance_mode}->{dc_critical}++;
$status = 'critical';
} elsif (defined($self->{instance_mode}->{option_results}->{'warning_' . $label}) && $self->{instance_mode}->{option_results}->{'warning_' . $label} ne '' &&
eval "$self->{instance_mode}->{option_results}->{'warning_' . $label}") {
$self->{instance_mode}->{dc_warning}++;
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("alarm [%s] [%s] [%s] [%s] %s/%s",
$self->{result_values}->{status},
$self->{result_values}->{type},
$self->{result_values}->{entity_name},
$self->{result_values}->{time},
$self->{result_values}->{name},
$self->{result_values}->{description}
);
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{entity_name} = $options{new_datas}->{$self->{instance} . '_entity_name'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
$self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'};
$self->{result_values}->{description} = $options{new_datas}->{$self->{instance} . '_description'};
$self->{result_values}->{time} = $options{new_datas}->{$self->{instance} . '_time'};
return 0;
}
sub custom_esxhost_perfdata {
my ($self, %options) = @_;
my $extra_label = '';
# We do it manually. Because we have only 1 instance in group.
if (scalar(keys %{$self->{instance_mode}->{esxhost}}) > 1) {
$extra_label .= '_' . $self->{result_values}->{name};
}
$self->{output}->perfdata_add(label => 'alarm_' . $self->{result_values}->{label_ref} . $extra_label,
value => $self->{result_values}->{alarm_value},
min => 0);
}
sub custom_esxhost_calc {
my ($self, %options) = @_;
$self->{result_values}->{label_ref} = $options{extra_options}->{label_ref};
$self->{result_values}->{alarm_value} = $self->{instance_mode}->{'dc_' . $options{extra_options}->{label_ref}};
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'esxhost', type => 2, cb_prefix_output => 'prefix_esxhost_output', cb_long_output => 'esxhost_long_output', message_multiple => 'All hosts are ok',
group => [
{ name => 'alarm', cb_init => 'alarm_reset', skipped_code => { -11 => 1 } },
{ name => 'esxhost_metrics', display => 0, skipped_code => { -11 => 1 } },
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'total-alarm-warning', set => {
key_values => [ { name => 'yellow' } ],
output_template => '%s warning alarm(s) found(s)',
perfdatas => [
{ label => 'total_alarm_warning', value => 'yellow_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'total-alarm-critical', set => {
key_values => [ { name => 'red' } ],
output_template => '%s critical alarm(s) found(s)',
perfdatas => [
{ label => 'total_alarm_critical', value => 'red_absolute', template => '%s', min => 0 },
],
}
},
];
$self->{maps_counters}->{alarm} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'entity_name' }, { name => 'status' },
{ name => 'time' }, { name => 'description' }, { name => 'name' }, { name => 'type' }, { name => 'since' } ],
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}->{esxhost_metrics} = [
{ label => 'alarm-warning', threshold => 0, set => {
key_values => [ { name => 'name' } ],
output_template => '',
closure_custom_calc => $self->can('custom_esxhost_calc'), closure_custom_calc_extra_options => { label_ref => 'warning' },
closure_custom_perfdata => $self->can('custom_esxhost_perfdata'),
}
},
{ label => 'alarm-critical', threshold => 0, set => {
key_values => [ { name => 'name' } ],
output_template => '',
closure_custom_calc => $self->can('custom_esxhost_calc'), closure_custom_calc_extra_options => { label_ref => 'critical' },
closure_custom_perfdata => $self->can('custom_esxhost_perfdata'),
}
},
];
}
sub prefix_esxhost_output {
my ($self, %options) = @_;
return "Host '" . $options{instance_value}->{display} . "' ";
}
sub alarm_reset {
my ($self, %options) = @_;
$self->{dc_warning} = 0;
$self->{dc_critical} = 0;
}
sub esxhost_long_output {
my ($self, %options) = @_;
return "checking host '" . $options{instance_value}->{display} . "'";
}
sub new {
my ($class, %options) = @_;
@ -39,22 +200,69 @@ sub new {
"scope-cluster:s" => { name => 'scope_cluster' },
"filter-time:s" => { name => 'filter_time', },
"memory" => { name => 'memory', },
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' },
});
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Date::Parse',
error_msg => "Cannot load module 'Date::Parse'.");
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->check_options(%options);
}
}
sub run {
sub manage_selection {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{connector}->add_params(params => $self->{option_results},
command => 'alarmhost');
$self->{connector}->run();
$self->{global} = { yellow => 0, red => 0 };
$self->{esxhost} = {};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'alarmhost');
my $last_time;
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->read(statefile => "cache_vmware_" . $options{custom}->get_id() . '_' . $self->{mode});
$last_time = $self->{statefile_cache}->get(name => 'last_time');
}
my ($i, $current_time) = (1, time());
foreach my $esxhost_id (keys %{$response->{data}}) {
my $esxhost_name = $response->{data}->{$esxhost_id}->{name};
$self->{esxhost}->{$esxhost_name} = { display => $esxhost_name, alarm => {}, esxhost_metrics => { 1 => { name => $esxhost_name } } };
foreach (keys %{$response->{data}->{$esxhost_id}->{alarms}}) {
my $create_time = Date::Parse::str2time($response->{data}->{$esxhost_id}->{alarms}->{$_}->{time});
if (!defined($create_time)) {
$self->{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Can't Parse date '" . $response->{data}->{$esxhost_id}->{alarms}->{$_}->{time} . "'");
next;
}
next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $create_time);
my $diff_time = $current_time - $create_time;
if (defined($self->{option_results}->{filter_time}) && $self->{option_results}->{filter_time} ne '') {
next if ($diff_time > $self->{option_results}->{filter_time});
}
$self->{esxhost}->{$esxhost_name}->{alarm}->{$i} = { %{$response->{data}->{$esxhost_id}->{alarms}->{$_}}, since => $diff_time };
$self->{global}->{$response->{data}->{$esxhost_id}->{alarms}->{$_}->{status}}++;
$i++;
}
}
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->write(data => { last_time => $current_time });
}
}
1;
@ -92,6 +300,26 @@ Don't check alarm older (value in seconds).
Check new alarms only.
=item B<--warning-status>
Set warning threshold for status (Default: '%{status} =~ /yellow/i).
Can used special variables like: %{status}, %{name}, %{entity}, %{type}.
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /red/i').
Can used special variables like: %{status}, %{name}, %{entity}, %{type}.
=item B<--warning-*>
Threshold warning.
Can be: 'total-alarm-warning', 'total-alarm-critical'.
=item B<--critical-*>
Threshold critical.
Can be: 'total-alarm-warning', 'total-alarm-critical'.
=back
=cut

View File

@ -44,15 +44,19 @@ sub check_options {
$self->SUPER::init(%options);
}
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{connector}->set_discovery();
$self->{connector}->add_params(params => $self->{option_results},
command => 'listclusters');
$self->{connector}->run();
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'listclusters');
foreach (keys %{$response->{data}}) {
$self->{output}->output_add(long_msg => ' ' . $response->{data}->{$_}->{name});
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List cluster(s):');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
@ -63,11 +67,12 @@ sub disco_format {
sub disco_show {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
# We ask to use XML output from the connector
$self->{connector}->add_params(params => { disco_show => 1 });
$self->run(custom => $self->{connector});
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'listclusters');
foreach (keys %{$response->{data}}) {
$self->{output}->add_disco_entry(name => $response->{data}->{$_}->{name});
}
}
1;

View File

@ -47,12 +47,19 @@ sub check_options {
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{connector}->set_discovery();
$self->{connector}->add_params(params => $self->{option_results},
command => 'listdatacenters');
$self->{connector}->run();
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'listdatacenters');
foreach (keys %{$response->{data}}) {
$self->{output}->output_add(long_msg => ' ' . $response->{data}->{$_}->{name});
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List datacenter(s):');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
$self->{connector} = $options{custom};
}
sub disco_format {
@ -63,11 +70,12 @@ sub disco_format {
sub disco_show {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
# We ask to use XML output from the connector
$self->{connector}->add_params(params => { disco_show => 1 });
$self->run(custom => $self->{connector});
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'listdatacenters');
foreach (keys %{$response->{data}}) {
$self->{output}->add_disco_entry(name => $response->{data}->{$_}->{name});
}
}
1;

View File

@ -48,12 +48,20 @@ sub check_options {
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{connector}->set_discovery();
$self->{connector}->add_params(params => $self->{option_results},
command => 'listdatastores');
$self->{connector}->run();
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'listdatastores');
foreach (keys %{$response->{data}}) {
$self->{output}->output_add(long_msg => sprintf(" %s [%s] [%s]",
$response->{data}->{$_}->{name},
$response->{data}->{$_}->{accessible},
$response->{data}->{$_}->{type}));
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List datastore(s):');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
@ -64,11 +72,14 @@ sub disco_format {
sub disco_show {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
# We ask to use XML output from the connector
$self->{connector}->add_params(params => { disco_show => 1 });
$self->run(custom => $self->{connector});
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'listdatastores');
foreach (keys %{$response->{data}}) {
$self->{output}->add_disco_entry(name => $response->{data}->{$_}->{name},
accessible => $response->{data}->{$_}->{accessible}, type => $response->{data}->{$_}->{type}
);
}
}
1;

View File

@ -52,12 +52,19 @@ sub check_options {
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'listnichost');
foreach (sort keys %{$response->{data}}) {
$self->{output}->output_add(long_msg => sprintf('%s [status: %s] [vswitch: %s]',
$response->{data}->{$_}->{name}, $response->{data}->{$_}->{status}, $response->{data}->{$_}->{vswitch})
);
}
$self->{connector}->set_discovery();
$self->{connector}->add_params(params => $self->{option_results},
command => 'listnichost');
$self->{connector}->run();
$self->{output}->output_add(severity => 'OK',
short_msg => 'List nic host:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
@ -68,11 +75,14 @@ sub disco_format {
sub disco_show {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
# We ask to use XML output from the connector
$self->{connector}->add_params(params => { disco_show => 1 });
$self->run(custom => $self->{connector});
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'listnichost');
foreach (sort keys %{$response->{data}}) {
$self->{output}->add_disco_entry(name => $response->{data}->{$_}->{name},
status => $response->{data}->{$_}->{status}, vswitch => $response->{data}->{$_}->{vswitch}
);
}
}
1;

View File

@ -106,7 +106,6 @@ sub new {
$_->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $_->{label});
$_->{obj}->{instance_mode} = $self;
$_->{obj}->set(%{$_->{set}});
}
}
@ -131,6 +130,7 @@ sub check_options {
}
foreach my $key (keys %{$self->{maps_counters}}) {
foreach (@{$self->{maps_counters}->{$key}}) {
$_->{obj}->{instance_mode} = $self;
$_->{obj}->init(option_results => $self->{option_results});
}
}
@ -364,7 +364,7 @@ sub run_group {
if (defined($options{config}->{cb_prefix_output}));
$prefix_output = '' if (!defined($prefix_output));
if ($multiple == 0) {
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");
}