]> granicus.if.org Git - icinga2/commitdiff
Refactor code
authorJean Flach <jean-marcel.flach@icinga.com>
Mon, 24 Jul 2017 07:36:39 +0000 (09:36 +0200)
committerJean Flach <jean-marcel.flach@netways.de>
Mon, 24 Jul 2017 07:53:25 +0000 (09:53 +0200)
refs #5421

plugins/check_disk.cpp

index ce989099c29eddd88801084ace3efde2323f606f..9cfe80b4cf878b8b260deeb1c6c85bbdef4b49fd 100644 (file)
@@ -185,10 +185,7 @@ static INT parseArguments(INT ac, WCHAR **av, po::variables_map& vm, printInfoSt
                        printInfo.unit = BunitB;
        }
 
-       if (vm.count("show-used"))
-               printInfo.showUsed = true;
-       else
-               printInfo.showUsed = false;
+       printInfo.showUsed = vm.count("show-used");
 
        if (vm.count("debug"))
                debug = TRUE;
@@ -208,9 +205,8 @@ static INT printOutput(printInfoStruct& printInfo, std::vector<drive>& vDrives)
 
        std::wstring output = L"DISK OK - free space:";
 
-       if (printInfo.showUsed) {
+       if (printInfo.showUsed)
                output = L"DISK OK - used space:";
-       }
        
        double tCap = 0, tFree = 0, tUsed = 0;
 
@@ -267,14 +263,15 @@ static INT printOutput(printInfoStruct& printInfo, std::vector<drive>& vDrives)
        std::wcout << output;
 
        if (vDrives.size() > 1) {
-               if (printInfo.showUsed)
-                       std::wcout << "Total " << tUsed << unit << " (" << removeZero(std::round(tUsed / tCap * 100.0)) << "%); ";
-
-               std::wcout << "Total " << tFree << unit << " (" << removeZero(std::round(tFree / tCap * 100.0)) << "%); ";
+               if (printInfo.showUsed) {
+                       std::wcout << "Total " << (printInfo.showUsed ? tUsed : tFree) << unit
+                           << " (" << removeZero(std::round(tUsed / tCap * 100.0)) << "%); ";
+               }
        }
 
        for (std::vector<std::wstring>::const_iterator it = wsDrives.begin(); it != wsDrives.end(); it++)
                std::wcout << *it;
+
        std::wcout << "|";
 
        for (std::vector<std::wstring>::const_iterator it = wsPerf.begin(); it != wsPerf.end(); it++)
@@ -433,7 +430,7 @@ static BOOL getDriveSpaceValues(drive& drive, const Bunit& unit)
 
        if (debug)
                std::wcout << "\tAfter conversion: " << drive.free << '\n' 
-               << "\tused: " << tempUsed.QuadPart << '\n';
+                   << "\tused: " << tempUsed.QuadPart << '\n';
 
        drive.used = round((tempUsed.QuadPart / pow(1024.0, unit)));