]> granicus.if.org Git - icinga2/commitdiff
Fix check_swap percentage calculation
authorMichael Insel <michael@insel.email>
Fri, 8 Feb 2019 15:57:19 +0000 (16:57 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 11 Feb 2019 12:16:55 +0000 (13:16 +0100)
This fixes the check_swap percentage calculation. When the pagefile is
turned off the available swap and total swap are 0 which leads to a
wrong calculation and misformated output.

refs #6913

(cherry picked from commit 4961e9ba62eebcfc1cf22e1840b289e4eab067d2)

plugins/check_swap.cpp

index 302f20b46a7c029b672e696e4474c3249ad04885..7579073b789d540fec7c6c2a3545a4eb8219625a 100644 (file)
@@ -229,7 +229,10 @@ static int check_swap(printInfoStruct& printInfo)
                printInfo.aSwap += round(pageFiles.at(i).availableSpwap / pow(1024.0, printInfo.unit));
        }
 
-       printInfo.percentFree = 100.0 * printInfo.aSwap / printInfo.tSwap;
+       if (printInfo.aSwap > 0 && printInfo.tSwap > 0)
+               printInfo.percentFree = 100.0 * printInfo.aSwap / printInfo.tSwap;
+       else
+               printInfo.percentFree = 0;
 
        return -1;
 }