WIP centreon compat with connector 3.0.0

This commit is contained in:
garnier-quentin 2019-02-04 11:30:30 +01:00
parent c65a3329fc
commit f08940976d
3 changed files with 144 additions and 47 deletions
centreon-plugins/apps/vmware/connector/mode

View File

@ -99,10 +99,10 @@ sub set_counters {
$self->{maps_counters}->{cpu} = [
{ label => 'cpu', set => {
key_values => [ { name => 'cpu_usage' }, { name => 'display' } ],
output_template => 'usage : %s %%',
output_template => 'usage : %s MHz',
perfdatas => [
{ label => 'cpu', value => 'cpu_usage_absolute', template => '%s', unit => '%',
min => 0, max => 100, label_extra_instance => 1 },
{ label => 'cpu', value => 'cpu_usage_absolute', template => '%s', unit => 'MHz',
min => 0, label_extra_instance => 1 },
],
}
},
@ -179,6 +179,8 @@ sub manage_selection {
$self->{vm} = {};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'cpuvm');
use Data::Dumper;
print Data::Dumper::Dumper($response);
foreach my $vm_id (keys %{$response->{data}}) {
my $vm_name = $response->{data}->{$vm_id}->{name};

View File

@ -233,14 +233,12 @@ Can used special variables like: %{status}
=item B<--warning-*>
Threshold warning.
Can be: 'total-on', 'total-off', 'total-suspended',
'on', 'off', 'suspended'.
Can be: 'read', 'write', 'read-vm', 'write-vm'.
=item B<--critical-*>
Threshold critical.
Can be: 'total-on', 'total-off', 'total-suspended',
'on', 'off', 'suspended'.
Can be: 'read', 'write', 'read-vm', 'write-vm'.
=back

View File

@ -20,10 +20,92 @@
package apps::vmware::connector::mode::datastoresnapshot;
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 = 'accessible ' . $self->{result_values}->{accessible};
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{accessible} = $options{new_datas}->{$self->{instance} . '_accessible'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'datastore', type => 3, cb_prefix_output => 'prefix_datastore_output', cb_long_output => 'datastore_long_output', indent_long_output => ' ', message_multiple => 'All datastores are ok',
group => [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'global_snapshot', type => 0, skipped_code => { -10 => 1 } },
{ name => 'files', cb_prefix_output => 'prefix_files_output', message_multiple => 'All snapshot files are ok', type => 1, skipped_code => { -10 => 1 } },
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'accessible' } ],
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_snapshot} = [
{ label => 'total', set => {
key_values => [ { name => 'total' } ],
output_template => 'total snapshots [size = %s %s]',
output_change_bytes => 2,
perfdatas => [
{ label => 'total_size', value => 'total_absolute', template => '%s', unit => 'B',
min => 0, label_extra_instance => 1 },
],
}
},
];
$self->{maps_counters}->{files} = [
{ label => 'snapshot', set => {
key_values => [ { name => 'total' } ],
output_template => '[size = %s %s]',
output_change_bytes => 2,
closure_custom_perfdata => sub { return 0; },
}
},
];
}
sub prefix_datastore_output {
my ($self, %options) = @_;
return "Datastore '" . $options{instance_value}->{display} . "' : ";
}
sub datastore_long_output {
my ($self, %options) = @_;
return "checking datastore '" . $options{instance_value}->{display} . "'";
}
sub prefix_files_output {
my ($self, %options) = @_;
return sprintf("file snapshot [%s]=>[%s] ", $options{instance_value}->{folder_path}, $options{instance_value}->{path});
}
sub new {
my ($class, %options) = @_;
@ -31,45 +113,55 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"datastore-name:s" => { name => 'datastore_name' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
"warning-total:s" => { name => 'warning_total', },
"critical-total:s" => { name => 'critical_total', },
"warning-snapshot:s" => { name => 'warning_snapshot', },
"critical-snapshot:s" => { name => 'critical_snapshot', },
});
$options{options}->add_options(arguments => {
"datastore-name:s" => { name => 'datastore_name' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"unknown-status:s" => { name => 'unknown_status', default => '%{accessible} !~ /^true|1$/i' },
"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);
foreach my $label (('warning_total', 'critical_total', 'warning_snapshot', 'critical_snapshot')) {
if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) {
my ($label_opt) = $label;
$label_opt =~ tr/_/-/;
$self->{output}->add_option_msg(short_msg => "Wrong " . $label_opt . " threshold '" . $self->{option_results}->{$label} . "'.");
$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 {
sub manage_selection {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{connector}->add_params(params => $self->{option_results},
command => 'datastoresnapshot');
$self->{connector}->run();
$self->{datastore} = {};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'datastoresnapshot');
my $i = 0;
foreach my $ds_id (keys %{$response->{data}}) {
my $ds_name = $response->{data}->{$ds_id}->{name};
$self->{datastore}->{$ds_name} = { display => $ds_name,
files => {},
global => {
accessible => $response->{data}->{$ds_id}->{accessible},
},
global_snapshot => {
total => 0
},
};
foreach (@{$response->{data}->{$ds_id}->{snapshost}}) {
$self->{datastore}->{$ds_name}->{files}->{$i} = {
folder_path => $_->{folder_path},
path => $_->{path},
total => $_->{size},
};
$self->{datastore}->{$ds_name}->{global_snapshot}->{total} += $_->{size};
$i++;
}
}
}
1;
@ -94,25 +186,30 @@ Datastore name is a regexp.
Search in following datacenter(s) (can be a regexp).
=item B<--disconnect-status>
=item B<--unknown-status>
Status if datastore disconnected (default: 'unknown').
Set warning threshold for status (Default: '%{accessible} !~ /^true|1$/i').
Can used special variables like: %{status}
=item B<--warning-total>
=item B<--warning-status>
Threshold warning in bytes for all snapshots.
Set warning threshold for status (Default: '').
Can used special variables like: %{status}
=item B<--critical-total>
=item B<--critical-status>
Threshold critical in bytes for all snapshots.
Set critical threshold for status (Default: '').
Can used special variables like: %{status}
=item B<--warning-snapshot>
=item B<--warning-*>
Threshold warning in bytes for a single snapshot.
Threshold warning.
Can be: 'total', 'snapshot'.
=item B<--critical-snapshot>
=item B<--critical-*>
Threshold critical in bytes for a single snapshot.
Threshold critical.
Can be: 'total', 'snapshot'.
=back