diff --git a/connectors/vmware/src/centreon/common/logger.pm b/connectors/vmware/src/centreon/common/logger.pm new file mode 100644 index 000000000..1f726c128 --- /dev/null +++ b/connectors/vmware/src/centreon/common/logger.pm @@ -0,0 +1,218 @@ +# 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::common::logger; + +=head1 NOM + +centreon::common::logger - Simple logging module + +=head1 SYNOPSIS + + #!/usr/bin/perl -w + + use strict; + use warnings; + + use centreon::polling; + + my $logger = new centreon::common::logger(); + + $logger->writeLogInfo("information"); + +=head1 DESCRIPTION + +This module offers a simple interface to write log messages to various output: + +* standard output +* file +* syslog + +=cut + +use strict; +use warnings; +use Sys::Syslog qw(:standard :macros); +use IO::Handle; + +my %severities = (1 => LOG_INFO, + 2 => LOG_ERR, + 4 => LOG_DEBUG); + +sub new { + my $class = shift; + + my $self = bless + { + file => 0, + filehandler => undef, + # 0 = nothing, 1 = critical, 3 = info, 7 = debug + severity => 3, + old_severity => 3, + # 0 = stdout, 1 = file, 2 = syslog + log_mode => 0, + # Output pid of current process + withpid => 0, + # syslog + log_facility => undef, + log_option => LOG_PID, + }, $class; + return $self; +} + +sub file_mode($$) { + my ($self, $file) = @_; + + if (defined($self->{filehandler})) { + $self->{filehandler}->close(); + } + if (open($self->{filehandler}, ">>", $file)){ + $self->{log_mode} = 1; + $self->{filehandler}->autoflush(1); + $self->{file_name} = $file; + return 1; + } + $self->{filehandler} = undef; + print STDERR "Cannot open file $file: $!\n"; + return 0; +} + +sub is_file_mode { + my $self = shift; + + if ($self->{log_mode} == 1) { + return 1; + } + return 0; +} + +sub is_debug { + my $self = shift; + + if (($self->{severity} & 4) == 0) { + return 0; + } + return 1; +} + +sub syslog_mode($$$) { + my ($self, $logopt, $facility) = @_; + + $self->{log_mode} = 2; + openlog($0, $logopt, $facility); + return 1; +} + +# For daemons +sub redirect_output { + my $self = shift; + + if ($self->is_file_mode()) { + open my $lfh, '>>', $self->{file_name}; + open STDOUT, '>&', $lfh; + open STDERR, '>&', $lfh; + } +} + +sub set_default_severity { + my $self = shift; + + $self->{severity} = $self->{old_severity}; +} + +# Getter/Setter Log severity +sub severity { + my $self = shift; + if (@_) { + my $save_severity = $self->{severity}; + if ($_[0] =~ /^[012347]$/) { + $self->{severity} = $_[0]; + } elsif ($_[0] eq "none") { + $self->{severity} = 0; + } elsif ($_[0] eq "error") { + $self->{severity} = 1; + } elsif ($_[0] eq "info") { + $self->{severity} = 3; + } elsif ($_[0] eq "debug") { + $self->{severity} = 7; + } else { + $self->writeLogError("Wrong severity value set."); + return -1; + } + $self->{old_severity} = $save_severity; + } + return $self->{severity}; +} + +sub withpid { + my $self = shift; + if (@_) { + $self->{withpid} = $_[0]; + } + return $self->{withpid}; +} + +sub get_date { + my $self = shift; + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time()); + return sprintf("%04d-%02d-%02d %02d:%02d:%02d", + $year+1900, $mon+1, $mday, $hour, $min, $sec); +} + +sub writeLog($$$%) { + my ($self, $severity, $msg, %options) = @_; + my $withdate = (defined $options{withdate}) ? $options{withdate} : 1; + $msg = ($self->{withpid} == 1) ? "$$ - $msg " : $msg; + my $newmsg = ($withdate) + ? $self->get_date . " - $msg" : $msg; + + if (($self->{severity} & $severity) == 0) { + return; + } + if ($self->{log_mode} == 0) { + print "$newmsg\n"; + } elsif ($self->{log_mode} == 1) { + if (defined $self->{filehandler}) { + print { $self->{filehandler} } "$newmsg\n"; + } + } elsif ($self->{log_mode} == 2) { + syslog($severities{$severity}, $msg); + } +} + +sub writeLogDebug { + shift->writeLog(4, @_); +} + +sub writeLogInfo { + shift->writeLog(2, @_); +} + +sub writeLogError { + shift->writeLog(1, @_); +} + +sub DESTROY { + my $self = shift; + + if (defined $self->{filehandler}) { + $self->{filehandler}->close(); + } +} + +1; diff --git a/connectors/vmware/src/centreon/script.pm b/connectors/vmware/src/centreon/script.pm new file mode 100644 index 000000000..5f83dc1c4 --- /dev/null +++ b/connectors/vmware/src/centreon/script.pm @@ -0,0 +1,94 @@ +# 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::script; + +use strict; +use warnings; +use FindBin; +use Getopt::Long; +use Pod::Usage; +use centreon::common::logger; + +$SIG{__DIE__} = sub { + return unless defined $^S and $^S == 0; # Ignore errors in eval + my $error = shift; + print "Error: $error"; + exit 1; +}; + +sub new { + my ($class, $name, %options) = @_; + my %defaults = + ( + log_file => undef, + severity => "info", + noroot => 0, + ); + my $self = {%defaults, %options}; + + bless $self, $class; + $self->{name} = $name; + $self->{logger} = centreon::common::logger->new(); + $self->{options} = { + "logfile=s" => \$self->{log_file}, + "severity=s" => \$self->{severity}, + "help|?" => \$self->{help} + }; + return $self; +} + +sub init { + my $self = shift; + + if (defined $self->{log_file}) { + $self->{logger}->file_mode($self->{log_file}); + } + $self->{logger}->severity($self->{severity}); + + if ($self->{noroot} == 1) { + # Stop exec if root + if ($< == 0) { + $self->{logger}->writeLogError("Can't execute script as root."); + die("Quit"); + } + } +} + +sub add_options { + my ($self, %options) = @_; + + $self->{options} = {%{$self->{options}}, %options}; +} + +sub parse_options { + my $self = shift; + + Getopt::Long::Configure('bundling'); + die "Command line error" if !GetOptions(%{$self->{options}}); + pod2usage(-exitval => 1, -input => $FindBin::Bin . "/" . $FindBin::Script) if $self->{help}; +} + +sub run { + my $self = shift; + + $self->parse_options(); + $self->init(); +} + +1; diff --git a/connectors/vmware/src/centreon/script/centreon_vmware.pm b/connectors/vmware/src/centreon/script/centreon_vmware.pm index 202c84ae9..b10e152ed 100644 --- a/connectors/vmware/src/centreon/script/centreon_vmware.pm +++ b/connectors/vmware/src/centreon/script/centreon_vmware.pm @@ -28,7 +28,7 @@ use ZMQ::Constants qw(:all); use File::Basename; use Digest::MD5 qw(md5_hex); use POSIX ":sys_wait_h"; -use JSON; +use JSON::XS; use centreon::script; use centreon::vmware::common; use centreon::vmware::connector; @@ -99,6 +99,7 @@ my @load_modules = ( sub new { my $class = shift; my $self = $class->SUPER::new("centreon_vmware", + # we keep it if we use centreon common library centreon_db_conn => 0, centstorage_db_conn => 0, noconfig => 1 @@ -119,10 +120,6 @@ sub new { dynamic_timeout_kill => 86400, refresh_keeper_session => 15, port => 5700, - datastore_state_error => 'UNKNOWN', - vm_state_error => 'UNKNOWN', - host_state_error => 'UNKNOWN', - retention_dir => '/var/lib/centreon/centplugins', case_insensitive => 0, vsphere_server => { #'default' => {'url' => 'https://XXXXXX/sdk', @@ -139,7 +136,6 @@ sub new { $self->{childs_vpshere_pid} = {}; $self->{counter_stats} = {}; $self->{whoaim} = undef; # to know which vsphere to connect - $self->{module_date_parse_loaded} = 0; $self->{modules_registry} = {}; return $self; @@ -193,12 +189,6 @@ sub init { $self->{centreon_vmware_config}->{vsphere_server}->{$_}->{password} = $lpassword; } } - - eval 'require Date::Parse'; - if (!$@) { - $self->{module_date_parse_loaded} = 1; - require Date::Parse; - } $self->set_signal_handlers; } @@ -381,7 +371,7 @@ sub request { # Decode json my $result; eval { - $result = JSON->new->utf8->decode($options{data}); + $result = JSON::XS->new->utf8->decode($options{data}); }; if ($@) { centreon::vmware::common::set_response(code => 1, short_message => "Cannot decode json result: $@"); @@ -436,7 +426,7 @@ sub repserver { # Decode json my $result; eval { - $result = JSON->new->utf8->decode($options{data}); + $result = JSON::XS->new->utf8->decode($options{data}); }; if ($@) { $self->{logger}->writeLogError("Cannot decode JSON: $@ (options{data}"); @@ -513,7 +503,6 @@ sub create_vsphere_child { if ($child_vpshere_pid == 0) { my $connector = centreon::vmware::connector->new(name => $self->{whoaim}, modules_registry => $self->{modules_registry}, - module_date_parse_loaded => $self->{module_date_parse_loaded}, config => $self->{centreon_vmware_config}, logger => $self->{logger}); $connector->run(); diff --git a/connectors/vmware/src/centreon/vmware/cmdgetmap.pm b/connectors/vmware/src/centreon/vmware/cmdgetmap.pm index f62ac294f..c131dbef5 100644 --- a/connectors/vmware/src/centreon/vmware/cmdgetmap.pm +++ b/connectors/vmware/src/centreon/vmware/cmdgetmap.pm @@ -38,23 +38,12 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null"); 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}; -} - sub run { my $self = shift; @@ -63,12 +52,16 @@ sub run { my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); return if (!defined($result)); - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("List ESX host(s):")); - + my $data = {}; foreach my $entity_view (@$result) { - $self->{manager}->{output}->output_add(long_msg => sprintf(" %s [v%s] %s", $entity_view->name, $entity_view->{'config.product.version'}, - defined($self->{vm_no}) ? '' : ':')); + my $entity_value = $entity_view->{mo_ref}->{value}; + + $data->{$entity_value} = { + name => $entity_view->{name}, + version => $entity_view->{'config.product.version'}, + vm => {} + }; + next if (defined($self->{vm_no})); my @vm_array = (); @@ -80,16 +73,15 @@ sub run { my $result2 = centreon::vmware::common::get_views($self->{connector}, \@vm_array, \@properties); return if (!defined($result2)); - my %vms = (); foreach my $vm (@$result2) { - $vms{$vm->name} = $vm->{'summary.runtime.powerState'}->val; - } - - foreach (sort keys %vms) { - $self->{manager}->{output}->output_add(long_msg => sprintf(" %s [%s]", - $_, $vms{$_})); + $data->{$entity_value}->{vm}->{$vm->{mo_ref}->{value}} = { + name => $vm->name, + power_state => $vm->{'summary.runtime.powerState'}->val, + }; } } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm b/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm index f1d860cb0..14d935bff 100644 --- a/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm @@ -38,148 +38,99 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname 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; - } - 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}; - $self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => 0); - $self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => 0); + return 0; } sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter'); my @properties = ('name', 'runtime.healthSystemRuntime.hardwareStatusInfo', 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo', 'runtime.connectionState'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); return if (!defined($result)); - if (scalar(@$result) > 1) { - $multiple = 1; - } - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All ESX health checks are ok")); - } - + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::host_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - multiple => $multiple) == 0); + my $entity_value = $entity_view->{mo_ref}->{value}; + $data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val }; + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); - my $OKCount = 0; - my $CAlertCount = 0; - my $WAlertCount = 0; my $cpuStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{cpuStatusInfo}; my $memoryStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{memoryStatusInfo}; my $storageStatusInfo = $entity_view->{'runtime.healthSystemRuntime.hardwareStatusInfo'}->{storageStatusInfo}; my $numericSensorInfo = $entity_view->{'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo'}; - $self->{manager}->{output}->output_add(long_msg => sprintf("Checking %s", $entity_view->{name})); # CPU if (defined($cpuStatusInfo)) { + $data->{$entity_value}->{cpu_info} = { ok => 0, yellow => 0, red => 0, summary_red => [], summary_yellow => [] }; foreach (@$cpuStatusInfo) { if ($_->status->key =~ /^red$/i) { - $self->{manager}->{output}->output_add(long_msg => $_->name . ": " . $_->status->summary); - $CAlertCount++; + push @{$data->{$entity_value}->{cpu_info}->{summary_red}}, { name => $_->name, summary => $_->status->summary }; + $data->{$entity_value}->{cpu_info}->{red}++; } elsif ($_->status->key =~ /^yellow$/i) { - $self->{manager}->{output}->output_add(long_msg => $_->name . ": " . $_->status->summary); - $WAlertCount++; + push @{$data->{$entity_value}->{cpu_info}->{summary_yellow}}, { name => $_->name, summary => $_->status->summary }; + $data->{$entity_value}->{cpu_info}->{yellow}++; } else { - $OKCount++; + $data->{$entity_value}->{cpu_info}->{ok}++; } } } # Memory if (defined($memoryStatusInfo)) { + $data->{$entity_value}->{memory_info} = { ok => 0, yellow => 0, red => 0, summary_red => [], summary_yellow => [] }; foreach (@$memoryStatusInfo) { if ($_->status->key =~ /^red$/i) { - $self->{manager}->{output}->output_add(long_msg => $_->name . ": " . $_->status->summary); - $CAlertCount++; + push @{$data->{$entity_value}->{memory_info}->{summary_red}}, { name => $_->name, summary => $_->status->summary }; + $data->{$entity_value}->{memory_info}->{red}++; } elsif ($_->status->key =~ /^yellow$/i) { - $self->{manager}->{output}->output_add(long_msg => $_->name . ": " . $_->status->summary); - $WAlertCount++; + push @{$data->{$entity_value}->{memory_info}->{summary_yellow}}, { name => $_->name, summary => $_->status->summary }; + $data->{$entity_value}->{memory_info}->{yellow}++; } else { - $OKCount++; + $data->{$entity_value}->{memory_info}->{ok}++; } } } # Storage if (defined($self->{storage_status}) && defined($storageStatusInfo)) { + $data->{$entity_value}->{storage_info} = { ok => 0, yellow => 0, red => 0, summary_red => [], summary_yellow => [] }; foreach (@$storageStatusInfo) { if ($_->status->key =~ /^red$/i) { - $self->{manager}->{output}->output_add(long_msg => $_->name . ": " . $_->status->summary); - $CAlertCount++; + push @{$data->{$entity_value}->{storage_info}->{summary_red}}, { name => $_->name, summary => $_->status->summary }; + $data->{$entity_value}->{storage_info}->{red}++; } elsif ($_->status->key =~ /^yellow$/i) { - $self->{manager}->{output}->output_add(long_msg => $_->name . ": " . $_->status->summary); - $WAlertCount++; + push @{$data->{$entity_value}->{storage_info}->{summary_yellow}}, { name => $_->name, summary => $_->status->summary }; + $data->{$entity_value}->{storage_info}->{yellow}++; } else { - $OKCount++; + $data->{$entity_value}->{storage_info}->{ok}++; } } } # Sensor if (defined($numericSensorInfo)) { + $data->{$entity_value}->{sensor_info} = { ok => 0, yellow => 0, red => 0, summary_red => [], summary_yellow => [] }; foreach (@$numericSensorInfo) { if ($_->healthState->key =~ /^red$/i) { - $self->{manager}->{output}->output_add(long_msg => $_->sensorType . " sensor " . $_->name . ": ".$_->healthState->summary); - $CAlertCount++; + push @{$data->{$entity_value}->{sensor_info}->{summary_red}}, { type => $_->sensorType, name => $_->name, summary => $_->healthState->summary }; + $data->{$entity_value}->{sensor_info}->{red}++; } elsif ($_->healthState->key =~ /^yellow$/i) { - $self->{manager}->{output}->output_add(long_msg => $_->sensorType . " sensor " . $_->name . ": ".$_->healthState->summary); - $WAlertCount++; + push @{$data->{$entity_value}->{sensor_info}->{summary_yellow}}, { type => $_->sensorType, name => $_->name, summary => $_->healthState->summary }; + $data->{$entity_value}->{sensor_info}->{yellow}++; } else { - $OKCount++; + $data->{$entity_value}->{sensor_info}->{ok}++; } } } - - my $exit = $self->{manager}->{perfdata}->threshold_check(value => $WAlertCount, - threshold => [ { label => 'warning', exit_litteral => 'warning' } ]); - if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $exit, - short_msg => sprintf("'%s' %s health issue(s) found", $entity_view->{name}, $WAlertCount)); - } - $exit = $self->{manager}->{perfdata}->threshold_check(value => $CAlertCount, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' } ]); - if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $exit, - short_msg => sprintf("'%s' %s health issue(s) found", $entity_view->{name}, $CAlertCount)); - } - - $self->{manager}->{output}->output_add(long_msg => sprintf("%s health checks are green", $OKCount)); - if ($multiple == 0) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("'%s' %s health checks are green", $entity_view->{name}, $OKCount)); - } - my $extra_label = ''; - $extra_label = '_' . $entity_view->{name} if ($multiple == 1); - $self->{manager}->{output}->perfdata_add(label => 'problems' . $extra_label, - value => $CAlertCount + $WAlertCount, - min => 0, max => $OKCount + $CAlertCount + $WAlertCount); } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdlimitvm.pm b/connectors/vmware/src/centreon/vmware/cmdlimitvm.pm index a495034f9..ab6eeeaa3 100644 --- a/connectors/vmware/src/centreon/vmware/cmdlimitvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdlimitvm.pm @@ -38,64 +38,16 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: vm hostname 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; - } - if (defined($options{arguments}->{cpu_limitset_status}) && - $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{cpu_limitset_status}) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for cpu limitset status '" . $options{arguments}->{cpu_limitset_status} . "'"); - return 1; - } - if (defined($options{arguments}->{memory_limitset_status}) && - $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{memory_limitset_status}) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for memory limitset status '" . $options{arguments}->{memory_limitset_status} . "'"); - return 1; - } - if (defined($options{arguments}->{disk_limitset_status}) && - $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{disk_limitset_status}) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for disk limitset status '" . $options{arguments}->{disk_limitset_status} . "'"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null"); 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}; -} - -sub display_verbose { - my ($self, %options) = @_; - - $self->{manager}->{output}->output_add(long_msg => $options{label}); - foreach my $vm (sort keys %{$options{vms}}) { - my $prefix = $vm; - if ($options{vms}->{$vm} ne '') { - $prefix .= ' [' . centreon::vmware::common::strip_cr(value => $options{vms}->{$vm}) . ']'; - } - $self->{manager}->{output}->output_add(long_msg => ' ' . $prefix); - } -} - sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter'); if (defined($self->{filter_description}) && $self->{filter_description} ne '') { $filters->{'config.annotation'} = qr/$self->{filter_description}/; @@ -112,72 +64,47 @@ sub run { my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters); return if (!defined($result)); - if (scalar(@$result) > 1) { - $multiple = 1; - } - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All Limits are ok")); - } else { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("Limits are ok")); - } - - my %cpu_limit = (); - my %memory_limit = (); - my %disk_limit = (); + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::vm_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - nocheck_ps => 1, - multiple => $multiple) == 0); - - next if (defined($self->{nopoweredon_skip}) && - centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0); + my $entity_value = $entity_view->{mo_ref}->{value}; + + $data->{$entity_value} = { + name => $entity_view->{name}, + connection_state => $entity_view->{'runtime.connectionState'}->val, + power_state => $entity_view->{'runtime.powerState'}->val, + 'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef, + 'config.cpuAllocation.limit' => -1, + 'config.memoryAllocation.limit' => -1, + 'config.storageIOAllocation.limit' => [], + }; + + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); # CPU Limit if (defined($entity_view->{'config.cpuAllocation.limit'}) && $entity_view->{'config.cpuAllocation.limit'} != -1) { - $cpu_limit{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : ''; + $data->{$entity_value}->{'config.cpuAllocation.limit'} = $entity_view->{'config.cpuAllocation.limit'}; } # Memory Limit if (defined($entity_view->{'config.memoryAllocation.limit'}) && $entity_view->{'config.memoryAllocation.limit'} != -1) { - $memory_limit{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : ''; + $data->{$entity_value}->{'config.memoryAllocation.limit'} = $entity_view->{'config.memoryAllocation.limit'}; } # Disk if (defined($self->{check_disk_limit})) { + use Data::Dumper; + print Data::Dumper::Dumper($entity_view->{'config.hardware.device'}); foreach my $device (@{$entity_view->{'config.hardware.device'}}) { if ($device->isa('VirtualDisk')) { - if (defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) { - $disk_limit{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : ''; - last; - } + if (defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) { + push @{$data->{$entity_value}->{'config.storageIOAllocation.limit'}}, { name => $device->backing->fileName, limit => $device->storageIOAllocation->limit }; + } } } - } + } } - if (scalar(keys %cpu_limit) > 0 && - !$self->{manager}->{output}->is_status(value => $self->{cpu_limitset_status}, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $self->{cpu_limitset_status}, - short_msg => sprintf('%d VM with CPU limits', scalar(keys %cpu_limit))); - $self->display_verbose(label => 'CPU limits:', vms => \%cpu_limit); - } - if (scalar(keys %memory_limit) > 0 && - !$self->{manager}->{output}->is_status(value => $self->{memory_limitset_status}, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $self->{memory_limitset_status}, - short_msg => sprintf('%d VM with memory limits', scalar(keys %memory_limit))); - $self->display_verbose(label => 'Memory limits:', vms => \%memory_limit); - } - if (scalar(keys %disk_limit) > 0 && - !$self->{manager}->{output}->is_status(value => $self->{disk_limitset_status}, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $self->{disk_limitset_status}, - short_msg => sprintf('%d VM with disk limits', scalar(keys %disk_limit))); - $self->display_verbose(label => 'Disk limits:', vms => \%disk_limit); - } + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdlistclusters.pm b/connectors/vmware/src/centreon/vmware/cmdlistclusters.pm index 9c77d3186..d9ab90e10 100644 --- a/connectors/vmware/src/centreon/vmware/cmdlistclusters.pm +++ b/connectors/vmware/src/centreon/vmware/cmdlistclusters.pm @@ -38,58 +38,27 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{cluster}) && $options{arguments}->{cluster} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: cluster cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: cluster cannot be null"); 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}; -} - sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'cluster', is_regexp => 'filter'); my @properties = ('name'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'ClusterComputeResource', properties => \@properties, filter => $filters); return if (!defined($result)); - if (!defined($self->{disco_show})) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => 'List cluster(s):'); - } + my $data = {}; foreach my $cluster (@$result) { - if (defined($self->{disco_show})) { - $self->{manager}->{output}->add_disco_entry(name => $cluster->name); - } else { - $self->{manager}->{output}->output_add(long_msg => sprintf(" %s", - $cluster->name)); - } + $data->{$cluster->{mo_ref}->{value}} = { name => $cluster->name }; } - if (defined($self->{disco_show})) { - my $stdout; - { - local *STDOUT; - $self->{manager}->{output}->{option_results}->{output_xml} = 1; - open STDOUT, '>', \$stdout; - $self->{manager}->{output}->display_disco_show(); - delete $self->{manager}->{output}->{option_results}->{output_xml}; - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => $stdout); - } - } + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdlistdatacenters.pm b/connectors/vmware/src/centreon/vmware/cmdlistdatacenters.pm index 40c0f2ff4..a17c35468 100644 --- a/connectors/vmware/src/centreon/vmware/cmdlistdatacenters.pm +++ b/connectors/vmware/src/centreon/vmware/cmdlistdatacenters.pm @@ -38,58 +38,27 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{datacenter}) && $options{arguments}->{datacenter} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: datacenter cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: datacenter cannot be null"); 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}; -} - sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'datacenter', is_regexp => 'filter'); my @properties = ('name'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datacenter', properties => \@properties, filter => $filters); return if (!defined($result)); - if (!defined($self->{disco_show})) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => 'List datacenter(s):'); - } + my $data = {}; foreach my $datacenter (@$result) { - if (defined($self->{disco_show})) { - $self->{manager}->{output}->add_disco_entry(name => $datacenter->name); - } else { - $self->{manager}->{output}->output_add(long_msg => sprintf(" %s", - $datacenter->name)); - } + $data->{$datacenter->{mo_ref}->{value}} = { name => $datacenter->{name} }; } - if (defined($self->{disco_show})) { - my $stdout; - { - local *STDOUT; - $self->{manager}->{output}->{option_results}->{output_xml} = 1; - open STDOUT, '>', \$stdout; - $self->{manager}->{output}->display_disco_show(); - delete $self->{manager}->{output}->{option_results}->{output_xml}; - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => $stdout); - } - } + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdlistdatastores.pm b/connectors/vmware/src/centreon/vmware/cmdlistdatastores.pm index 5a2e00f94..05a12c7b3 100644 --- a/connectors/vmware/src/centreon/vmware/cmdlistdatastores.pm +++ b/connectors/vmware/src/centreon/vmware/cmdlistdatastores.pm @@ -38,23 +38,12 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null"); 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}; -} - sub run { my $self = shift; @@ -65,35 +54,16 @@ sub run { my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters); return if (!defined($result)); - if (!defined($self->{disco_show})) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => 'List datastore(s):'); - } + my $data = {}; foreach my $datastore (@$result) { - if (defined($self->{disco_show})) { - $self->{manager}->{output}->add_disco_entry(name => $datastore->summary->name, - accessible => $datastore->summary->accessible, - type => $datastore->summary->type); - } else { - $self->{manager}->{output}->output_add(long_msg => sprintf(" %s [%s] [%s]", - $datastore->summary->name, - $datastore->summary->accessible, - $datastore->summary->type)); - } + $data->{$datastore->{mo_ref}->{value}} = { + name => $datastore->summary->name, + type => $datastore->summary->type, + accessible => $datastore->summary->accessible + }; } - if (defined($self->{disco_show})) { - my $stdout; - { - local *STDOUT; - $self->{manager}->{output}->{option_results}->{output_xml} = 1; - open STDOUT, '>', \$stdout; - $self->{manager}->{output}->display_disco_show(); - delete $self->{manager}->{output}->{option_results}->{output_xml}; - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => $stdout); - } - } + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdlistnichost.pm b/connectors/vmware/src/centreon/vmware/cmdlistnichost.pm index d95c4d35f..8dd883f3b 100644 --- a/connectors/vmware/src/centreon/vmware/cmdlistnichost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdlistnichost.pm @@ -38,23 +38,12 @@ sub checkArgs { my ($self, %options) = @_; if (!defined($options{arguments}->{esx_hostname}) || $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname need to be set"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname need to be set"); 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}; -} - sub run { my $self = shift; my %nic_in_vswitch = (); @@ -82,11 +71,6 @@ sub run { } } } - - if (!defined($self->{disco_show})) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => 'List nic host:'); - } my %nics = (); foreach (@{$$result[0]->{'config.network.pnic'}}) { @@ -99,33 +83,16 @@ sub run { $nics{$_->device}{down} = 1; } } - + + my $data = {}; foreach my $nic_name (sort keys %nics) { my $status = defined($nics{$nic_name}{up}) ? 'up' : 'down'; my $vswitch = defined($nics{$nic_name}{vswitch}) ? 1 : 0; - if (defined($self->{disco_show})) { - $self->{manager}->{output}->add_disco_entry(name => $nic_name, - status => $status, - vswitch => $vswitch); - } else { - $self->{manager}->{output}->output_add(long_msg => sprintf('%s [status: %s] [vswitch: %s]', - $nic_name, $status, $vswitch)); - } - } - - if (defined($self->{disco_show})) { - my $stdout; - { - local *STDOUT; - $self->{manager}->{output}->{option_results}->{output_xml} = 1; - open STDOUT, '>', \$stdout; - $self->{manager}->{output}->display_disco_show(); - delete $self->{manager}->{output}->{option_results}->{output_xml}; - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => $stdout); - } + $data->{$nic_name} = { name => $nic_name, status => $status, vswitch => $vswitch }; } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdmaintenancehost.pm b/connectors/vmware/src/centreon/vmware/cmdmaintenancehost.pm index 5f7d7781a..6afae9951 100644 --- a/connectors/vmware/src/centreon/vmware/cmdmaintenancehost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdmaintenancehost.pm @@ -38,74 +38,32 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname 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; - } - if (defined($options{arguments}->{maintenance_status}) && - $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{maintenance_status}) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for maintenance status '" . $options{arguments}->{maintenance_status} . "'"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null"); 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}; -} - sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter'); my @properties = ('name', 'runtime.inMaintenanceMode', 'runtime.connectionState'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); return if (!defined($result)); - if (scalar(@$result) > 1) { - $multiple = 1; - } - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All ESX maintenance mode are ok")); - } - + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::host_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - multiple => $multiple) == 0); - - $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' maintenance mode is %s", - $entity_view->{name}, $entity_view->{'runtime.inMaintenanceMode'})); + my $entity_value = $entity_view->{mo_ref}->{value}; + $data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val }; + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); - if ($entity_view->{'runtime.inMaintenanceMode'} =~ /$self->{maintenance_alert}/ && - !$self->{manager}->{output}->is_status(value => $self->{maintenance_status}, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $self->{maintenance_status}, - short_msg => sprintf("'%s' maintenance mode is %s", - $entity_view->{name}, $entity_view->{'runtime.inMaintenanceMode'})) - } elsif ($multiple == 0) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("'%s' maintenance mode is %s", - $entity_view->{name}, $entity_view->{'runtime.inMaintenanceMode'})) - } + $data->{$entity_value}->{inMaintenanceMode} = $entity_view->{'runtime.inMaintenanceMode'}; } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdmemhost.pm b/connectors/vmware/src/centreon/vmware/cmdmemhost.pm index baa6095c7..9aa7e9021 100644 --- a/connectors/vmware/src/centreon/vmware/cmdmemhost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdmemhost.pm @@ -45,15 +45,6 @@ sub checkArgs { return 0; } -sub initArgs { - my ($self, %options) = @_; - - foreach (keys %{$options{arguments}}) { - $self->{$_} = $options{arguments}->{$_}; - } - centreon::vmware::common::init_response(identity => $options{arguments}->{identity}); -} - sub run { my $self = shift; diff --git a/connectors/vmware/src/centreon/vmware/cmdmemvm.pm b/connectors/vmware/src/centreon/vmware/cmdmemvm.pm index 075a7b08e..a294868ec 100644 --- a/connectors/vmware/src/centreon/vmware/cmdmemvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdmemvm.pm @@ -38,57 +38,21 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: vm hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname 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; - } - if (defined($options{arguments}->{nopoweredon_status}) && - $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{nopoweredon_status}) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for nopoweredon status '" . $options{arguments}->{nopoweredon_status} . "'"); - return 1; - } - if (($options{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning})) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for warning value '" . $options{arguments}->{warning} . "'."); - return 1; - } - if (($options{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical})) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for critical value '" . $options{arguments}->{critical} . "'."); - 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}; - $self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning}); - $self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical}); + return 0; } sub run { my $self = shift; if (!($self->{connector}->{perfcounter_speriod} > 0)) { - $self->{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Can't retrieve perf counters"); + centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters"); return ; } - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter'); if (defined($self->{filter_description}) && $self->{filter_description} ne '') { $filters->{'config.annotation'} = qr/$self->{filter_description}/; @@ -113,24 +77,20 @@ sub run { skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); - if (scalar(@$result) > 1) { - $multiple = 1; - } - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All memory usages are ok")); - } + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::vm_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - power => $entity_view->{'runtime.powerState'}->val, - status => $self->{disconnect_status}, - powerstatus => $self->{nopoweredon_status}, - multiple => $multiple) == 0); my $entity_value = $entity_view->{mo_ref}->{value}; - my $memory_size = $entity_view->{'summary.config.memorySizeMB'} * 1024 * 1024; + + $data->{$entity_value} = { + name => $entity_view->{name}, + connection_state => $entity_view->{'runtime.connectionState'}->val, + power_state => $entity_view->{'runtime.powerState'}->val, + 'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef, + }; + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); + next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0); + # in KB my $mem_consumed = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"})) * 1024; my $mem_active = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.active.average'}->{'key'} . ":"})) * 1024; @@ -138,56 +98,15 @@ sub run { my $mem_ballooning = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.vmmemctl.average'}->{'key'} . ":"})) * 1024; my $mem_shared = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.shared.average'}->{'key'} . ":"})) * 1024; - my $mem_free = $memory_size - $mem_consumed; - my $prct_used = $mem_consumed * 100 / $memory_size; - my $prct_free = 100 - $prct_used; - - my $exit = $self->{manager}->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my ($total_value, $total_unit) = $self->{manager}->{perfdata}->change_bytes(value => $memory_size); - my ($used_value, $used_unit) = $self->{manager}->{perfdata}->change_bytes(value => $mem_consumed); - my ($free_value, $free_unit) = $self->{manager}->{perfdata}->change_bytes(value => $mem_free); - - my $prefix_msg = "'$entity_view->{name}'"; - if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) && - $entity_view->{'config.annotation'} ne '') { - $prefix_msg .= ' [' . centreon::vmware::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']'; - } - - $self->{manager}->{output}->output_add(long_msg => sprintf("%s Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $prefix_msg, - $total_value . " " . $total_unit, - $used_value . " " . $used_unit, $prct_used, - $free_value . " " . $free_unit, $prct_free)); - 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 Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $prefix_msg, - $total_value . " " . $total_unit, - $used_value . " " . $used_unit, $prct_used, - $free_value . " " . $free_unit, $prct_free)); - } - - my $extra_label = ''; - $extra_label = '_' . $entity_view->{name} if ($multiple == 1); - $self->{manager}->{output}->perfdata_add(label => 'used' . $extra_label, unit => 'B', - value => $mem_consumed, - warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning', total => $memory_size, cast_int => 1), - critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical', total => $memory_size, cast_int => 1), - min => 0, max => $memory_size); - $self->{manager}->{output}->perfdata_add(label => 'overhead' . $extra_label, unit => 'B', - value => $mem_overhead, - min => 0); - $self->{manager}->{output}->perfdata_add(label => 'ballooning' . $extra_label, unit => 'B', - value => $mem_ballooning, - min => 0); - $self->{manager}->{output}->perfdata_add(label => 'active' . $extra_label, unit => 'B', - value => $mem_active, - min => 0); - $self->{manager}->{output}->perfdata_add(label => 'shared' . $extra_label, unit => 'B', - value => $mem_shared, - min => 0); + $data->{$entity_value}->{'memory_size'} = $entity_view->{'summary.config.memorySizeMB'} * 1024 * 1024; + $data->{$entity_value}->{'mem.consumed.average'} = $mem_consumed; + $data->{$entity_value}->{'mem.active.average'} = $mem_active; + $data->{$entity_value}->{'mem.overhead.average'} = $mem_overhead; + $data->{$entity_value}->{'mem.vmmemctl.average'} = $mem_ballooning; + $data->{$entity_value}->{'mem.shared.average'} = $mem_shared; } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdservicehost.pm b/connectors/vmware/src/centreon/vmware/cmdservicehost.pm index 24a180931..eea7607e0 100644 --- a/connectors/vmware/src/centreon/vmware/cmdservicehost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdservicehost.pm @@ -38,33 +38,16 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname 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; - } - 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}; + return 0; } sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter'); my @properties = ('name', 'runtime.connectionState', 'runtime.inMaintenanceMode', 'configManager.serviceSystem'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); @@ -72,64 +55,43 @@ sub run { my %host_names = (); my @host_array = (); + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::host_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - multiple => $multiple) == 0); - next if (centreon::vmware::common::host_maintenance(connector => $self->{connector}, - hostname => $entity_view->{name}, - maintenance => $entity_view->{'runtime.inMaintenanceMode'}, - multiple => $multiple) == 0); + my $entity_value = $entity_view->{mo_ref}->{value}; + + $data->{$entity_value} = { name => $entity_view->{name}, + state => $entity_view->{'runtime.connectionState'}->val, + inMaintenanceMode => $entity_view->{'runtime.inMaintenanceMode'}, + services => [], + }; + + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); + next if (centreon::vmware::common::is_maintenance(maintenance => $entity_view->{'runtime.inMaintenanceMode'}) == 0); + if (defined($entity_view->{'configManager.serviceSystem'})) { push @host_array, $entity_view->{'configManager.serviceSystem'}; $host_names{$entity_view->{'configManager.serviceSystem'}->{value}} = $entity_view->{name}; } } - return if (scalar(@host_array) == 0); + if (scalar(@host_array) == 0) { + centreon::vmware::common::set_response(data => $data); + return ; + } @properties = ('serviceInfo'); my $result2 = centreon::vmware::common::get_views($self->{connector}, \@host_array, \@properties); return if (!defined($result2)); - if (scalar(@$result) > 1) { - $multiple = 1; - } - - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All ESX services are ok")); - } - foreach my $entity (@$result2) { my $hostname = $host_names{$entity->{mo_ref}->{value}}; - - my @services_ok = (); - my @services_problem = (); + foreach my $service (@{$entity->{serviceInfo}->{service}}) { - next if (defined($self->{filter_services}) && $self->{filter_services} ne '' && - $service->{key} !~ /$self->{filter_services}/); - - if ($service->{policy} =~ /^on|automatic/i && !$service->{running}) { - push @services_problem, $service->{key}; - } else { - push @services_ok, $service->{key}; - } - } - - $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' services [ ok : %s ] [ nok : %s ]", $hostname, - join(', ', @services_ok), join(', ', @services_problem))); - my $status = 'OK'; - $status = 'CRITICAL' if (scalar(@services_problem) > 0); - if ($multiple == 0 || - !$self->{manager}->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $status, - short_msg => sprintf("'%s' services [ ok : %s ] [ nok : %s ]", $hostname, - join(', ', @services_ok), join(', ', @services_problem))); + push @{$data->{$entity->{mo_ref}->{value}}->{services}}, { label => $service->{label}, policy => $service->{policy}, running => $service->{running} }; } } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdsnapshotvm.pm b/connectors/vmware/src/centreon/vmware/cmdsnapshotvm.pm index 43add42a1..b86b4e890 100644 --- a/connectors/vmware/src/centreon/vmware/cmdsnapshotvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdsnapshotvm.pm @@ -38,49 +38,16 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: vm hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname 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', 'critical')) { - 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', 'critical')) { - $self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label}); - } + return 0; } sub run { my $self = shift; - if ($self->{connector}->{module_date_parse_loaded} == 0) { - $self->{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Need to install Date::Parse CPAN Module"); - return ; - } - - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter'); if (defined($self->{filter_description}) && $self->{filter_description} ne '') { $filters->{'config.annotation'} = qr/$self->{filter_description}/; @@ -99,79 +66,32 @@ sub run { my %vm_consolidate = (); my %vm_errors = (warning => {}, critical => {}); - if (scalar(@$result) > 1) { - $multiple = 1; - } - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All snapshots are ok")); - } else { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("Snapshot(s) OK")); - } + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::vm_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - nocheck_ps => 1, - multiple => $multiple) == 0); - - next if (defined($self->{nopoweredon_skip}) && - centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0); - + my $entity_value = $entity_view->{mo_ref}->{value}; + + $data->{$entity_value} = { + name => $entity_view->{name}, + connection_state => $entity_view->{'runtime.connectionState'}->val, + power_state => $entity_view->{'runtime.powerState'}->val, + 'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef, + snapshosts => [], + }; + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); + if (defined($self->{check_consolidation}) && defined($entity_view->{'runtime.consolidationNeeded'}) && $entity_view->{'runtime.consolidationNeeded'} =~ /^true|1$/i) { - $vm_consolidate{$entity_view->{name}} = 1; + $data->{$entity_value}->{consolidation_needed} = 1; } next if (!defined($entity_view->{'snapshot.rootSnapshotList'})); foreach my $snapshot (@{$entity_view->{'snapshot.rootSnapshotList'}}) { # 2012-09-21T14:16:17.540469Z - my $create_time = Date::Parse::str2time($snapshot->createTime); - if (!defined($create_time)) { - $self->{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Can't Parse date '" . $snapshot->createTime . "' for vm '" . $entity_view->{name} . "'"); - next; - } - - my $diff_time = time() - $create_time; - my $days = int($diff_time / 60 / 60 / 24); - my $exit = $self->{manager}->{perfdata}->threshold_check(value => $diff_time, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - my $prefix_msg = "'$entity_view->{name}'"; - if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) && - $entity_view->{'config.annotation'} ne '') { - $prefix_msg .= ' [' . centreon::vmware::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']'; - } - if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $vm_errors{$exit}->{$entity_view->{name}} = 1; - $self->{manager}->{output}->output_add(long_msg => "$prefix_msg snapshot create time: " . $snapshot->createTime); - } + push @{$data->{$entity_value}->{snapshosts}}, { name => $snapshot->name, description => $snapshot->description, create_time => $snapshot->createTime }; } } - - $self->{manager}->{output}->perfdata_add(label => 'num_warning', - value => scalar(keys %{$vm_errors{warning}}), - min => 0); - $self->{manager}->{output}->perfdata_add(label => 'num_critical', - value => scalar(keys %{$vm_errors{critical}}), - min => 0); - if (scalar(keys %{$vm_errors{warning}}) > 0) { - $self->{manager}->{output}->output_add(severity => 'WARNING', - short_msg => sprintf('Snapshots for VM older than %d days: [%s]', ($self->{warning} / 86400), - join('] [', sort keys %{$vm_errors{warning}}))); - } - if (scalar(keys %{$vm_errors{critical}}) > 0) { - $self->{manager}->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf('Snapshots for VM older than %d days: [%s]', ($self->{critical} / 86400), - join('] [', sort keys %{$vm_errors{critical}}))); - } - if (scalar(keys %vm_consolidate) > 0) { - $self->{manager}->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf('VMs need consolidation: [%s]', - join('] [', sort keys %vm_consolidate))); - } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdstatushost.pm b/connectors/vmware/src/centreon/vmware/cmdstatushost.pm index 6031c5f85..c2094f67f 100644 --- a/connectors/vmware/src/centreon/vmware/cmdstatushost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdstatushost.pm @@ -38,75 +38,31 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname 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; - } - 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}; + return 0; } sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter'); my @properties = ('name', 'summary.overallStatus', 'runtime.connectionState'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); return if (!defined($result)); - - if (scalar(@$result) > 1) { - $multiple = 1; - } - my %overallStatus = ( - 'gray' => 'status is unknown', - 'green' => 'is OK', - 'red' => 'has a problem', - 'yellow' => 'might have a problem', - ); - my %overallStatusReturn = ( - 'gray' => 'UNKNOWN', - 'green' => 'OK', - 'red' => 'CRITICAL', - 'yellow' => 'WARNING' - ); - - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All ESX are ok")); + + my $data = {}; + foreach my $entity_view (@$result) { + my $entity_value = $entity_view->{mo_ref}->{value}; + $data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val }; + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); + + $data->{$entity_value}->{overall_status} = $entity_view->{'summary.overallStatus'}->val; } - foreach my $entity_view (@$result) { - next if (centreon::vmware::common::host_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - multiple => $multiple) == 0); - - my $status_esx = $entity_view->{'summary.overallStatus'}->val; - $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' %s", $entity_view->{name}, $overallStatus{$status_esx})); - - if ($multiple == 0 || - !$self->{manager}->{output}->is_status(value => $overallStatusReturn{$status_esx}, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $overallStatusReturn{$status_esx}, - short_msg => sprintf("'%s' %s", $entity_view->{name}, $overallStatus{$status_esx})); - } - } + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdstatusvm.pm b/connectors/vmware/src/centreon/vmware/cmdstatusvm.pm index ea07c3b45..47d2d81c9 100644 --- a/connectors/vmware/src/centreon/vmware/cmdstatusvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdstatusvm.pm @@ -38,82 +38,44 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: vm hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname 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; - } - 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}; + return 0; } sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter'); if (defined($self->{filter_description}) && $self->{filter_description} ne '') { $filters->{'config.annotation'} = qr/$self->{filter_description}/; } - my @properties = ('name', 'summary.overallStatus', 'runtime.connectionState'); + my @properties = ('name', 'summary.overallStatus', 'runtime.connectionState', 'runtime.powerState'); if (defined($self->{display_description})) { push @properties, 'config.annotation'; } my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters); return if (!defined($result)); - if (scalar(@$result) > 1) { - $multiple = 1; - } - my %overallStatus = ( - 'gray' => 'status is unknown', - 'green' => 'is OK', - 'red' => 'has a problem', - 'yellow' => 'might have a problem', - ); - my %overallStatusReturn = ( - 'gray' => 'UNKNOWN', - 'green' => 'OK', - 'red' => 'CRITICAL', - 'yellow' => 'WARNING' - ); + my $data = {}; + foreach my $entity_view (@$result) { + my $entity_value = $entity_view->{mo_ref}->{value}; - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All virtual machines are ok")); + $data->{$entity_value} = { + name => $entity_view->{name}, + connection_state => $entity_view->{'runtime.connectionState'}->val, + power_state => $entity_view->{'runtime.powerState'}->val, + 'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef, + }; + + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); + + $data->{$entity_value}->{overall_status} = $entity_view->{'summary.overallStatus'}->val; } - foreach my $entity_view (@$result) { - next if (centreon::vmware::common::vm_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - nocheck_ps => 1, - multiple => $multiple) == 0); - - my $status_vm = $entity_view->{'summary.overallStatus'}->val; - $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' %s", $entity_view->{name}, $overallStatus{$status_vm})); - - if ($multiple == 0 || - !$self->{manager}->{output}->is_status(value => $overallStatusReturn{$status_vm}, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $overallStatusReturn{$status_vm}, - short_msg => sprintf("'%s' %s", $entity_view->{name}, $overallStatus{$status_vm})); - } - } + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdswaphost.pm b/connectors/vmware/src/centreon/vmware/cmdswaphost.pm index 1956635e1..b2fd7dbc4 100644 --- a/connectors/vmware/src/centreon/vmware/cmdswaphost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdswaphost.pm @@ -38,59 +38,26 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname 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; - } - if (($options{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning})) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for warning value '" . $options{arguments}->{warning} . "'."); - return 1; - } - if (($options{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical})) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for critical value '" . $options{arguments}->{critical} . "'."); - 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}; - $self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning}); - $self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical}); -} - sub run { my $self = shift; if (!($self->{connector}->{perfcounter_speriod} > 0)) { - $self->{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Can't retrieve perf counters"); + centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters"); return ; } - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter'); my @properties = ('name', 'runtime.connectionState'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); return if (!defined($result)); - if (scalar(@$result) > 1) { - $multiple = 1; - } my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector}, $result, [{'label' => 'mem.swapinRate.average', 'instances' => ['']}, @@ -100,54 +67,21 @@ sub run { skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All swap rate usages are ok")); - } + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::host_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - multiple => $multiple) == 0); - my $entity_value = $entity_view->{mo_ref}->{value}; + my $entity_value = $entity_view->{mo_ref}->{value}; + $data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val }; + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); # KBps my $swap_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"})) * 1024; my $swap_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"})) * 1024; - my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $swap_in, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $swap_out, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - my ($swap_in_value, $swap_in_unit) = $self->{manager}->{perfdata}->change_bytes(value => $swap_in); - my ($swap_out_value, $swap_out_unit) = $self->{manager}->{perfdata}->change_bytes(value => $swap_out); - - $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' Swap In: %s Swap Out: %s", - $entity_view->{name}, - $swap_in_value . " " . $swap_in_unit . "/s", - $swap_out_value . " " . $swap_out_unit . "/s")); - 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' Swap In: %s Swap Out: %s", - $entity_view->{name}, - $swap_in_value . " " . $swap_in_unit . "/s", - $swap_out_value . " " . $swap_out_unit . "/s")); - } - - my $extra_label = ''; - $extra_label = '_' . $entity_view->{name} if ($multiple == 1); - $self->{manager}->{output}->perfdata_add(label => 'swap_in' . $extra_label, unit => 'B/s', - value => $swap_in, - warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - $self->{manager}->{output}->perfdata_add(label => 'swap_out' . $extra_label, unit => 'B/s', - value => $swap_out, - warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + $data->{$entity_value}->{'mem.swapinRate.average'} = $swap_in; + $data->{$entity_value}->{'mem.swapoutRate.average'} = $swap_out; } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdswapvm.pm b/connectors/vmware/src/centreon/vmware/cmdswapvm.pm index e20af75f9..9ff70ad67 100644 --- a/connectors/vmware/src/centreon/vmware/cmdswapvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdswapvm.pm @@ -38,57 +38,21 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: vm hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname 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; - } - if (defined($options{arguments}->{nopoweredon_status}) && - $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{nopoweredon_status}) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for nopoweredon status '" . $options{arguments}->{nopoweredon_status} . "'"); - return 1; - } - if (($options{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning})) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for warning value '" . $options{arguments}->{warning} . "'."); - return 1; - } - if (($options{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical})) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for critical value '" . $options{arguments}->{critical} . "'."); - 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}; - $self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning}); - $self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical}); + return 0; } sub run { my $self = shift; if (!($self->{connector}->{perfcounter_speriod} > 0)) { - $self->{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Can't retrieve perf counters"); + centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters"); return ; } - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter'); if (defined($self->{filter_description}) && $self->{filter_description} ne '') { $filters->{'config.annotation'} = qr/$self->{filter_description}/; @@ -111,66 +75,29 @@ sub run { skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); - if (scalar(@$result) > 1) { - $multiple = 1; - } - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All swap rate usages are ok")); - } - + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::vm_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - power => $entity_view->{'runtime.powerState'}->val, - status => $self->{disconnect_status}, - powerstatus => $self->{nopoweredon_status}, - multiple => $multiple) == 0); - my $entity_value = $entity_view->{mo_ref}->{value}; + my $entity_value = $entity_view->{mo_ref}->{value}; + + $data->{$entity_value} = { + name => $entity_view->{name}, + connection_state => $entity_view->{'runtime.connectionState'}->val, + power_state => $entity_view->{'runtime.powerState'}->val, + 'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef, + }; + + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); + next if (centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0); # KBps my $swap_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"})) * 1024; my $swap_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"})) * 1024; - my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $swap_in, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $swap_out, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - my ($swap_in_value, $swap_in_unit) = $self->{manager}->{perfdata}->change_bytes(value => $swap_in); - my ($swap_out_value, $swap_out_unit) = $self->{manager}->{perfdata}->change_bytes(value => $swap_out); - - my $prefix_msg = "'$entity_view->{name}'"; - if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) && - $entity_view->{'config.annotation'} ne '') { - $prefix_msg .= ' [' . centreon::vmware::common::strip_cr(value => $entity_view->{'config.annotation'}) . ']'; - } - - $self->{manager}->{output}->output_add(long_msg => sprintf("%s Swap In: %s Swap Out: %s", - $prefix_msg, - $swap_in_value . " " . $swap_in_unit . "/s", - $swap_out_value . " " . $swap_out_unit . "/s")); - 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 Swap In: %s Swap Out: %s", - $prefix_msg, - $swap_in_value . " " . $swap_in_unit . "/s", - $swap_out_value . " " . $swap_out_unit . "/s")); - } - - my $extra_label = ''; - $extra_label = '_' . $entity_view->{name} if ($multiple == 1); - $self->{manager}->{output}->perfdata_add(label => 'swap_in' . $extra_label, unit => 'B/s', - value => $swap_in, - warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - $self->{manager}->{output}->perfdata_add(label => 'swap_out' . $extra_label, unit => 'B/s', - value => $swap_out, - warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + $data->{$entity_value}->{'mem.swapinRate.average'} = $swap_in; + $data->{$entity_value}->{'mem.swapoutRate.average'} = $swap_out; } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdthinprovisioningvm.pm b/connectors/vmware/src/centreon/vmware/cmdthinprovisioningvm.pm index 17ca1a231..5b60267b7 100644 --- a/connectors/vmware/src/centreon/vmware/cmdthinprovisioningvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdthinprovisioningvm.pm @@ -38,55 +38,16 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: vm hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null"); return 1; } - if (defined($options{arguments}->{thinprovisioning_status}) && $options{arguments}->{thinprovisioning_status} ne '') { - my ($entry, $status) = split /,/, $options{arguments}->{thinprovisioning_status}; - if ($entry !~ /^(notactive|active)$/) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Wrong thinprovisioning-status option. Can only be 'active' or 'noactive'. Not: '" . $entry . "'."); - return 1; - } - if ($options{manager}->{output}->is_litteral_status(status => $status) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Wrong thinprovisioning-status option. Not a good status: '" . $status . "'."); - 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}; -} - -sub display_verbose { - my ($self, %options) = @_; - - foreach my $vm (sort keys %{$options{vms}}) { - my $prefix = $vm; - if ($options{vms}->{$vm}->{description} ne '') { - $prefix .= ' [' . centreon::vmware::common::strip_cr(value => $options{vms}->{$vm}->{description}) . ']'; - } - $self->{manager}->{output}->output_add(long_msg => $prefix); - foreach my $disk (sort keys %{$options{vms}->{$vm}->{disks}}) { - $self->{manager}->{output}->output_add(long_msg => ' ' . $disk); - } - } -} - sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter'); if (defined($self->{filter_description}) && $self->{filter_description} ne '') { $filters->{'config.annotation'} = qr/$self->{filter_description}/; @@ -100,55 +61,28 @@ sub run { my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters); return if (!defined($result)); - if (scalar(@$result) > 1) { - $multiple = 1; - } - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All thinprovisoning virtualdisks are ok.")); - } else { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("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; - my ($entry, $status); - if (defined($self->{thinprovisioning_status}) && $self->{thinprovisioning_status} ne '') { - ($entry, $status) = split /,/, $self->{thinprovisioning_status}; - } - + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::vm_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - nocheck_ps => 1, - multiple => $multiple) == 0); - - next if (defined($self->{nopoweredon_skip}) && - centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0); + my $entity_value = $entity_view->{mo_ref}->{value}; + + $data->{$entity_value} = { + name => $entity_view->{name}, + connection_state => $entity_view->{'runtime.connectionState'}->val, + power_state => $entity_view->{'runtime.powerState'}->val, + 'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef, + disks => [], + }; + + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); foreach (@{$entity_view->{'config.hardware.device'}}) { if ($_->isa('VirtualDisk')) { - if (defined($entry) && $_->backing->thinProvisioned =~ /$maps_match{$entry}->{regexp}/) { - $num++; - if (!defined($disks_vm->{$entity_view->{name}})) { - $disks_vm->{$entity_view->{name}} = { disks => {}, description => (defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : '') }; - } - $disks_vm->{$entity_view->{name}}->{disks}->{$_->backing->fileName} = 1; - } + push @{$data->{$entity_value}->{disks}}, { thin_provisioned => $_->backing->thinProvisioned, name => $_->backing->fileName }; } } } - if ($num > 0) { - $self->{manager}->{output}->output_add(severity => $status, - short_msg => sprintf('%d %s', $num, $maps_match{$entry}->{output})); - $self->display_verbose(vms => $disks_vm); - } + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdtimehost.pm b/connectors/vmware/src/centreon/vmware/cmdtimehost.pm index d6f7014a7..c9559e978 100644 --- a/connectors/vmware/src/centreon/vmware/cmdtimehost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdtimehost.pm @@ -38,70 +38,29 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname 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_time', 'critical_time')) { - 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_time', 'critical_time')) { - $self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label}); - } + return 0; } sub run { my $self = shift; - if ($self->{connector}->{module_date_parse_loaded} == 0) { - $self->{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Need to install Date::Parse CPAN Module"); - return ; - } - - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter'); my @properties = ('name', 'configManager.dateTimeSystem', 'runtime.connectionState'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); return if (!defined($result)); - if (scalar(@$result) > 1) { - $multiple = 1; - } - - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => 'All Times are ok'); - } + my $data = {}; my @host_array = (); foreach my $entity_view (@$result) { - next if (centreon::vmware::common::host_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->{val}, - status => $self->{disconnect_status}, - multiple => $multiple) == 0); + my $entity_value = $entity_view->{mo_ref}->{value}; + $data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val }; + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); + if (defined($entity_view->{'configManager.dateTimeSystem'})) { push @host_array, $entity_view->{'configManager.dateTimeSystem'}; } @@ -111,39 +70,17 @@ sub run { my $result2 = centreon::vmware::common::get_views($self->{connector}, \@host_array, \@properties); return if (!defined($result2)); - my $localtime = time(); foreach my $entity_view (@$result) { my $host_dts_value = $entity_view->{'configManager.dateTimeSystem'}->{value}; foreach my $host_dts_view (@$result2) { - if ($host_dts_view->{mo_ref}->{value} eq $host_dts_value) { - my $time = $host_dts_view->QueryDateTime(); - my $timestamp = Date::Parse::str2time($time); - my $offset = $localtime - $timestamp; - - my $exit = $self->{manager}->{perfdata}->threshold_check(value => $offset, threshold => [ { label => 'critical_time', exit_litteral => 'critical' }, { label => 'warning_time', exit_litteral => 'warning' } ]); - $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' date: %s, offset: %s second(s)", - $entity_view->{name}, - $time, $offset)); - 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' Time offset %d second(s) : %s", - $entity_view->{name}, $offset, - $time)); - } - - my $extra_label = ''; - $extra_label = '_' . $entity_view->{name} if ($multiple == 1); - $self->{manager}->{output}->perfdata_add(label => 'offset' . $extra_label, unit => 's', - value => $offset, - warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning_time'), - critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical_time'), - min => 0); - + if ($host_dts_view->{mo_ref}->{value} eq $host_dts_value) { + $data->{$entity_view->{mo_ref}->{value}}->{current_time} = $host_dts_view->QueryDateTime(); last; } } } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdtoolsvm.pm b/connectors/vmware/src/centreon/vmware/cmdtoolsvm.pm index fe9e7b80b..28d122a21 100644 --- a/connectors/vmware/src/centreon/vmware/cmdtoolsvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdtoolsvm.pm @@ -38,45 +38,11 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{vm_hostname}) && $options{arguments}->{vm_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: vm hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: vm hostname cannot be null"); return 1; } - if (defined($options{arguments}->{tools_notinstalled_status}) && - $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{tools_notinstalled_status}) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for tools notinstalled status '" . $options{arguments}->{tools_notinstalled_status} . "'"); - return 1; - } - if (defined($options{arguments}->{tools_notrunning_status}) && - $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{tools_notrunning_status}) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for tools notrunning status '" . $options{arguments}->{tools_notrunning_status} . "'"); - return 1; - } - if (defined($options{arguments}->{tools_notupd2date_status}) && - $options{manager}->{output}->is_litteral_status(status => $options{arguments}->{tools_notupd2date_status}) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for tools notupd2date status '" . $options{arguments}->{tools_notupd2date_status} . "'"); - 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; - } - 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}; + return 0; } sub display_verbose { @@ -95,7 +61,6 @@ sub display_verbose { sub run { my $self = shift; - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'vm_hostname', is_regexp => 'filter'); if (defined($self->{filter_description}) && $self->{filter_description} ne '') { $filters->{'config.annotation'} = qr/$self->{filter_description}/; @@ -109,71 +74,22 @@ sub run { my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'VirtualMachine', properties => \@properties, filter => $filters); return if (!defined($result)); - if (scalar(@$result) > 1) { - $multiple = 1; - } - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All VMTools are OK")); - } else { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("VMTools are OK")); - } - my %not_installed = (); - my %not_running = (); - my %not_up2date = (); + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::vm_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - nocheck_ps => 1, - multiple => $multiple) == 0); - - next if (defined($self->{nopoweredon_skip}) && - centreon::vmware::common::is_running(power => $entity_view->{'runtime.powerState'}->val) == 0); - - my $tools_status = lc($entity_view->{'summary.guest.toolsStatus'}->val); - if ($tools_status eq 'toolsnotinstalled') { - $not_installed{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : ''; - } elsif ($tools_status eq 'toolsnotrunning') { - $not_running{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : ''; - } elsif ($tools_status eq 'toolsold') { - $not_up2date{$entity_view->{name}} = defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : ''; - } + my $entity_value = $entity_view->{mo_ref}->{value}; + + $data->{$entity_value} = { + name => $entity_view->{name}, + connection_state => $entity_view->{'runtime.connectionState'}->val, + power_state => $entity_view->{'runtime.powerState'}->val, + 'config.annotation' => defined($entity_view->{'config.annotation'}) ? $entity_view->{'config.annotation'} : undef, + }; + + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); + $data->{$entity_value}->{tools_status} = defined($entity_view->{'summary.guest.toolsStatus'}) ? $entity_view->{'summary.guest.toolsStatus'}->val : undef; } - if (scalar(keys %not_up2date) > 0 && - !$self->{manager}->{output}->is_status(value => $self->{tools_notupd2date_status}, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $self->{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); - } - if (scalar(keys %not_running) > 0 && - !$self->{manager}->{output}->is_status(value => $self->{tools_notrunning_status}, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $self->{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); - } - if (scalar(keys %not_installed) > 0 && - !$self->{manager}->{output}->is_status(value => $self->{tools_notinstalled_status}, compare => 'ok', litteral => 1)) { - $self->{manager}->{output}->output_add(severity => $self->{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); - } - - if ($multiple == 1) { - my $total = scalar(keys %not_up2date) + scalar(keys %not_running) + scalar(keys %not_installed); - $self->{manager}->{output}->perfdata_add(label => 'not_updated', - value => scalar(keys %not_up2date), - min => 0, max => $total); - $self->{manager}->{output}->perfdata_add(label => 'not_running', - value => scalar(keys %not_running), - min => 0, max => $total); - $self->{manager}->{output}->perfdata_add(label => 'not_installed', - value => scalar(keys %not_installed), - min => 0, max => $total); - } + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmduptimehost.pm b/connectors/vmware/src/centreon/vmware/cmduptimehost.pm index 321795c68..e19697fd2 100644 --- a/connectors/vmware/src/centreon/vmware/cmduptimehost.pm +++ b/connectors/vmware/src/centreon/vmware/cmduptimehost.pm @@ -38,101 +38,30 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: esx hostname cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname 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; - } - if (($options{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning})) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for warning value '" . $options{arguments}->{warning} . "'."); - return 1; - } - if (($options{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical})) == 0) { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: wrong value for critical value '" . $options{arguments}->{critical} . "'."); - 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}; - $self->{manager}->{perfdata}->threshold_validate(label => 'warning', value => $options{arguments}->{warning}); - $self->{manager}->{perfdata}->threshold_validate(label => 'critical', value => $options{arguments}->{critical}); -} - sub run { my $self = shift; - - if ($self->{connector}->{module_date_parse_loaded} == 0) { - $self->{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Need to install Date::Parse Perl Module."); - return ; - } - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter'); my @properties = ('name', 'runtime.bootTime', 'runtime.connectionState'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); return if (!defined($result)); - if (scalar(@$result) > 1) { - $multiple = 1; - } - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All uptimes are ok")); - } - + my $data = {}; foreach my $entity_view (@$result) { - next if (centreon::vmware::common::host_state(connector => $self->{connector}, - hostname => $entity_view->{name}, - state => $entity_view->{'runtime.connectionState'}->val, - status => $self->{disconnect_status}, - multiple => $multiple) == 0); + my $entity_value = $entity_view->{mo_ref}->{value}; + $data->{$entity_value} = { name => $entity_view->{name}, state => $entity_view->{'runtime.connectionState'}->val }; + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); - my $create_time = Date::Parse::str2time($entity_view->{'runtime.bootTime'}); - if (!defined($create_time)) { - $self->{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Can't Parse date '" . $entity_view->{'runtime.bootTime'} . "'"); - return ; - } - - my $diff_time = time() - $create_time; - my $days = int($diff_time / 60 / 60 / 24); - - my $exit = $self->{manager}->{perfdata}->threshold_check(value => $diff_time, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' Uptime: %s day(s)", - $entity_view->{name}, - $days)); - 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' Uptime: %s day(s)", - $entity_view->{name}, - $days)); - } - - my $extra_label = ''; - $extra_label = '_' . $entity_view->{name} if ($multiple == 1); - $self->{manager}->{output}->perfdata_add(label => 'uptime' . $extra_label, unit => 's', - value => $diff_time, - warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + $data->{$entity_value}->{boot_time} = $entity_view->{'runtime.bootTime'}; } + + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/cmdvmoperationcluster.pm b/connectors/vmware/src/centreon/vmware/cmdvmoperationcluster.pm index 28909261b..2e51a0c55 100644 --- a/connectors/vmware/src/centreon/vmware/cmdvmoperationcluster.pm +++ b/connectors/vmware/src/centreon/vmware/cmdvmoperationcluster.pm @@ -23,8 +23,6 @@ use base qw(centreon::vmware::cmdbase); use strict; use warnings; use centreon::vmware::common; -use centreon::plugins::statefile; -use Digest::MD5 qw(md5_hex); sub new { my ($class, %options) = @_; @@ -40,60 +38,25 @@ sub checkArgs { my ($self, %options) = @_; if (defined($options{arguments}->{cluster}) && $options{arguments}->{cluster} eq "") { - $options{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Argument error: cluster cannot be null"); + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: cluster cannot be null"); return 1; } - foreach my $label (('warning_svmotion', 'critical_svmotion', 'warning_vmotion', 'critical_vmotion', - 'warning_clone', 'critical_clone')) { - 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_svmotion', 'critical_svmotion', 'warning_vmotion', 'critical_vmotion', - 'warning_clone', 'critical_clone')) { - $self->{manager}->{perfdata}->threshold_validate(label => $label, value => $options{arguments}->{$label}); - } -} - sub run { my $self = shift; - - $self->{statefile_cache} = centreon::plugins::statefile->new(output => $self->{manager}->{output}); - $self->{statefile_cache}->read(statefile_dir => $self->{connector}->{retention_dir}, - statefile => "cache_vmware_connector_" . $self->{connector}->{whoaim} . "_" . $self->{commandName} . "_" . (defined($self->{cluster}) ? md5_hex($self->{cluster}) : md5_hex('.*')), - statefile_suffix => '', - no_quit => 1); - return if ($self->{statefile_cache}->error() == 1); if (!($self->{connector}->{perfcounter_speriod} > 0)) { - $self->{manager}->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Can't retrieve perf counters"); + centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters"); return ; } - my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'cluster', is_regexp => 'filter'); my @properties = ('name'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'ClusterComputeResource', properties => \@properties, filter => $filters); return if (!defined($result)); - - if (scalar(@$result) > 1) { - $multiple = 1; - } + my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector}, $result, [{'label' => 'vmop.numVMotion.latest', 'instances' => ['']}, @@ -103,71 +66,17 @@ sub run { sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); - - if ($multiple == 1) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("All virtual machine operations are ok")); - } - - my $new_datas = {}; - my $old_datas = {}; - my $checked = 0; + + my $data = {}; foreach my $entity_view (@$result) { my $entity_value = $entity_view->{mo_ref}->{value}; - my $name = centreon::vmware::common::substitute_name(value => $entity_view->{name}); - my %values = (); - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - - foreach my $label (('Clone', 'VMotion', 'SVMotion')) { - $new_datas->{$label . '_' . $entity_value} = $values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'vmop.num' . $label . '.latest'}->{key} . ":"}; - $old_datas->{$label . '_' . $entity_value} = $self->{statefile_cache}->get(name => $label . '_' . $entity_value); - - next if (!defined($old_datas->{$label . '_' . $entity_value})); - $checked = 1; - - if ($old_datas->{$label . '_' . $entity_value} > $new_datas->{$label . '_' . $entity_value}) { - $old_datas->{$label . '_' . $entity_value} = 0; - } - - my $diff = $new_datas->{$label . '_' . $entity_value} - $old_datas->{$label . '_' . $entity_value}; - $long_msg .= $long_msg_append . $label . ' ' . $diff; - $long_msg_append = ', '; - - my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $diff, threshold => [ { label => 'critical_' . lc($label), exit_litteral => 'critical' }, { label => 'warning_' . lc($label), exit_litteral => 'warning' } ]); - push @exits, $exit2; - if ($multiple == 0 || !$self->{manager}->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $label . ' ' . $diff; - $short_msg_append = ', '; - } - - my $extra_label = ''; - $extra_label = '_' . $name if ($multiple == 1); - $self->{manager}->{output}->perfdata_add(label => lc($label) . $extra_label, - value => $diff, - warning => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'warning_' . lc($label)), - critical => $self->{manager}->{perfdata}->get_perfdata_for_output(label => 'critical_' . lc($label)), - min => 0); - } - - $self->{manager}->{output}->output_add(long_msg => "Cluster '" . $name . "' vm operations: $long_msg"); - my $exit = $self->{manager}->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{manager}->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{manager}->{output}->output_add(severity => $exit, - short_msg => "Cluster '" . $name . "' vm operations: $short_msg" - ); - } - - if ($multiple == 0) { - $self->{manager}->{output}->output_add(short_msg => "Cluster '" . $name . "' vm operations: $long_msg"); - } + $data->{$entity_value} = { name => centreon::vmware::common::substitute_name(value => $entity_view->{name}) }; + $data->{$entity_value}->{'vmop.numVMotion.latest'} = $values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'vmop.numVMotion.latest'}->{key} . ":"}; + $data->{$entity_value}->{'vmop.numSVMotion.latest'} = $values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'vmop.numSVMotion.latest'}->{key} . ":"}; + $data->{$entity_value}->{'vmop.numClone.latest'} = $values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'vmop.numClone.latest'}->{key} . ":"}; } - if ($checked == 0) { - $self->{manager}->{output}->output_add(severity => 'OK', - short_msg => sprintf("Buffer creation")); - } - $self->{statefile_cache}->write(data => $new_datas); + centreon::vmware::common::set_response(data => $data); } 1; diff --git a/connectors/vmware/src/centreon/vmware/common.pm b/connectors/vmware/src/centreon/vmware/common.pm index 976f2e3be..dffaa2ae2 100644 --- a/connectors/vmware/src/centreon/vmware/common.pm +++ b/connectors/vmware/src/centreon/vmware/common.pm @@ -590,80 +590,12 @@ sub is_running { return 1; } -sub datastore_state { - my (%options) = @_; - my $status = defined($options{status}) ? $options{status} : $options{connector}->{datastore_state_error}; - - if ($options{state} !~ /^true|1$/) { - my $output = "Datastore '" . $options{name} . "' not accessible. Current connection state: '$options{state}'."; - if ($options{multiple} == 0 || - !$manager_display->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) { - $manager_display->{output}->output_add(severity => $status, - short_msg => $output); - } - return 0; - } - - return 1; -} - -sub vm_state { - my (%options) = @_; - my $status = defined($options{status}) ? $options{status} : $options{connector}->{host_state_error}; - my $power_status = defined($options{powerstatus}) ? $options{powerstatus} : $options{connector}->{vm_state_error}; - - if ($options{state} !~ /^connected$/i) { - my $output = "VM '" . $options{hostname} . "' not connected. Current Connection State: '$options{state}'."; - if ($options{multiple} == 0 || - !$manager_display->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) { - $manager_display->{output}->output_add(severity => $status, - short_msg => $output); - } - return 0; - } - - if (!defined($options{nocheck_ps}) && $options{power} !~ /^poweredOn$/i) { - my $output = "VM '" . $options{hostname} . "' not running. Current Power State: '$options{power}'."; - if ($options{multiple} == 0 || - !$manager_display->{output}->is_status(value => $power_status, compare => 'ok', litteral => 1)) { - $manager_display->{output}->output_add(severity => $power_status, - short_msg => $output); - } - return 0; - } - - return 1; -} - -sub host_state { - my (%options) = @_; - my $status = defined($options{status}) ? $options{status} : $options{connector}->{host_state_error}; - - if ($options{state} !~ /^connected$/i) { - my $output = "Host '" . $options{hostname} . "' not connected. Current Connection State: '$options{state}'."; - if ($options{multiple} == 0 || - !$manager_display->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) { - $manager_display->{output}->output_add(severity => $status, - short_msg => $output); - } - return 0; - } - - return 1; -} - -sub host_maintenance { +sub is_maintenance { my (%options) = @_; if ($options{maintenance} =~ /^true|1$/) { - my $output = "Host '" . $options{hostname} . "' is in maintenance mode."; - if ($options{multiple} == 0) { - $manager_display->{output}->output_add(severity => 'OK', - short_msg => $output); - } return 0; } - return 1; } diff --git a/connectors/vmware/src/centreon/vmware/connector.pm b/connectors/vmware/src/centreon/vmware/connector.pm index 76448ff19..b0503b973 100644 --- a/connectors/vmware/src/centreon/vmware/connector.pm +++ b/connectors/vmware/src/centreon/vmware/connector.pm @@ -55,7 +55,6 @@ sub new { $connector->{modules_registry} = $options{modules_registry}; $connector->{logger} = $options{logger}; $connector->{whoaim} = $options{name}; - $connector->{module_date_parse_loaded} = $options{module_date_parse_loaded}; $connector->{config_child_timeout} = $options{config}->{timeout}; $connector->{config_stop_child_timeout} = $options{config}->{timeout_kill}; $connector->{config_vsphere_session_heartbeat} = $options{config}->{refresh_keeper_session}; @@ -63,10 +62,6 @@ sub new { $connector->{config_vsphere_url} = $options{config}->{vsphere_server}->{$options{name}}->{url}; $connector->{config_vsphere_user} = $options{config}->{vsphere_server}->{$options{name}}->{username}; $connector->{config_vsphere_pass} = $options{config}->{vsphere_server}->{$options{name}}->{password}; - $connector->{retention_dir} = $options{config}->{retention_dir}; - $connector->{datastore_state_error} = $options{config}->{datastore_state_error}; - $connector->{vm_state_error} = $options{config}->{vm_state_error}; - $connector->{host_state_error} = $options{config}->{host_state_error}; return $connector; }