diff --git a/connectors/vmware/src/centreon/script/centreon_vmware.pm b/connectors/vmware/src/centreon/script/centreon_vmware.pm index 6fd7180b3..8132acea3 100644 --- a/connectors/vmware/src/centreon/script/centreon_vmware.pm +++ b/connectors/vmware/src/centreon/script/centreon_vmware.pm @@ -51,6 +51,7 @@ my @load_modules = ( 'centreon::vmware::cmdcountvmhost', 'centreon::vmware::cmdcpuhost', 'centreon::vmware::cmdcpuvm', + 'centreon::vmware::cmddatastorecountvm', 'centreon::vmware::cmddatastoreio', 'centreon::vmware::cmddatastoreiops', 'centreon::vmware::cmddatastorehost', diff --git a/connectors/vmware/src/centreon/vmware/cmddatastorecountvm.pm b/connectors/vmware/src/centreon/vmware/cmddatastorecountvm.pm new file mode 100644 index 000000000..352a6e2d5 --- /dev/null +++ b/connectors/vmware/src/centreon/vmware/cmddatastorecountvm.pm @@ -0,0 +1,166 @@ +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package centreon::vmware::cmddatastorecountvm; + +use strict; +use warnings; +use centreon::vmware::common; + +sub new { + my $class = shift; + my $self = {}; + $self->{logger} = shift; + $self->{commandName} = 'datastorecountvm'; + + bless $self, $class; + return $self; +} + +sub getCommandName { + my $self = shift; + return $self->{commandName}; +} + +sub checkArgs { + my ($self, %options) = @_; + + if (defined($options{arguments}->{datastore_name}) && $options{arguments}->{datastore_name} eq "") { + $options{manager}->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Argument error: datastore name cannot be null"); + return 1; + } + if (defined($options{arguments}->{disconnect_status}) && + $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{disconnect_status}) == 0) { + $options{manager}->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Argument error: wrong value for disconnect status '" . $options{arguments}->{disconnect_status} . "'"); + return 1; + } + foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) { + if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) { + $options{manager}->{output}->output_add(severity => 'UNKNOWN', + short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'."); + return 1; + } + } + return 0; +} + +sub initArgs { + my ($self, %options) = @_; + + foreach (keys %{$options{arguments}}) { + $self->{$_} = $options{arguments}->{$_}; + } + $self->{manager} = centreon::vmware::common::init_response(); + $self->{manager}->{output}->{plugin} = $options{arguments}->{identity}; + foreach my $label (('warning_on', 'critical_on', 'warning_off', 'critical_off', 'warning_suspended', 'critical_suspended')) { + $self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label}); + } +} + +sub set_connector { + my ($self, %options) = @_; + + $self->{connector} = $options{connector}; +} + +sub run { + my $self = shift; + + my %filters = (); + my $multiple = 0; + if (defined($self->{datastore_name}) && !defined($self->{filter})) { + $filters{name} = qr/^\Q$self->{datastore_name}\E$/; + } elsif (!defined($self->{datastore_name})) { + $filters{name} = qr/.*/; + } else { + $filters{name} = qr/$self->{datastore_name}/; + } + my @properties = ('summary.name', 'vm', 'summary.accessible'); + my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => \%filters); + return if (!defined($result)); + + if (scalar(@$result) > 1) { + $multiple = 1; + } + + my @vm_array = (); + foreach my $entity_view (@$result) { + if (defined($entity_view->vm)) { + @vm_array = (@vm_array, @{$entity_view->vm}); + } + } + @properties = ('runtime.powerState'); + my $result2 = centreon::vmware::common::get_views($self->{connector}, \@vm_array, \@properties); + return if (!defined($result2)); + + if ($multiple == 1) { + $self->{manager}->{output}->output_add(severity => 'OK', + short_msg => sprintf("All Datastores are ok")); + } + + foreach my $entity_view (@$result) { + next if (centreon::vmware::common::datastore_state(connector => $self->{connector}, + name => $entity_view->{'summary.name'}, + state => $entity_view->{'summary.accessible'}, + status => $self->{disconnect_status}, + multiple => $multiple) == 0); + + my $extra_label = ''; + $extra_label = '_' . $entity_view->{'summary.name'} if ($multiple == 1); + my %vm_states = (poweredon => 0, poweredoff => 0, suspended => 0); + if (defined($entity_view->vm)) { + foreach my $vm_host (@{$entity_view->vm}) { + foreach my $vm (@{$result2}) { + if ($vm_host->{value} eq $vm->{mo_ref}->{value}) { + my $power_value = lc($vm->{'runtime.powerState'}->val); + $vm_states{$power_value}++; + last; + } + } + } + } + + foreach my $labels ((['poweredon', 'warning_on', 'critical_on'], + ['poweredoff', 'warning_off', 'critical_off'], + ['suspended', 'warning_suspended', 'critical_suspended'])) { + my $exit = $self->{manager}->{perfdata}->threshold_check(value => $vm_states{$labels->[0]}, + threshold => [ { label => $labels->[2], exit_litteral => 'critical' }, + { label => $labels->[1], exit_litteral => 'warning' } ]); + $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' %s VM(s) %s", $entity_view->{'summary.name'}, + $vm_states{$labels->[0]}, + $labels->[0])); + if ($multiple == 0 || + !$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{manager}->{output}->output_add(severity => $exit, + short_msg => sprintf("'%s' %s VM(s) %s", $entity_view->{'summary.name'}, + $vm_states{$labels->[0]}, + $labels->[0])); + } + + $self->{manager}->{output}->perfdata_add(label => $labels->[0] . $extra_label, + value => $vm_states{$labels->[0]}, + warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => $labels->[1]), + critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => $labels->[2]), + min => 0, max => $vm_states{poweredoff} + $vm_states{suspended} + $vm_states{poweredon}); + } + } +} + +1; diff --git a/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm b/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm index e4c66984a..5f80a9fd6 100644 --- a/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm +++ b/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm @@ -55,7 +55,7 @@ sub checkArgs { $self->{output}->add_option_msg(short_msg => "Wrong units option '" . (defined($options{arguments}->{units}) ? $options{arguments}->{units} : 'null') . "'."); $self->{output}->option_exit(); } - foreach my $label (('warning', 'critical')) { + foreach my $label (('warning', 'critical', 'warning_provisioned', 'critical_provisioned')) { if (($options{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label})) == 0) { $options{manager}->{output}->output_add(severity => 'UNKNOWN', short_msg => "Argument error: wrong value for $label value '" . $options{arguments}->{$label} . "'."); @@ -73,7 +73,7 @@ sub initArgs { } $self->{manager} = centreon::vmware::common::init_response(); $self->{manager}->{output}->{plugin} = $options{arguments}->{identity}; - foreach my $label (('warning', 'critical')) { + foreach my $label (('warning', 'critical', 'warning_provisioned', 'critical_provisioned')) { $self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label}); } } @@ -126,6 +126,7 @@ sub run { } # in Bytes + my $exits = []; my $name_storage = $entity_view->summary->name; my $total_size = $entity_view->summary->capacity; my $total_free = $entity_view->summary->freeSpace; @@ -133,29 +134,42 @@ sub run { my $prct_used = $total_used * 100 / $total_size; my $prct_free = 100 - $prct_used; - my ($exit, $threshold_value); + my ($total_uncommited, $prct_uncommited); + my $msg_uncommited = ''; + if (defined($entity_view->summary->uncommitted)) { + $total_uncommited = $total_used + $entity_view->summary->uncommitted; + $prct_uncommited = $total_uncommited * 100 / $total_size; + my ($total_uncommited_value, $total_uncommited_unit) = $self->{manager}->{perfdata}->change_bytes(value => $total_uncommited); + $msg_uncommited = sprintf(" Provisioned: %s (%.2f%%)", $total_uncommited_value . " " . $total_uncommited_unit, $prct_uncommited); + push @{$exits}, $self->{manager}->{perfdata}->threshold_check(value => $prct_uncommited, threshold => [ { label => 'critical_provisioned', exit_litteral => 'critical' }, { label => 'warning_provisioned', exit_litteral => 'warning' } ]); + } + + my ($threshold_value); $threshold_value = $total_used; $threshold_value = $total_free if (defined($self->{free})); if ($self->{units} eq '%') { $threshold_value = $prct_used; $threshold_value = $prct_free if (defined($self->{free})); } - $exit = $self->{manager}->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - + push @{$exits}, $self->{manager}->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{manager}->{output}->get_most_critical(status => $exits); + my ($total_size_value, $total_size_unit) = $self->{manager}->{perfdata}->change_bytes(value => $total_size); my ($total_used_value, $total_used_unit) = $self->{manager}->{perfdata}->change_bytes(value => $total_used); my ($total_free_value, $total_free_unit) = $self->{manager}->{perfdata}->change_bytes(value => $total_free); - $self->{manager}->{output}->output_add(long_msg => sprintf("Datastore '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name_storage, + $self->{manager}->{output}->output_add(long_msg => sprintf("Datastore '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)%s", $name_storage, $total_size_value . " " . $total_size_unit, $total_used_value . " " . $total_used_unit, $prct_used, - $total_free_value . " " . $total_free_unit, $prct_free)); + $total_free_value . " " . $total_free_unit, $prct_free, + $msg_uncommited)); if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || $multiple == 0) { $self->{manager}->{output}->output_add(severity => $exit, - short_msg => sprintf("Datastore '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name_storage, + short_msg => sprintf("Datastore '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)%s", $name_storage, $total_size_value . " " . $total_size_unit, $total_used_value . " " . $total_used_unit, $prct_used, - $total_free_value . " " . $total_free_unit, $prct_free)); + $total_free_value . " " . $total_free_unit, $prct_free, + $msg_uncommited)); } my $label = 'used'; @@ -176,6 +190,13 @@ sub run { warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options), critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options), min => 0, max => $total_size); + if (defined($total_uncommited)) { + $self->{manager}->{output}->perfdata_add(label => 'provisioned' . $extra_label, unit => 'B', + value => $total_uncommited, + warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning_provisioned', total => $total_size, cast_int => 1), + critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical_provisioned', total => $total_size, cast_int => 1), + min => 0, max => $total_size); + } } }