Merge pull request #6412 from Icinga/fix/plugin-output

Fix output formatting in windows plugins
This commit is contained in:
Michael Friedrich 2018-06-26 09:54:43 +02:00 committed by GitHub
commit 73f69e89d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 4 deletions

View File

@ -189,7 +189,7 @@ static int printOutput(printInfoStruct& printInfo)
std::wcout << "| 'memory'=" << currentValue << BunitStr(printInfo.unit) << L";"
<< printInfo.warn.pString(printInfo.tRam) << L";" << printInfo.crit.pString(printInfo.tRam)
<< L";0;" << printInfo.tRam;
<< L";0;" << printInfo.tRam << '\n';
return state;
}

View File

@ -264,7 +264,7 @@ static bool resolveHostname(const std::wstring& hostname, bool ipv6, std::wstrin
DWORD ret = GetAddrInfoW(hostname.c_str(), NULL, &hints, &result);
if (ret) {
std::cout << "Failed to resolve hostname. Winsock Error Code: " << ret << '\n';
std::wcout << L"Failed to resolve hostname. Error " << ret << L": " << formatErrorInfo(ret) << L"\n";
return false;
}

View File

@ -224,6 +224,25 @@ void printErrorInfo(unsigned long err)
if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&mBuf, 0, NULL))
std::wcout << "Failed to format error message, last error was: " << err << '\n';
else
else {
boost::trim_right(std::wstring(mBuf));
std::wcout << mBuf << std::endl;
}
}
std::wstring formatErrorInfo(unsigned long err) {
std::wostringstream out;
if (!err)
err = GetLastError();
LPWSTR mBuf = NULL;
if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&mBuf, 0, NULL))
out << "Failed to format error message, last error was: " << err;
else {
std::wstring tempOut = std::wstring(mBuf);
boost::trim_right(tempOut);
out << tempOut;
}
return out.str();
}

View File

@ -73,5 +73,6 @@ Tunit parseTUnit(const std::wstring&);
std::wstring TunitStr(const Tunit&);
void printErrorInfo(unsigned long err = 0);
std::wstring formatErrorInfo(unsigned long err);
#endif /* THRESHOLDS_H */