mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-29 08:34:46 +02:00
Add filter regexp for 'datastoreshost' command
git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@73 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
7edf8e502f
commit
38307dfcca
@ -29,7 +29,7 @@ my %OPTION = (
|
||||
on => undef,
|
||||
units => undef,
|
||||
free => undef,
|
||||
filter => undef
|
||||
filter => undef,
|
||||
);
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
@ -50,6 +50,7 @@ GetOptions(
|
||||
"units=s" => \$OPTION{units},
|
||||
"light-perfdata" => \$OPTION{'light-perfdata'},
|
||||
"datastore=s" => \$OPTION{datastore},
|
||||
|
||||
"nic=s" => \$OPTION{nic},
|
||||
|
||||
"older=i" => \$OPTION{older},
|
||||
@ -144,7 +145,8 @@ 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 " --datastore Datastores to check (can use a regexp with --filter)\n";
|
||||
print " --filter Use regexp for --datastore option (can check multiples datastores at once)\n";
|
||||
print "\n";
|
||||
print "'countvmhost':\n";
|
||||
print " -e (--esx-host) Esx Host to check (required)\n";
|
||||
@ -398,15 +400,20 @@ sub datastoreshost_check_arg {
|
||||
if (!defined($OPTION{critical})) {
|
||||
$OPTION{critical} = '';
|
||||
}
|
||||
if (!defined($OPTION{'filter-datastores'})) {
|
||||
$OPTION{'filter-datastores'} = '';
|
||||
if (!defined($OPTION{datastore})) {
|
||||
$OPTION{datastore} = '';
|
||||
}
|
||||
if (defined($OPTION{filter})) {
|
||||
$OPTION{filter} = 1;
|
||||
} else {
|
||||
$OPTION{filter} = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub datastoreshost_get_str {
|
||||
return join($separatorin,
|
||||
('datastoreshost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{warning}, $OPTION{critical} , $OPTION{'filter-datastores'}));
|
||||
('datastoreshost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{warning}, $OPTION{critical} , $OPTION{datastore}, $OPTION{filter}));
|
||||
}
|
||||
|
||||
sub memhost_check_arg {
|
||||
|
@ -50,19 +50,15 @@ sub initArgs {
|
||||
$self->{lhost} = $_[0];
|
||||
$self->{warn} = (defined($_[1]) ? $_[1] : '');
|
||||
$self->{crit} = (defined($_[2]) ? $_[2] : '');
|
||||
$self->{filter_ds} = (defined($_[3]) ? $_[3] : '');
|
||||
$self->{ds} = (defined($_[3]) ? $_[3] : '');
|
||||
$self->{filter} = (defined($_[4]) && $_[4] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my %valid_ds = ();
|
||||
my $filter_ok = 0;
|
||||
if ($self->{filter_ds} ne '') {
|
||||
foreach (split /,/, $self->{filter_ds}) {
|
||||
$valid_ds{$_} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!($self->{obj_esxd}->{perfcounter_speriod} > 0)) {
|
||||
my $status = centreon::esxd::common::errors_mask(0, 'UNKNOWN');
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|Can't retrieve perf counters.\n");
|
||||
@ -111,8 +107,12 @@ sub run {
|
||||
my $output_critical_append = '';
|
||||
my $perfdata = '';
|
||||
foreach (keys %uuid_list) {
|
||||
if ($self->{filter_ds} ne '' and !defined($valid_ds{$uuid_list{$_}})) {
|
||||
if ($self->{ds} ne '') {
|
||||
if ($self->{filter} == 0 && $uuid_list{$_} !~ /^\Q$self->{ds}\E$/) {
|
||||
next;
|
||||
} elsif ($self->{filter} == 1 && $uuid_list{$_} !~ /$self->{ds}/) {
|
||||
next;
|
||||
}
|
||||
}
|
||||
if (defined($values->{$self->{obj_esxd}->{perfcounter_cache}->{'datastore.totalReadLatency.average'}->{'key'} . ":" . $_}) and
|
||||
defined($values->{$self->{obj_esxd}->{perfcounter_cache}->{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $_})) {
|
||||
@ -142,9 +142,9 @@ sub run {
|
||||
}
|
||||
}
|
||||
|
||||
if ($self->{filter_ds} ne '' and $filter_ok == 0) {
|
||||
if ($self->{ds} ne '' and $filter_ok == 0) {
|
||||
$status = centreon::esxd::common::errors_mask(0, 'UNKNOWN');
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status). "|Datastore names in filter are unknown.\n");
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status). "|Can't get a datastore with the filter '$self->{ds}'.\n");
|
||||
return ;
|
||||
}
|
||||
if ($output_critical ne "") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user