/******************************************************************************
* Icinga 2 *
-* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
+* Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
("fmt-countertype", po::wvalue<std::wstring>(), "Value type of counter: 'double'(default), 'long', 'int64'")
("print-objects", "Prints all available objects to console")
("print-object-info", "Prints all available instances and counters of --performance-counter, do not use a full perfomance counter string here")
+ ("perf-syntax", po::wvalue<std::wstring>(), "Use this string as name for the performance counter (graphite compatibility)")
;
po::basic_command_line_parser<wchar_t> parser(ac, av);
}
if (vm.count("fmt-countertype")) {
- if (vm["fmt-countertype"].as<std::wstring>().compare(L"double"))
- printInfo.dwRequestedType = PDH_FMT_DOUBLE;
- else if (vm["fmt-countertype"].as<std::wstring>().compare(L"int64"))
+ if (!vm["fmt-countertype"].as<std::wstring>().compare(L"int64"))
printInfo.dwRequestedType = PDH_FMT_LARGE;
- else if (vm["fmt-countertype"].as<std::wstring>().compare(L"long"))
+ else if (!vm["fmt-countertype"].as<std::wstring>().compare(L"long"))
printInfo.dwRequestedType = PDH_FMT_LONG;
- else {
+ else if (vm["fmt-countertype"].as<std::wstring>().compare(L"double")) {
std::wcout << "Unknown value type " << vm["fmt-countertype"].as<std::wstring>() << '\n';
return FALSE;
}
{
case (PDH_FMT_LONG):
pI.dValue = pDisplayValues[0].FmtValue.longValue;
- case (PDH_FMT_LARGE) :
+ break;
+ case (PDH_FMT_LARGE):
pI.dValue = pDisplayValues[0].FmtValue.largeValue;
+ break;
default:
pI.dValue = pDisplayValues[0].FmtValue.doubleValue;
+ break;
}
delete[]pDisplayValues;
INT PrintOutput(CONST po::variables_map& vm, printInfoStruct& pi)
{
std::wstringstream wssPerfData;
- wssPerfData << "perfmon=" << pi.dValue << ';'
- << pi.tWarn.pString() << ';' << pi.tCrit.pString() << ";; "
- << '"' << pi.wsFullPath << "\"=" << pi.dValue;
+
+ if (vm.count("perf-syntax")) {
+ wssPerfData << "\"" << vm["perf-syntax"].as<std::wstring>() << "\"=";
+ } else {
+ wssPerfData << "\"" << pi.wsFullPath << "\"=";
+ }
+
+ wssPerfData << pi.dValue << ';' << pi.tWarn.pString() << ';' << pi.tCrit.pString() << ";;";
if (pi.tCrit.rend(pi.dValue)) {
- std::wcout << "PERFMON CRITICAL \"" << pi.wsFullPath << "\" = "
- << pi.dValue << " | " << wssPerfData.str() << '\n';
+ std::wcout << "PERFMON CRITICAL \"" << (vm.count("perf-syntax") ? vm["perf-syntax"].as<std::wstring>() : pi.wsFullPath)
+ << "\" = " << pi.dValue << " | " << wssPerfData.str() << '\n';
return 2;
}
if (pi.tWarn.rend(pi.dValue)) {
- std::wcout << "PERFMON WARNING \"" << pi.wsFullPath << "\" = "
- << pi.dValue << " | " << wssPerfData.str() << '\n';
+ std::wcout << "PERFMON WARNING \"" << (vm.count("perf-syntax") ? vm["perf-syntax"].as<std::wstring>() : pi.wsFullPath)
+ << "\" = " << pi.dValue << " | " << wssPerfData.str() << '\n';
return 1;
}
- std::wcout << "PERFMON OK \"" << pi.wsFullPath << "\" = "
- << pi.dValue << " | " << wssPerfData.str() << '\n';
+ std::wcout << "PERFMON OK \"" << (vm.count("perf-syntax") ? vm["perf-syntax"].as<std::wstring>() : pi.wsFullPath)
+ << "\" = " << pi.dValue << " | " << wssPerfData.str() << '\n';
return 0;
}