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

Function printOutput

plugins/check_network.cpp:139–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139static int printOutput(printInfoStruct& printInfo, const std::vector<nInterface>& vInterfaces, const std::map<std::wstring, std::wstring>& mapNames)
140{
141 if (l_Debug)
142 std::wcout << L"Constructing output string" << '\n';
143
144 long tIn = 0, tOut = 0;
145 std::wstringstream tss;
146 state state = OK;
147
148 std::map<std::wstring, std::wstring>::const_iterator mapIt;
149 std::wstring wsFriendlyName;
150
151 for (std::vector<nInterface>::const_iterator it = vInterfaces.begin(); it != vInterfaces.end(); ++it) {
152 tIn += it->BytesInSec;
153 tOut += it->BytesOutSec;
154 if (l_Debug)
155 std::wcout << "Getting friendly name of " << it->name << '\n';
156 mapIt = mapNames.find(it->name);
157 if (mapIt != mapNames.end()) {
158 if (l_Debug)
159 std::wcout << "\tIs " << mapIt->second << '\n';
160 wsFriendlyName = mapIt->second;
161 } else {
162 if (l_Debug)
163 std::wcout << "\tNo friendly name found, using adapter name\n";
164 wsFriendlyName = it->name;
165 }
166 if (wsFriendlyName.find(L"isatap") != std::wstring::npos && l_NoISATAP) {
167 if (l_Debug)
168 std::wcout << "\tSkipping isatap interface " << wsFriendlyName << "\n";
169 continue;
170 } else {
171 boost::algorithm::replace_all(wsFriendlyName, "'", "''");
172 tss << L"'" << wsFriendlyName << L"_in'=" << it->BytesInSec << L"B '" << wsFriendlyName << L"_out'=" << it->BytesOutSec << L"B ";
173 }
174 }
175
176 if (printInfo.warn.rend(tIn + tOut))
177 state = WARNING;
178 if (printInfo.crit.rend(tIn + tOut))
179 state = CRITICAL;
180
181 std::wcout << "NETWORK ";
182
183 switch (state) {
184 case OK:
185 std::wcout << L"OK";
186 break;
187 case WARNING:
188 std::wcout << L"WARNING";
189 break;
190 case CRITICAL:
191 std::wcout << L"CRITICAL";
192 break;
193 }
194
195 std::wcout << " " << tIn + tOut << L"B/s | "
196 << L"'network'=" << tIn + tOut << L"B;" << printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";" << L"0; "

Callers 1

wmainFunction · 0.70

Calls 5

findMethod · 0.80
rendMethod · 0.80
pStringMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected