diff --git a/connectors/vmware/centreon_esx_client.pl b/connectors/vmware/centreon_esx_client.pl index 640045bb6..acefa1625 100644 --- a/connectors/vmware/centreon_esx_client.pl +++ b/connectors/vmware/centreon_esx_client.pl @@ -40,6 +40,7 @@ GetOptions( "e|esx-host=s" => \$OPTION{'esx-host'}, "vm=s" => \$OPTION{'vm'}, + "filter-datastores=s" => \$OPTION{'filter-datastores'}, "light-perfdata" => \$OPTION{'light-perfdata'}, "datastore=s" => \$OPTION{'datastore'}, "nic=s" => \$OPTION{'nic'}, @@ -121,6 +122,7 @@ sub print_usage () { print " -e (--esx-host) Esx Host to check (required)\n"; print " -w (--warning) Warning Threshold in ms (latency) (default none)\n"; print " -c (--critical) Critical Threshold in ms (latency) (default none)\n"; + print " --filter-datastores Datastores to verify (separated by coma)\n"; print "\n"; print "'countvmhost':\n"; print " -e (--esx-host) Esx Host to check (required)\n"; @@ -314,11 +316,14 @@ sub datastoreshost_check_arg { if (!defined($OPTION{'critical'})) { $OPTION{'critical'} = ''; } + if (!defined($OPTION{'filter-datastores'})) { + $OPTION{'filter-datastores'} = ''; + } return 0; } sub datastoreshost_get_str { - return "datastoreshost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'}; + return "datastoreshost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'} . "|" . $OPTION{'filter-datastores'}; } sub memhost_check_arg { diff --git a/connectors/vmware/lib/command-datastoreshost.pm b/connectors/vmware/lib/command-datastoreshost.pm index b230422ae..b936e4fd0 100644 --- a/connectors/vmware/lib/command-datastoreshost.pm +++ b/connectors/vmware/lib/command-datastoreshost.pm @@ -23,11 +23,20 @@ sub datastoreshost_compute_args { my $lhost = $_[0]; my $warn = (defined($_[1]) ? $_[1] : ''); my $crit = (defined($_[2]) ? $_[2] : ''); - return ($lhost, $warn, $crit); + my $filter_ds = (defined($_[3]) ? $_[3] : ''); + return ($lhost, $warn, $crit, $filter_ds); } sub datastoreshost_do { - my ($lhost, $warn, $crit) = @_; + my ($lhost, $warn, $crit, $filter_ds) = @_; + + my %valid_ds = (); + my $filter_ok = 0; + if ($filter_ds ne '') { + foreach (split /,/, $filter_ds) { + $valid_ds{$_} = 1; + } + } if (!($perfcounter_speriod > 0)) { my $status |= $MYERRORS_MASK{'UNKNOWN'}; print_response($ERRORS{$MYERRORS{$status}} . "|Can't retrieve perf counters.\n"); @@ -71,6 +80,9 @@ sub datastoreshost_do { my $output_critical_append = ''; my $perfdata = ''; foreach (keys %uuid_list) { + if ($filter_ds ne '' and !defined($valid_ds{$uuid_list{$_}})) { + next; + } if (defined($values->{$perfcounter_cache{'datastore.totalReadLatency.average'}->{'key'} . ":" . $_}) and defined($values->{$perfcounter_cache{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $_})) { my $read_counter = simplify_number(convert_number($values->{$perfcounter_cache{'datastore.totalReadLatency.average'}->{'key'} . ":" . $_}[0])); @@ -94,10 +106,16 @@ sub datastoreshost_do { $status |= $MYERRORS_MASK{'WARNING'}; } + $filter_ok = 1; $perfdata .= " 'trl_" . $uuid_list{$_} . "'=" . $read_counter . "ms 'twl_" . $uuid_list{$_} . "'=" . $write_counter . 'ms'; } } + if ($filter_ds ne '' and $filter_ok == 0) { + my $status |= $MYERRORS_MASK{'UNKNOWN'}; + print_response($ERRORS{$MYERRORS{$status}} . "|Datastore names in filter are unknown.\n"); + return ; + } if ($output_critical ne "") { $output .= $output_append . "CRITICAL - Latency counter: $output_critical"; $output_append = ". ";