MCPcopy Create free account
hub / github.com/Icinga/icinga2 / printOutput

Function printOutput

plugins/check_disk.cpp:328–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

326}
327
328static int printOutput(printInfoStruct& printInfo, std::vector<drive>& vDrives)
329{
330 if (l_Debug)
331 std::wcout << "Constructing output string\n";
332
333 std::vector<std::wstring> wsDrives, wsPerf;
334 std::wstring unit = BunitStr(printInfo.unit);
335
336 state state = OK;
337
338 std::wstring output = L"DISK OK - free space:";
339
340 if (printInfo.showUsed)
341 output = L"DISK OK - used space:";
342
343 double tCap = 0, tFree = 0, tUsed = 0;
344
345 for (std::vector<drive>::iterator it = vDrives.begin(); it != vDrives.end(); it++) {
346 tCap += it->cap;
347 tFree += it->free;
348 tUsed += it->used;
349
350 if (printInfo.showUsed) {
351 wsDrives.push_back(it->name + L" " + removeZero(it->used) + L" " + unit + L" (" +
352 removeZero(std::round(it->used / it->cap * 100.0)) + L"%); ");
353
354 wsPerf.push_back(L" " + it->name + L"=" + removeZero(it->used) + unit + L";" +
355 printInfo.warn.pString(it->cap) + L";" + printInfo.crit.pString(it->cap) + L";0;"
356 + removeZero(it->cap));
357
358 if (printInfo.crit.set && !printInfo.crit.rend(it->used, it->cap))
359 state = CRITICAL;
360
361 if (state == OK && printInfo.warn.set && !printInfo.warn.rend(it->used, it->cap))
362 state = WARNING;
363 } else {
364 wsDrives.push_back(it->name + L" " + removeZero(it->free) + L" " + unit + L" (" +
365 removeZero(std::round(it->free / it->cap * 100.0)) + L"%); ");
366
367 wsPerf.push_back(L" '" + it->name + L"'=" + removeZero(it->free) + unit + L";" +
368 printInfo.warn.pString(it->cap) + L";" + printInfo.crit.pString(it->cap) + L";0;"
369 + removeZero(it->cap));
370
371 if (printInfo.crit.rend(it->free, it->cap))
372 state = CRITICAL;
373
374 if (state == OK && printInfo.warn.rend(it->free, it->cap))
375 state = WARNING;
376 }
377 }
378
379 if (state == WARNING) {
380 output = L"DISK WARNING - free space:";
381
382 if (printInfo.showUsed)
383 output = L"DISK WARNING - used space:";
384 }
385

Callers 1

wmainFunction · 0.70

Calls 8

BunitStrFunction · 0.85
removeZeroFunction · 0.85
push_backMethod · 0.80
pStringMethod · 0.80
rendMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected