Skip to content

Commit c4c9fa4

Browse files
c0xcrhagman
authored andcommitted
Return WARNING/CRITICAL in maintenance mode only
Using the "maintwarn" option, the script would return with exit code 1, even if the system was not in maintenance mode. Without that option, the script would fail because $addopts is undefined. A workaround is to use -o "". Alternatively, // '' could be added to line 512.
1 parent 572d9b3 commit c4c9fa4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

check_vmware_api.pl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,13 +2273,18 @@ sub host_runtime_info
22732273
elsif ($subcommand eq "MAINTENANCE")
22742274
{
22752275
my %host_maintenance_state = (0 => "no", 1 => "yes");
2276-
$output = "maintenance=" . $host_maintenance_state{$runtime->inMaintenanceMode};
2276+
my $state = $runtime->inMaintenanceMode;
2277+
$output = "maintenance=" . $host_maintenance_state{$state};
22772278
$res = OK;
2278-
if ($addopts eq "maintwarn") {
2279-
$res = WARNING;
2280-
}
2281-
elsif ($addopts eq "maintcrit") {
2282-
$res = CRITICAL;
2279+
if ($state) {
2280+
if (!defined($addopts)) {
2281+
}
2282+
elsif ($addopts eq "maintwarn") {
2283+
$res = WARNING;
2284+
}
2285+
elsif ($addopts eq "maintcrit") {
2286+
$res = CRITICAL;
2287+
}
22832288
}
22842289
}
22852290
elsif (($subcommand eq "LIST") || ($subcommand eq "LISTVM"))

0 commit comments

Comments
 (0)