]> granicus.if.org Git - icinga2/commitdiff
Change plugins output and update README
authorJean Flach <jean-marcel.flach@netways.de>
Fri, 23 Jan 2015 15:34:16 +0000 (16:34 +0100)
committerJean Flach <jean-marcel.flach@netways.de>
Fri, 23 Jan 2015 15:34:16 +0000 (16:34 +0100)
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

plugins/README.md
plugins/check_disk.cpp
plugins/thresholds.cpp
plugins/thresholds.h

index 715237d0dba1e03f91a257b6a44766c4bb61f2d3..53a3892fda6efe84faa588a8294298b9350caf63 100644 (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)
 
- 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  
+of the License, or (at your option) any later version.
 
- 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.
index cd49c86ef1a9c5d290886892e72d18865a956527..5b2e12a6486057e871da7ec24369410c80206968 100644 (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;
-       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);
-       }
+       vector<wstring> wsDrives, wsPerf;
+       wstring unit = BunitStr(printInfo.unit);
 
-       prePerf << L" | disk=" << removeZero(tFree) << unit << L";" << printInfo.warn.pString() << L";"
-               << printInfo.crit.pString() << L";0;" << removeZero(tCap);
+       state state = OK;
+       wstring output = L"DISK OK - free space:";
 
-       if (printInfo.warn.perc) {
-               if (printInfo.warn.rend((tFree / tCap) * 100.0))
-                       state = WARNING;
-       } else {
-               if (printInfo.warn.rend(tFree))
-                       state = WARNING;
+       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));
        }
 
-       if (printInfo.crit.perc) {
-               if (printInfo.crit.rend((tFree / tCap) * 100.0))
-                       state = CRITICAL;
-       } else {
-               if (printInfo.crit.rend(tFree))
-                       state = CRITICAL;
+       if (printInfo.warn.rend(tFree, tCap)) {
+               state = WARNING;
+               output = L"DISK WARNING - 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;
+       if (printInfo.crit.rend(tFree, tCap)) {
+               state = CRITICAL;
+               output = L"DISK CRITICAL - free space:";
        }
 
+       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;
 }
\ No newline at end of file
index 3a74da17ad1a4e4e760c16e580d9504e3f9af7cd..630112af939f28da376a29f976be2349e3b906d8 100644 (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
-                       s = lowerStr;
-       }
+               s.append(L"[").append(lowerStr).append(L"-")
+               .append(upperStr).append(L"]");
+       } else 
+               s = lowerStr;
+       
        return s;
 }
 
index ce2b0af1b0d81ecd19ab30bf9598548bd2b3b813..099517bae0687453a3cdd66070c4d31684645be1 100644 (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);