[host] Filtrer les datastores


git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@44 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
Quentin Garnier 2012-10-08 13:53:28 +00:00
parent 8aa332fa74
commit e77a7a7529
2 changed files with 26 additions and 3 deletions

View File

@ -40,6 +40,7 @@ GetOptions(
"e|esx-host=s" => \$OPTION{'esx-host'}, "e|esx-host=s" => \$OPTION{'esx-host'},
"vm=s" => \$OPTION{'vm'}, "vm=s" => \$OPTION{'vm'},
"filter-datastores=s" => \$OPTION{'filter-datastores'},
"light-perfdata" => \$OPTION{'light-perfdata'}, "light-perfdata" => \$OPTION{'light-perfdata'},
"datastore=s" => \$OPTION{'datastore'}, "datastore=s" => \$OPTION{'datastore'},
"nic=s" => \$OPTION{'nic'}, "nic=s" => \$OPTION{'nic'},
@ -121,6 +122,7 @@ sub print_usage () {
print " -e (--esx-host) Esx Host to check (required)\n"; print " -e (--esx-host) Esx Host to check (required)\n";
print " -w (--warning) Warning Threshold in ms (latency) (default none)\n"; print " -w (--warning) Warning Threshold in ms (latency) (default none)\n";
print " -c (--critical) Critical 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 "\n";
print "'countvmhost':\n"; print "'countvmhost':\n";
print " -e (--esx-host) Esx Host to check (required)\n"; print " -e (--esx-host) Esx Host to check (required)\n";
@ -314,11 +316,14 @@ sub datastoreshost_check_arg {
if (!defined($OPTION{'critical'})) { if (!defined($OPTION{'critical'})) {
$OPTION{'critical'} = ''; $OPTION{'critical'} = '';
} }
if (!defined($OPTION{'filter-datastores'})) {
$OPTION{'filter-datastores'} = '';
}
return 0; return 0;
} }
sub datastoreshost_get_str { 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 { sub memhost_check_arg {

View File

@ -23,11 +23,20 @@ sub datastoreshost_compute_args {
my $lhost = $_[0]; my $lhost = $_[0];
my $warn = (defined($_[1]) ? $_[1] : ''); my $warn = (defined($_[1]) ? $_[1] : '');
my $crit = (defined($_[2]) ? $_[2] : ''); my $crit = (defined($_[2]) ? $_[2] : '');
return ($lhost, $warn, $crit); my $filter_ds = (defined($_[3]) ? $_[3] : '');
return ($lhost, $warn, $crit, $filter_ds);
} }
sub datastoreshost_do { 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)) { if (!($perfcounter_speriod > 0)) {
my $status |= $MYERRORS_MASK{'UNKNOWN'}; my $status |= $MYERRORS_MASK{'UNKNOWN'};
print_response($ERRORS{$MYERRORS{$status}} . "|Can't retrieve perf counters.\n"); print_response($ERRORS{$MYERRORS{$status}} . "|Can't retrieve perf counters.\n");
@ -71,6 +80,9 @@ sub datastoreshost_do {
my $output_critical_append = ''; my $output_critical_append = '';
my $perfdata = ''; my $perfdata = '';
foreach (keys %uuid_list) { 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 if (defined($values->{$perfcounter_cache{'datastore.totalReadLatency.average'}->{'key'} . ":" . $_}) and
defined($values->{$perfcounter_cache{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $_})) { defined($values->{$perfcounter_cache{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $_})) {
my $read_counter = simplify_number(convert_number($values->{$perfcounter_cache{'datastore.totalReadLatency.average'}->{'key'} . ":" . $_}[0])); 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'}; $status |= $MYERRORS_MASK{'WARNING'};
} }
$filter_ok = 1;
$perfdata .= " 'trl_" . $uuid_list{$_} . "'=" . $read_counter . "ms 'twl_" . $uuid_list{$_} . "'=" . $write_counter . 'ms'; $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 "") { if ($output_critical ne "") {
$output .= $output_append . "CRITICAL - Latency counter: $output_critical"; $output .= $output_append . "CRITICAL - Latency counter: $output_critical";
$output_append = ". "; $output_append = ". ";