]> granicus.if.org Git - icinga2/blobdiff - plugins/check_perfmon.cpp
Make a few functions static
[icinga2] / plugins / check_perfmon.cpp
index 02b1186203b29463924fee9e544fe5f88acb933a..d1365163bf4c76fd53bddb8ef71e44a170755b7d 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
 * 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                *
@@ -67,6 +67,7 @@ BOOL ParseArguments(CONST INT ac, WCHAR **av, po::variables_map& vm, printInfoSt
                ("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);
@@ -131,13 +132,11 @@ BOOL ParseArguments(CONST INT ac, WCHAR **av, po::variables_map& vm, printInfoSt
        }
 
        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;
                }
@@ -341,10 +340,13 @@ BOOL QueryPerfData(printInfoStruct& pI)
        {
        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;
@@ -360,24 +362,29 @@ die:
 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;
 }