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 warn;
|
||||||
threshold crit;
|
threshold crit;
|
||||||
long long time;
|
long long time;
|
||||||
|
long long timeInSeconds;
|
||||||
Tunit unit;
|
Tunit unit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -166,19 +167,19 @@ static int printOutput(printInfoStruct& printInfo)
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case OK:
|
case OK:
|
||||||
std::wcout << L"UPTIME OK " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.time
|
std::wcout << L"UPTIME OK " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.timeInSeconds
|
||||||
<< TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";"
|
<< "s" << L";" << printInfo.warn.toSeconds(printInfo.unit).pString() << L";"
|
||||||
<< printInfo.crit.pString() << L";0;" << '\n';
|
<< printInfo.crit.toSeconds(printInfo.unit).pString() << L";0;" << '\n';
|
||||||
break;
|
break;
|
||||||
case WARNING:
|
case WARNING:
|
||||||
std::wcout << L"UPTIME WARNING " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.time
|
std::wcout << L"UPTIME WARNING " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.timeInSeconds
|
||||||
<< TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";"
|
<< "s" << L";" << printInfo.warn.toSeconds(printInfo.unit).pString() << L";"
|
||||||
<< printInfo.crit.pString() << L";0;" << '\n';
|
<< printInfo.crit.toSeconds(printInfo.unit).pString() << L";0;" << '\n';
|
||||||
break;
|
break;
|
||||||
case CRITICAL:
|
case CRITICAL:
|
||||||
std::wcout << L"UPTIME CRITICAL " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.time
|
std::wcout << L"UPTIME CRITICAL " << printInfo.time << TunitStr(printInfo.unit) << L" | 'uptime'=" << printInfo.timeInSeconds
|
||||||
<< TunitStr(printInfo.unit) << L";" << printInfo.warn.pString() << L";"
|
<< "s" << L";" << printInfo.warn.toSeconds(printInfo.unit).pString() << L";"
|
||||||
<< printInfo.crit.pString() << L";0;" << '\n';
|
<< printInfo.crit.toSeconds(printInfo.unit).pString() << L";0;" << '\n';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,6 +210,9 @@ static void getUptime(printInfoStruct& printInfo)
|
||||||
printInfo.time = uptime.count();
|
printInfo.time = uptime.count();
|
||||||
break;
|
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)
|
int wmain(int argc, WCHAR **argv)
|
||||||
|
|
|
@ -28,6 +28,13 @@ threshold::threshold()
|
||||||
: set(false)
|
: 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)
|
threshold::threshold(const std::wstring& stri)
|
||||||
{
|
{
|
||||||
if (stri.empty())
|
if (stri.empty())
|
||||||
|
@ -126,6 +133,35 @@ std::wstring threshold::pString(const double max)
|
||||||
return s;
|
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 removeZero(double val)
|
||||||
{
|
{
|
||||||
std::wstring ret = boost::lexical_cast<std::wstring>(val);
|
std::wstring ret = boost::lexical_cast<std::wstring>(val);
|
||||||
|
|
|
@ -62,6 +62,7 @@ public:
|
||||||
// returns a printable string of the threshold
|
// returns a printable string of the threshold
|
||||||
std::wstring pString(const double max = 100.0);
|
std::wstring pString(const double max = 100.0);
|
||||||
|
|
||||||
|
threshold toSeconds(const Tunit& fromUnit);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::wstring removeZero(double);
|
std::wstring removeZero(double);
|
||||||
|
|
Loading…
Reference in New Issue