diff --git a/plugins/check_memory.cpp b/plugins/check_memory.cpp index e8cb8aae9..4b71517a4 100644 --- a/plugins/check_memory.cpp +++ b/plugins/check_memory.cpp @@ -164,7 +164,7 @@ static int printOutput(printInfoStruct& printInfo) if (l_Debug) std::wcout << L"Constructing output string" << '\n'; - state state; + state state = OK; std::wcout << L"MEMORY "; @@ -175,16 +175,13 @@ static int printOutput(printInfoStruct& printInfo) else currentValue = printInfo.tRam - printInfo.aRam; - if (printInfo.warn.rend(currentValue, printInfo.tRam)) { + if (printInfo.warn.rend(currentValue, printInfo.tRam)) state = WARNING; - std::wcout << L"WARNING"; - } else if (printInfo.crit.rend(currentValue, printInfo.tRam)) { + + if (printInfo.crit.rend(currentValue, printInfo.tRam)) state = CRITICAL; - std::wcout << L"CRITICAL"; - } else { - state = OK; - std::wcout << L"OK"; - } + + std::wcout << stateToString(state); if (!printInfo.showUsed) std::wcout << " - " << printInfo.percentFree << L"% free"; diff --git a/plugins/check_swap.cpp b/plugins/check_swap.cpp index 7f6db013a..906a1017d 100644 --- a/plugins/check_swap.cpp +++ b/plugins/check_swap.cpp @@ -194,16 +194,13 @@ static int printOutput(printInfoStruct& printInfo) else currentValue = printInfo.tSwap - printInfo.aSwap; - if (printInfo.warn.rend(currentValue, printInfo.tSwap)) { + if (printInfo.warn.rend(currentValue, printInfo.tSwap)) state = WARNING; - std::wcout << L"WARNING - "; - } else if (printInfo.crit.rend(currentValue, printInfo.tSwap)) { + + if (printInfo.crit.rend(currentValue, printInfo.tSwap)) state = CRITICAL; - std::wcout << L"CRITICAL - "; - } else { - state = OK; - std::wcout << L"OK - "; - } + + std::wcout << stateToString(state) << " "; if (!printInfo.showUsed) std::wcout << printInfo.percentFree << L"% free "; diff --git a/plugins/thresholds.cpp b/plugins/thresholds.cpp index f32e6d360..acc2bcafb 100644 --- a/plugins/thresholds.cpp +++ b/plugins/thresholds.cpp @@ -281,4 +281,13 @@ std::wstring formatErrorInfo(unsigned long err) { } return out.str(); +} + +std::wstring stateToString(const state& state) { + switch (state) { + case OK: return L"OK"; + case WARNING: return L"WARNING"; + case CRITICAL: return L"CRITICAL"; + default: return L"UNKNOWN"; + } } \ No newline at end of file diff --git a/plugins/thresholds.hpp b/plugins/thresholds.hpp index 8348306f2..e7d77f745 100644 --- a/plugins/thresholds.hpp +++ b/plugins/thresholds.hpp @@ -76,4 +76,6 @@ std::wstring TunitStr(const Tunit&); void printErrorInfo(unsigned long err = 0); std::wstring formatErrorInfo(unsigned long err); +std::wstring stateToString(const state&); + #endif /* THRESHOLDS_H */