From bac04ff4bd48c1add54483e56b4f6df358f1ed2b Mon Sep 17 00:00:00 2001 From: "Brian R. Becker" Date: Sat, 27 Jan 2018 00:28:27 -0800 Subject: [PATCH 1/2] vmwarevSphereHealthCheck.pl: Fix divide by zero crash if filesystem is not mounted on a VM. --- perl/vmwarevSphereHealthCheck.pl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/perl/vmwarevSphereHealthCheck.pl b/perl/vmwarevSphereHealthCheck.pl index 0f86dd29..f5a28a50 100755 --- a/perl/vmwarevSphereHealthCheck.pl +++ b/perl/vmwarevSphereHealthCheck.pl @@ -1402,8 +1402,15 @@ sub printVMSummary { my $vm_disk_path = $disk->diskPath; my $vm_disk_free = prettyPrintData($disk->freeSpace,'B'); my $vm_disk_cap = prettyPrintData($disk->capacity,'B'); - my $vm_perc_free = &restrict_num_decimal_digits((($disk->freeSpace / $disk->capacity) * 100),2); - my $perc_string = getColor($vm_perc_free); + my ($vm_perc_free, $perc_string) = (); + # If the disk is not mounted by the VM, it will return a zero size and capacity, leading to divide by zero. + if ($disk->capacity != 0) { + $vm_perc_free = &restrict_num_decimal_digits((($disk->freeSpace / $disk->capacity) * 100),2); + $perc_string = getColor($vm_perc_free); + } else { + $vm_perc_free = "NaN"; + $perc_string = "NaN %"; + } $disk_string .= "$perc_string
$vm_disk_path$vm_disk_free$vm_disk_cap
"; } $vmstorageString .= $disk_string; From 06433c4c695cbd962902df74dbf25c5f9d91db3d Mon Sep 17 00:00:00 2001 From: "Brian R. Becker" Date: Fri, 23 Feb 2018 13:49:33 -0800 Subject: [PATCH 2/2] vmwarevSphereHealthCheck.pl: Make comment clearer. --- perl/vmwarevSphereHealthCheck.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perl/vmwarevSphereHealthCheck.pl b/perl/vmwarevSphereHealthCheck.pl index f5a28a50..916bf088 100755 --- a/perl/vmwarevSphereHealthCheck.pl +++ b/perl/vmwarevSphereHealthCheck.pl @@ -1403,7 +1403,7 @@ sub printVMSummary { my $vm_disk_free = prettyPrintData($disk->freeSpace,'B'); my $vm_disk_cap = prettyPrintData($disk->capacity,'B'); my ($vm_perc_free, $perc_string) = (); - # If the disk is not mounted by the VM, it will return a zero size and capacity, leading to divide by zero. + # If the disk is not mounted by the VM, it will show a zero capacity, leading to divide by zero crash when calculating the percent free. if ($disk->capacity != 0) { $vm_perc_free = &restrict_num_decimal_digits((($disk->freeSpace / $disk->capacity) * 100),2); $perc_string = getColor($vm_perc_free);