mirror of https://github.com/Icinga/icinga2.git
Some minor plugin fixes
This commit is contained in:
parent
bf6a205edf
commit
023cfc15bb
|
@ -98,7 +98,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
||||||
("version,v", "print version and exit")
|
("version,v", "print version and exit")
|
||||||
("warning,w", po::wvalue<wstring>(), "warning threshold")
|
("warning,w", po::wvalue<wstring>(), "warning threshold")
|
||||||
("critical,c", po::wvalue<wstring>(), "critical threshold")
|
("critical,c", po::wvalue<wstring>(), "critical threshold")
|
||||||
("drives,d", po::wvalue<vector<std::wstring>>()->multitoken(), "declare explicitly which drives to check (default checks all)")
|
("path,p", po::wvalue<vector<std::wstring>>()->multitoken(), "declare explicitly which drives to check (default checks all)")
|
||||||
("unit,u", po::wvalue<wstring>(), "assign unit possible are: B, kB, MB, GB, TB")
|
("unit,u", po::wvalue<wstring>(), "assign unit possible are: B, kB, MB, GB, TB")
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -186,8 +186,8 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.count("drives"))
|
if (vm.count("path"))
|
||||||
printInfo.drives = vm["drives"].as<vector<wstring>>();
|
printInfo.drives = vm["path"].as<vector<wstring>>();
|
||||||
|
|
||||||
if (vm.count("unit")) {
|
if (vm.count("unit")) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,15 +16,16 @@
|
||||||
* along with this program; if not, write to the Free Software Foundation *
|
* along with this program; if not, write to the Free Software Foundation *
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "thresholds.h"
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
#include <Pdh.h>
|
#include <Pdh.h>
|
||||||
#include <Shlwapi.h>
|
#include <Shlwapi.h>
|
||||||
#include <pdhmsg.h>
|
#include <pdhmsg.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "thresholds.h"
|
|
||||||
|
|
||||||
#include "boost/program_options.hpp"
|
|
||||||
|
|
||||||
#define VERSION 1.0
|
#define VERSION 1.0
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
@ -142,7 +143,10 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
||||||
|
|
||||||
if (vm.count("warning")) {
|
if (vm.count("warning")) {
|
||||||
try {
|
try {
|
||||||
printInfo.warn = threshold(vm["warning"].as<wstring>());
|
std::wstring wthreshold = vm["warning"].as<wstring>();
|
||||||
|
std::vector<std::wstring> tokens;
|
||||||
|
boost::algorithm::split(tokens, wthreshold, boost::algorithm::is_any_of(","));
|
||||||
|
printInfo.warn = threshold(tokens[0]);
|
||||||
} catch (std::invalid_argument& e) {
|
} catch (std::invalid_argument& e) {
|
||||||
cout << e.what() << endl;
|
cout << e.what() << endl;
|
||||||
return 3;
|
return 3;
|
||||||
|
@ -150,7 +154,10 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
||||||
}
|
}
|
||||||
if (vm.count("critical")) {
|
if (vm.count("critical")) {
|
||||||
try {
|
try {
|
||||||
printInfo.crit = threshold(vm["critical"].as<wstring>());
|
std::wstring cthreshold = vm["critical"].as<wstring>();
|
||||||
|
std::vector<std::wstring> tokens;
|
||||||
|
boost::algorithm::split(tokens, cthreshold, boost::algorithm::is_any_of(","));
|
||||||
|
printInfo.crit = threshold(tokens[0]);
|
||||||
} catch (std::invalid_argument& e) {
|
} catch (std::invalid_argument& e) {
|
||||||
cout << e.what() << endl;
|
cout << e.what() << endl;
|
||||||
return 3;
|
return 3;
|
||||||
|
|
|
@ -172,15 +172,15 @@ int printOutput(printInfoStruct& printInfo)
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case OK:
|
case OK:
|
||||||
wcout << L"USERS OK " << printInfo.users << L"User|users=" << printInfo.users << L";"
|
wcout << L"USERS OK " << printInfo.users << L" User(s)|users=" << printInfo.users << L";"
|
||||||
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl;
|
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl;
|
||||||
break;
|
break;
|
||||||
case WARNING:
|
case WARNING:
|
||||||
wcout << L"USERS WARNING " << printInfo.users << L"User|users=" << printInfo.users << L";"
|
wcout << L"USERS WARNING " << printInfo.users << L" User(s)|users=" << printInfo.users << L";"
|
||||||
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl;
|
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl;
|
||||||
break;
|
break;
|
||||||
case CRITICAL:
|
case CRITICAL:
|
||||||
wcout << L"USERS CRITICAL " << printInfo.users << L"User|users=" << printInfo.users << L";"
|
wcout << L"USERS CRITICAL " << printInfo.users << L" User(s)|users=" << printInfo.users << L";"
|
||||||
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl;
|
<< printInfo.warn.pString() << L";" << printInfo.crit.pString() << L";0" << endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,12 @@
|
||||||
* along with this program; if not, write to the Free Software Foundation *
|
* along with this program; if not, write to the Free Software Foundation *
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "thresholds.h"
|
#include "thresholds.h"
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
#include "boost/algorithm/string.hpp"
|
#include <boost/lexical_cast.hpp>
|
||||||
#include "boost/lexical_cast.hpp"
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace boost::algorithm;
|
using namespace boost::algorithm;
|
||||||
|
|
||||||
|
@ -100,9 +99,11 @@ threshold::threshold(const wstring& stri)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
double d1 = boost::lexical_cast<double>(str1);
|
boost::algorithm::trim(str1);
|
||||||
double d2 = boost::lexical_cast<double>(str2);
|
lower = boost::lexical_cast<double>(str1);
|
||||||
lower = d1; upper = d2; legal = !low; perc = pc; set = true;
|
boost::algorithm::trim(str2);
|
||||||
|
upper = boost::lexical_cast<double>(str2);
|
||||||
|
legal = !low; perc = pc; set = true;
|
||||||
} catch (const boost::bad_lexical_cast&) {
|
} catch (const boost::bad_lexical_cast&) {
|
||||||
throw std::invalid_argument("Unknown Threshold type");
|
throw std::invalid_argument("Unknown Threshold type");
|
||||||
}
|
}
|
||||||
|
@ -112,8 +113,9 @@ threshold::threshold(const wstring& stri)
|
||||||
str = wstring(str.begin(), str.end() - 1);
|
str = wstring(str.begin(), str.end() - 1);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
double d = boost::lexical_cast<double>(str);
|
boost::algorithm::trim(str);
|
||||||
lower = d; upper = d; legal = !low; perc = pc; set = true;
|
lower = upper = boost::lexical_cast<double>(str);
|
||||||
|
legal = !low; perc = pc; set = true;
|
||||||
} catch (const boost::bad_lexical_cast&) {
|
} catch (const boost::bad_lexical_cast&) {
|
||||||
throw std::invalid_argument("Unknown Threshold type");
|
throw std::invalid_argument("Unknown Threshold type");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue