MCPcopy Create free account
hub / github.com/Icinga/icinga2 / parseArguments

Function parseArguments

plugins/check_perfmon.cpp:27–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25};
26
27static bool parseArguments(const int ac, WCHAR **av, po::variables_map& vm, printInfoStruct& printInfo)
28{
29 WCHAR szNamePath[MAX_PATH + 1];
30 GetModuleFileName(NULL, szNamePath, MAX_PATH);
31 WCHAR *szProgName = PathFindFileName(szNamePath);
32
33 po::options_description desc("Options");
34 desc.add_options()
35 ("help,h", "Print help page and exit")
36 ("version,V", "Print version and exit")
37 ("warning,w", po::wvalue<std::wstring>(), "Warning thershold")
38 ("critical,c", po::wvalue<std::wstring>(), "Critical threshold")
39 ("performance-counter,P", po::wvalue<std::wstring>(), "The performance counter string to use")
40 ("performance-wait", po::value<DWORD>(), "Sleep in milliseconds between the two perfomance querries (Default: 1000ms)")
41 ("fmt-countertype", po::wvalue<std::wstring>(), "Value type of counter: 'double'(default), 'long', 'int64'")
42 ("print-objects", "Prints all available objects to console")
43 ("print-object-info", "Prints all available instances and counters of --performance-counter, do not use a full perfomance counter string here")
44 ("perf-syntax", po::wvalue<std::wstring>(), "Use this string as name for the performance counter (graphite compatibility)")
45 ;
46
47 po::wcommand_line_parser parser(ac, av);
48
49 try {
50 po::store(
51 parser
52 .options(desc)
53 .style(
54 po::command_line_style::unix_style |
55 po::command_line_style::allow_long_disguise)
56 .run(),
57 vm);
58 vm.notify();
59 } catch (const std::exception& e) {
60 std::cout << e.what() << '\n' << desc << '\n';
61 return false;
62 }
63
64 if (vm.count("version")) {
65 std::wcout << "Version: " << VERSION << '\n';
66 return false;
67 }
68
69 if (vm.count("help")) {
70 std::wcout << szProgName << " Help\n\tVersion: " << VERSION << '\n';
71 wprintf(
72 L"%s runs a check against a performance counter.\n"
73 L"You can use the following options to define its behaviour:\n\n", szProgName);
74 std::cout << desc;
75 wprintf(
76 L"\nIt will then output a string looking something like this:\n\n"
77 L"\tPERFMON CRITICAL \"\\Processor(_Total)\\%% Idle Time\" = 40.34 | "
78 L"perfmon=40.34;20;40;; \"\\Processor(_Total)\\%% Idle Time\"=40.34\n\n"
79 L"\"tPERFMON\" being the type of the check, \"CRITICAL\" the returned status\n"
80 L"and \"40.34\" is the performance counters value.\n"
81 L"%s' exit codes denote the following:\n"
82 L" 0\tOK,\n\tNo Thresholds were exceeded\n"
83 L" 1\tWARNING,\n\tThe warning was broken, but not the critical threshold\n"
84 L" 2\tCRITICAL,\n\tThe critical threshold was broken\n"

Callers 1

wmainFunction · 0.70

Calls 4

thresholdClass · 0.85
optionsMethod · 0.80
countMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected