| 188 | } |
| 189 | |
| 190 | static int printOutput(printInfoStruct& printInfo, response& response) |
| 191 | { |
| 192 | if (l_Debug) |
| 193 | std::wcout << L"Constructing output string" << '\n'; |
| 194 | |
| 195 | state state = OK; |
| 196 | |
| 197 | double plp = ((double)response.dropped / printInfo.num) * 100.0; |
| 198 | |
| 199 | if (printInfo.warn.rend(response.avg) || printInfo.wpl.rend(plp)) |
| 200 | state = WARNING; |
| 201 | |
| 202 | if (printInfo.crit.rend(response.avg) || printInfo.cpl.rend(plp)) |
| 203 | state = CRITICAL; |
| 204 | |
| 205 | std::wstringstream perf; |
| 206 | perf << L"rta=" << response.avg << L"ms;" << printInfo.warn.pString() << L";" |
| 207 | << printInfo.crit.pString() << L";0;" << " pl=" << removeZero(plp) << "%;" |
| 208 | << printInfo.wpl.pString() << ";" << printInfo.cpl.pString() << ";0;100"; |
| 209 | |
| 210 | if (response.dropped == printInfo.num) { |
| 211 | std::wcout << L"PING CRITICAL ALL CONNECTIONS DROPPED | " << perf.str() << '\n'; |
| 212 | return 2; |
| 213 | } |
| 214 | |
| 215 | std::wcout << L"PING "; |
| 216 | |
| 217 | switch (state) { |
| 218 | case OK: |
| 219 | std::wcout << L"OK"; |
| 220 | break; |
| 221 | case WARNING: |
| 222 | std::wcout << L"WARNING"; |
| 223 | break; |
| 224 | case CRITICAL: |
| 225 | std::wcout << L"CRITICAL"; |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | std::wcout << L" RTA: " << response.avg << L"ms Packet loss: " << removeZero(plp) << "% | " << perf.str() << '\n'; |
| 230 | |
| 231 | return state; |
| 232 | } |
| 233 | |
| 234 | static bool resolveHostname(const std::wstring& hostname, bool ipv6, std::wstring& ipaddr) |
| 235 | { |
no test coverage detected