Change plugins output and update README

In their perfdata the plugins will now use absolute values for percentage thresholds.
Also the check_disks output is now more similar to the one of nagios/check_disk.
The README has also been improved.

refs #7886 #8060
This commit is contained in:
Jean Flach 2015-01-23 16:34:16 +01:00
parent 01d3be8820
commit a4bfa99552
4 changed files with 99 additions and 71 deletions

View File

@ -1,26 +1,51 @@
##Icinga 2 plugins for Windows##
This collection of plugins is intended to provide basic functionality checks on windows machines. They (mostly) conform to the [nagios developer guidelines](https://nagios-plugins.org/doc/guidelines.html), returning adequate exit codes and printing a pertinent string with performance data.
## Icinga 2 plugins for Windows
This collection of plugins is intended to provide basic functionality checks on windows machines.
They (mostly) conform to the [nagios developer guidelines](https://nagios-plugins.org/doc/guidelines.html),
returning adequate exit codes and printing a pertinent string with performance data.
### Intallation
###Intallation###
The plugins are installed as part of Icinga 2.
###Requirements###
### Requirements
- Boost 1.41.0
- Windows Vista, Windows Server 2008 or newer
###Usage###
Call a plugin with the "--help" option to receive information about its usage.
###License###
### Usage
Call a plugin with the "--help" option to receive information about its usage.
Most of them don't need any parameters to but all of them have a -w (warning) and -c (critical) option.
Those accept, if not otherwise specified, value or percentage based thresholds or threshold ranges.
A few examples:
*./check_command.exe -w 12 -c !60%*
Adds a warning threshold of 12 and an inversed critical threshold of 60%
*./check_command.exe -w ![20%-80%] -c [0%-40%]*
The warning threshold is outside of 20% to 80% and the critical threshold is the range from 0% to 40%.
A critical state always overwrites a warning state, meaning the check would be critical with a value of 30%.
### License
Icinga 2
Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org)
This program is free software; you can redistribute it and/or modify it under the tems of the GNU General Public License as published by the Free Software Foundation; either version 2
This program is free software; you can redistribute it and/or
modify it under the tems of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

View File

@ -27,7 +27,7 @@
#include "boost/program_options.hpp"
#define VERSION 1.0
#define VERSION 1.1
namespace po = boost::program_options;
@ -209,48 +209,46 @@ int printOutput(printInfoStruct& printInfo, vector<drive>& vDrives)
{
if (debug)
wcout << L"Constructing output string" << endl;
state state = OK;
double tCap = 0, tFree = 0;
std::wstringstream perf, prePerf;
vector<wstring> wsDrives, wsPerf;
wstring unit = BunitStr(printInfo.unit);
for (vector<drive>::iterator it = vDrives.begin(); it != vDrives.end(); ++it) {
tCap += it->cap; tFree += it->free;
perf << std::fixed << L" " << it->name << L"=" << removeZero(it->free) << unit << L";"
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0;" << removeZero(tCap);
state state = OK;
wstring output = L"DISK OK - free space:";
double tCap = 0, tFree = 0;
for (vector<drive>::iterator it = vDrives.begin(); it != vDrives.end(); it++) {
tCap += it->cap;
tFree += it->free;
wsDrives.push_back(it->name + L" " + removeZero(it->free) + L" " + unit + L" (" +
removeZero(std::round(it->free/it->cap * 100.0)) + L"%); ");
wsPerf.push_back(L" " + it->name + L"=" + removeZero(it->free) + unit + L";" +
printInfo.warn.pString(it->cap) + L";" + printInfo.crit.pString(it->cap) + L";0;"
+ removeZero(it->cap));
}
prePerf << L" | disk=" << removeZero(tFree) << unit << L";" << printInfo.warn.pString() << L";"
<< printInfo.crit.pString() << L";0;" << removeZero(tCap);
if (printInfo.warn.perc) {
if (printInfo.warn.rend((tFree / tCap) * 100.0))
state = WARNING;
} else {
if (printInfo.warn.rend(tFree))
if (printInfo.warn.rend(tFree, tCap)) {
state = WARNING;
output = L"DISK WARNING - free space:";
}
if (printInfo.crit.perc) {
if (printInfo.crit.rend((tFree / tCap) * 100.0))
state = CRITICAL;
} else {
if (printInfo.crit.rend(tFree))
if (printInfo.crit.rend(tFree, tCap)) {
state = CRITICAL;
output = L"DISK CRITICAL - free space:";
}
switch (state) {
case OK:
wcout << L"DISK OK " << std::fixed << removeZero(tFree) << unit << prePerf.str() << perf.str() << endl;
break;
case WARNING:
wcout << L"DISK WARNING " << std::fixed << removeZero(tFree) << unit << prePerf.str() << perf.str() << endl;
break;
case CRITICAL:
wcout << L"DISK CRITICAL " << std::fixed << removeZero(tFree) << unit << prePerf.str() << perf.str() << endl;
break;
}
wcout << output;
if (vDrives.size() > 1)
wcout << L"Total " << tFree << unit << L" (" << removeZero(std::round(tFree/tCap * 100.0)) << L"%); ";
for (vector<wstring>::const_iterator it = wsDrives.begin(); it != wsDrives.end(); it++)
wcout << *it;
wcout << L"|";
for (vector<wstring>::const_iterator it = wsPerf.begin(); it != wsPerf.end(); it++)
wcout << *it;
wcout << endl;
return state;
}
@ -369,11 +367,11 @@ bool getFreeAndCap(drive& drive, const Bunit& unit)
wcout << L"\tcap: " << tempFree.QuadPart << endl;
drive.cap = round((tempTotal.QuadPart / pow(1024.0, unit)));
if (debug)
wcout << L"\tAfter converion: " << drive.cap << endl
wcout << L"\tAfter conversion: " << drive.cap << endl
<< L"\tfree: " << tempFree.QuadPart << endl;
drive.free = round((tempFree.QuadPart / pow(1024.0, unit)));
if (debug)
wcout << L"\tAfter converion: " << drive.free << endl << endl;
wcout << L"\tAfter conversion: " << drive.free << endl << endl;
return TRUE;
}

View File

@ -86,39 +86,44 @@ threshold::threshold(const wstring& stri)
}
//return TRUE if the threshold is broken
bool threshold::rend(const double b)
bool threshold::rend(const double val, const double max)
{
double upperAbs = upper;
double lowerAbs = lower;
if (perc) {
upperAbs = upper / 100 * max;
lowerAbs = lower / 100 * max;
}
if (!set)
return set;
if (lower == upper)
return b > upper == legal;
if (lowerAbs == upperAbs)
return val > upperAbs == legal;
else
return (b < lower || upper < b) != legal;
return (val < lowerAbs || upperAbs < val) != legal;
}
//returns a printable string of the threshold
std::wstring threshold::pString()
std::wstring threshold::pString(const double max)
{
if (!set)
return L"";
//transform percentages to abolute values
double lowerAbs = lower/100 * max;
double upperAbs = upper/100 * max;
std::wstring s, lowerStr = removeZero(lower), upperStr = removeZero(upper);
std::wstring s, lowerStr = removeZero(lowerAbs),
upperStr = removeZero(upperAbs);
if (!legal)
s.append(L"!");
if (lower != upper) {
if (perc)
s.append(L"[").append(lowerStr).append(L"%").append(L"-")
.append(upperStr).append(L"%").append(L"]");
else
s.append(L"[").append(lowerStr).append(L"-")
.append(upperStr).append(L"]");
} else {
if (perc)
s = lowerStr.append(L"%");
else
} else
s = lowerStr;
}
return s;
}

View File

@ -40,10 +40,10 @@ public:
threshold(const std::wstring&);
//return TRUE if the threshold is broken
bool rend(const double b);
bool rend(const double val, const double max = 100);
//returns a printable string of the threshold
std::wstring pString();
std::wstring pString(const double max = 100);
};
std::wstring removeZero(double);