mirror of https://github.com/Icinga/icinga2.git
Fix wrong UOM in check_uptime windows plugin
This fixes the usage of unvalid UOM in the check_uptime windows plugin. The performance data will now provided in seconds.
This commit is contained in:
parent
ed1e45cff9
commit
5dc900369d
|
@ -33,6 +33,7 @@ struct printInfoStruct
|
|||
threshold warn;
|
||||
threshold crit;
|
||||
long long time;
|
||||
long long timeInSeconds;
|
||||
Tunit unit;
|
||||
};
|
||||
|
||||
|
@ -166,19 +167,19 @@ static int printOutput(printInfoStruct& printInfo)
|
|||
|
||||
switch (state) {
|
||||
case OK:
|
||||
std::wcout << L"UPTIME OK " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.time
|
||||
<< TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";"
|
||||
<< printInfo.crit.pString() << L";0;" << '\n';
|
||||
std::wcout << L"UPTIME OK " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.timeInSeconds
|
||||
<< "s" << L";" << printInfo.warn.toSeconds(printInfo.unit).pString() << L";"
|
||||
<< printInfo.crit.toSeconds(printInfo.unit).pString() << L";0;" << '\n';
|
||||
break;
|
||||
case WARNING:
|
||||
std::wcout << L"UPTIME WARNING " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.time
|
||||
<< TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";"
|
||||
<< printInfo.crit.pString() << L";0;" << '\n';
|
||||
std::wcout << L"UPTIME WARNING " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.timeInSeconds
|
||||
<< "s" << L";" << printInfo.warn.toSeconds(printInfo.unit).pString() << L";"
|
||||
<< printInfo.crit.toSeconds(printInfo.unit).pString() << L";0;" << '\n';
|
||||
break;
|
||||
case CRITICAL:
|
||||
std::wcout << L"UPTIME CRITICAL " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.time
|
||||
<< TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";"
|
||||
<< printInfo.crit.pString() << L";0;" << '\n';
|
||||
std::wcout << L"UPTIME CRITICAL " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.timeInSeconds
|
||||
<< "s" << L";" << printInfo.warn.toSeconds(printInfo.unit).pString() << L";"
|
||||
<< printInfo.crit.toSeconds(printInfo.unit).pString() << L";0;" << '\n';
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -209,6 +210,9 @@ static void getUptime(printInfoStruct& printInfo)
|
|||
printInfo.time = uptime.count();
|
||||
break;
|
||||
}
|
||||
|
||||
// For the Performance Data we need the time in seconds
|
||||
printInfo.timeInSeconds = boost::chrono::duration_cast<boost::chrono::seconds>(uptime).count();
|
||||
}
|
||||
|
||||
int wmain(int argc, WCHAR **argv)
|
||||
|
|
|
@ -28,6 +28,13 @@ threshold::threshold()
|
|||
: set(false)
|
||||
{}
|
||||
|
||||
threshold::threshold(const double v, const double c, bool l , bool p ) {
|
||||
lower = v;
|
||||
upper = c;
|
||||
legal = l;
|
||||
perc = p;
|
||||
}
|
||||
|
||||
threshold::threshold(const std::wstring& stri)
|
||||
{
|
||||
if (stri.empty())
|
||||
|
@ -126,6 +133,35 @@ std::wstring threshold::pString(const double max)
|
|||
return s;
|
||||
}
|
||||
|
||||
threshold threshold::toSeconds(const Tunit& fromUnit) {
|
||||
if (!set)
|
||||
return *this;
|
||||
|
||||
double lowerAbs = lower;
|
||||
double upperAbs = upper;
|
||||
|
||||
switch (fromUnit) {
|
||||
case TunitMS:
|
||||
lowerAbs = lowerAbs / 1000;
|
||||
upperAbs = upperAbs / 1000;
|
||||
break;
|
||||
case TunitS:
|
||||
lowerAbs = lowerAbs ;
|
||||
upperAbs = upperAbs ;
|
||||
break;
|
||||
case TunitM:
|
||||
lowerAbs = lowerAbs * 60;
|
||||
upperAbs = upperAbs * 60;
|
||||
break;
|
||||
case TunitH:
|
||||
lowerAbs = lowerAbs * 60 * 60;
|
||||
upperAbs = upperAbs * 60 * 60;
|
||||
break;
|
||||
}
|
||||
|
||||
return threshold(lowerAbs, upperAbs, legal, perc);
|
||||
}
|
||||
|
||||
std::wstring removeZero(double val)
|
||||
{
|
||||
std::wstring ret = boost::lexical_cast<std::wstring>(val);
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
// returns a printable string of the threshold
|
||||
std::wstring pString(const double max = 100.0);
|
||||
|
||||
threshold toSeconds(const Tunit& fromUnit);
|
||||
};
|
||||
|
||||
std::wstring removeZero(double);
|
||||
|
|
Loading…
Reference in New Issue