WIP: centreon connector 3.0.0 vmware compat

This commit is contained in:
garnier-quentin 2019-02-06 10:52:00 +01:00
parent e3cbaadd99
commit 0899c1be5a
4 changed files with 197 additions and 43 deletions

View File

@ -218,7 +218,7 @@ sub connector_response_status {
}
}
sub host_is_connected {
sub entity_is_connected {
my ($self, %options) = @_;
if ($options{state} !~ /^connected$/i) {

View File

@ -91,7 +91,7 @@ sub run {
foreach my $vm_id (sort keys %{$response->{data}}) {
my $vm_name = $response->{data}->{$vm_id}->{name};
if ($options{custom}->host_is_connected(state => $response->{data}->{$vm_id}->{connection_state}) == 0) {
if ($options{custom}->entity_is_connected(state => $response->{data}->{$vm_id}->{connection_state}) == 0) {
my $output = "VM '" . $vm_name . "' not connected. Current Connection State: '$response->{data}->{$vm_id}->{connection_state}'.";
if ($multiple == 0 ||
!$self->{output}->is_status(value => $self->{option_results}->{disconnect_status}, compare => 'ok', litteral => 1)) {

View File

@ -31,19 +31,19 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"vm-hostname:s" => { name => 'vm_hostname' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"scope-cluster:s" => { name => 'scope_cluster' },
"scope-host:s" => { name => 'scope_host' },
"filter-description:s" => { name => 'filter_description' },
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
"nopoweredon-skip" => { name => 'nopoweredon_skip' },
"display-description" => { name => 'display_description' },
"thinprovisioning-status:s" => { name => 'thinprovisioning_status' },
});
$options{options}->add_options(arguments => {
"vm-hostname:s" => { name => 'vm_hostname' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"scope-cluster:s" => { name => 'scope_cluster' },
"scope-host:s" => { name => 'scope_host' },
"filter-description:s" => { name => 'filter_description' },
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
"nopoweredon-skip" => { name => 'nopoweredon_skip' },
"display-description" => { name => 'display_description' },
"thinprovisioning-status:s" => { name => 'thinprovisioning_status' },
});
return $self;
}
@ -56,25 +56,90 @@ sub check_options {
$self->{output}->option_exit();
}
if (defined($self->{option_results}->{thinprovisioning_status}) && $self->{option_results}->{thinprovisioning_status} ne '') {
my ($entry, $status) = split /,/, $self->{option_results}->{thinprovisioning_status};
if ($entry !~ /^(notactive|active)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong thinprovisioning-status option. Can only be 'active' or 'noactive'. Not: '" . $entry . "'.");
($self->{thin_entry}, $self->{thin_status}) = split /,/, $self->{option_results}->{thinprovisioning_status};
if ($self->{thin_entry} !~ /^(notactive|active)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong thinprovisioning-status option. Can only be 'active' or 'noactive'. Not: '" . $self->{thin_entry} . "'.");
$self->{output}->option_exit();
}
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong thinprovisioning-status option. Not a good status: '" . $status . "'.");
if ($self->{output}->is_litteral_status(status => $self->{thin_status}) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong thinprovisioning-status option. Not a good status: '" . $self->{thin_status} . "'.");
$self->{output}->option_exit();
}
}
}
sub display_verbose {
my ($self, %options) = @_;
foreach my $vm (sort keys %{$options{vms}}) {
my $prefix = $vm;
if (defined($options{vms}->{$vm}->{description}) && $options{vms}->{$vm}->{description} ne '') {
$prefix .= ' [' . $options{vms}->{$vm}->{description} . ']';
}
$self->{output}->output_add(long_msg => $prefix);
foreach my $disk (sort keys %{$options{vms}->{$vm}->{disks}}) {
$self->{output}->output_add(long_msg => ' ' . $disk);
}
}
}
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'thinprovisioningvm');
$self->{connector}->add_params(params => $self->{option_results},
command => 'thinprovisioningvm');
$self->{connector}->run();
my $multiple = 0;
if (scalar(keys %{$response->{data}}) > 1) {
$multiple = 1;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All thinprovisoning virtualdisks are ok.');
} else {
$self->{output}->output_add(severity => 'OK',
short_msg => 'Thinprovisoning virtualdisks are ok.');
}
my $disks_vm = {};
my %maps_match = ('active' => { regexp => '^1$', output => 'VirtualDisks thinprovisioning actived' },
'notactive' => { regexp => '^(?!(1)$)', output => 'VirtualDisks thinprovisioning not actived' });
my $num = 0;
foreach my $vm_id (sort keys %{$response->{data}}) {
my $vm_name = $response->{data}->{$vm_id}->{name};
if ($options{custom}->entity_is_connected(state => $response->{data}->{$vm_id}->{connection_state}) == 0) {
my $output = "VM '" . $vm_name . "' not connected. Current Connection State: '$response->{data}->{$vm_id}->{connection_state}'.";
if ($multiple == 0 ||
!$self->{output}->is_status(value => $self->{option_results}->{disconnect_status}, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $self->{option_results}->{disconnect_status},
short_msg => $output);
}
next;
}
next if (defined($self->{option_results}->{nopoweredon_skip}) &&
$options{custom}->vm_is_running(power => $response->{data}->{$vm_id}->{power_state}) == 0);
foreach (@{$response->{data}->{$vm_id}->{disks}}) {
if (defined($self->{thin_entry}) && $_->{thin_provisioned} =~ /$maps_match{$self->{thin_entry}}->{regexp}/) {
$num++;
if (!defined($disks_vm->{$vm_name})) {
$disks_vm->{$vm_name} = { disks => {}, description => (defined($self->{option_results}->{display_description}) ? $options{custom}->strip_cr(value => $response->{data}->{$vm_id}->{'config.annotation'}) : undef) };
}
$disks_vm->{$vm_name}->{disks}->{$_->{name}} = 1;
}
}
}
if ($num > 0) {
$self->{output}->output_add(severity => $self->{thin_status},
short_msg => sprintf('%d %s', $num, $maps_match{$self->{thin_entry}}->{output}));
$self->display_verbose(vms => $disks_vm);
}
$self->{output}->display();
$self->{output}->exit();
}
1;

View File

@ -31,21 +31,21 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"vm-hostname:s" => { name => 'vm_hostname' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"scope-cluster:s" => { name => 'scope_cluster' },
"scope-host:s" => { name => 'scope_host' },
"filter-description:s" => { name => 'filter_description' },
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
"display-description" => { name => 'display_description' },
"tools-notinstalled-status:s" => { name => 'tools_notinstalled_status', default => 'critical' },
"tools-notrunning-status:s" => { name => 'tools_notrunning_status', default => 'critical' },
"tools-notup2date-status:s" => { name => 'tools_notupd2date_status', default => 'warning' },
"nopoweredon-skip" => { name => 'nopoweredon_skip' },
});
$options{options}->add_options(arguments => {
"vm-hostname:s" => { name => 'vm_hostname' },
"filter" => { name => 'filter' },
"scope-datacenter:s" => { name => 'scope_datacenter' },
"scope-cluster:s" => { name => 'scope_cluster' },
"scope-host:s" => { name => 'scope_host' },
"filter-description:s" => { name => 'filter_description' },
"display-description" => { name => 'display_description' },
"disconnect-status:s" => { name => 'disconnect_status', default => 'unknown' },
"tools-notinstalled-status:s" => { name => 'tools_notinstalled_status', default => 'critical' },
"tools-notrunning-status:s" => { name => 'tools_notrunning_status', default => 'critical' },
"tools-notup2date-status:s" => { name => 'tools_notupd2date_status', default => 'warning' },
"nopoweredon-skip" => { name => 'nopoweredon_skip' },
});
return $self;
}
@ -71,13 +71,102 @@ sub check_options {
}
}
sub display_verbose {
my ($self, %options) = @_;
$self->{output}->output_add(long_msg => $options{label});
foreach my $vm (sort keys %{$options{vms}}) {
my $prefix = $vm;
if ($options{vms}->{$vm} ne '') {
$prefix .= ' [' . $options{custom}->strip_cr(value => $options{vms}->{$vm}) . ']';
}
$self->{output}->output_add(long_msg => ' ' . $prefix);
}
}
sub run {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
my $response = $options{custom}->execute(params => $self->{option_results},
command => 'toolsvm');
$self->{connector}->add_params(params => $self->{option_results},
command => 'toolsvm');
$self->{connector}->run();
my $multiple = 0;
if (scalar(keys %{$response->{data}}) > 1) {
$multiple = 1;
}
if ($multiple == 1) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All VMTools are OK');
} else {
$self->{output}->output_add(severity => 'OK',
short_msg => 'VMTools are OK');
}
my %not_installed = ();
my %not_running = ();
my %not_up2date = ();
foreach my $vm_id (sort keys %{$response->{data}}) {
my $vm_name = $response->{data}->{$vm_id}->{name};
if ($options{custom}->entity_is_connected(state => $response->{data}->{$vm_id}->{connection_state}) == 0) {
my $output = "VM '" . $vm_name . "' not connected. Current Connection State: '$response->{data}->{$vm_id}->{connection_state}'.";
if ($multiple == 0 ||
!$self->{output}->is_status(value => $self->{option_results}->{disconnect_status}, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $self->{option_results}->{disconnect_status},
short_msg => $output);
}
next;
}
next if (defined($self->{option_results}->{nopoweredon_skip}) &&
$options{custom}->vm_is_running(power => $response->{data}->{$vm_id}->{power_state}) == 0);
next if (!defined($response->{data}->{$vm_id}->{tools_status}));
my $tools_status = lc($response->{data}->{$vm_id}->{tools_status});
if ($tools_status eq 'toolsnotinstalled') {
$not_installed{$vm_name} = defined($response->{data}->{$vm_id}->{'config.annotation'}) ? $response->{data}->{$vm_id}->{'config.annotation'} : '';
} elsif ($tools_status eq 'toolsnotrunning') {
$not_running{$vm_name} = defined($response->{data}->{$vm_id}->{'config.annotation'}) ? $response->{data}->{$vm_id}->{'config.annotation'} : '';
} elsif ($tools_status eq 'toolsold') {
$not_up2date{$vm_name} = defined($response->{data}->{$vm_id}->{'config.annotation'}) ? $response->{data}->{$vm_id}->{'config.annotation'} : '';
}
}
if (scalar(keys %not_up2date) > 0 &&
!$self->{output}->is_status(value => $self->{option_results}->{tools_notupd2date_status}, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $self->{option_results}->{tools_notupd2date_status},
short_msg => sprintf('%d VM with VMTools not up-to-date', scalar(keys %not_up2date)));
$self->display_verbose(label => 'vmtools not up-to-date:', vms => \%not_up2date, custom => $options{custom});
}
if (scalar(keys %not_running) > 0 &&
!$self->{output}->is_status(value => $self->{option_results}->{tools_notrunning_status}, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $self->{option_results}->{tools_notrunning_status},
short_msg => sprintf('%d VM with VMTools not running', scalar(keys %not_running)));
$self->display_verbose(label => 'vmtools not running:', vms => \%not_running, custom => $options{custom});
}
if (scalar(keys %not_installed) > 0 &&
!$self->{output}->is_status(value => $self->{option_results}->{tools_notinstalled_status}, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $self->{option_results}->{tools_notinstalled_status},
short_msg => sprintf('%d VM with VMTools not installed', scalar(keys %not_installed)));
$self->display_verbose(label => 'vmtools not installed:', vms => \%not_installed, custom => $options{custom});
}
if ($multiple == 1) {
my $total = scalar(keys %not_up2date) + scalar(keys %not_running) + scalar(keys %not_installed);
$self->{output}->perfdata_add(label => 'not_updated',
value => scalar(keys %not_up2date),
min => 0, max => $total);
$self->{output}->perfdata_add(label => 'not_running',
value => scalar(keys %not_running),
min => 0, max => $total);
$self->{output}->perfdata_add(label => 'not_installed',
value => scalar(keys %not_installed),
min => 0, max => $total);
}
$self->{output}->display();
$self->{output}->exit();
}
1;