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

Function parseArguments

plugins/check_load.cpp:26–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24static bool l_Debug;
25
26static int parseArguments(int ac, WCHAR **av, po::variables_map& vm, printInfoStruct& printInfo)
27{
28 wchar_t namePath[MAX_PATH];
29 GetModuleFileName(NULL, namePath, MAX_PATH);
30 wchar_t *progName = PathFindFileName(namePath);
31
32 po::options_description desc;
33
34 desc.add_options()
35 ("help,h", "Print usage message and exit")
36 ("version,V", "Print version and exit")
37 ("debug,d", "Verbose/Debug output")
38 ("warning,w", po::wvalue<std::wstring>(), "Warning value (in percent)")
39 ("critical,c", po::wvalue<std::wstring>(), "Critical value (in percent)")
40 ;
41
42 po::wcommand_line_parser parser(ac, av);
43
44 try {
45 po::store(
46 parser
47 .options(desc)
48 .style(
49 po::command_line_style::unix_style |
50 po::command_line_style::allow_long_disguise)
51 .run(),
52 vm);
53 vm.notify();
54 } catch (const std::exception& e) {
55 std::cout << e.what() << '\n' << desc << '\n';
56 return 3;
57 }
58
59 if (vm.count("help")) {
60 std::wcout << progName << " Help\n\tVersion: " << VERSION << '\n';
61 wprintf(
62 L"%s is a simple program to check a machines CPU load.\n"
63 L"You can use the following options to define its behaviour:\n\n", progName);
64 std::cout << desc;
65 wprintf(
66 L"\nIt will then output a string looking something like this:\n\n"
67 L"\tLOAD WARNING 67%% | load=67%%;50%%;90%%;0;100\n\n"
68 L"\"LOAD\" being the type of the check, \"WARNING\" the returned status\n"
69 L"and \"67%%\" is the returned value.\n"
70 L"The performance data is found behind the \"|\", in order:\n"
71 L"returned value, warning threshold, critical threshold, minimal value and,\n"
72 L"if applicable, the maximal value.\n\n"
73 L"%s' exit codes denote the following:\n"
74 L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n"
75 L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n"
76 L" 2\tCRITICAL,\n\tThe critical threshold was broken\n"
77 L" 3\tUNKNOWN, \n\tThe program experienced an internal or input error\n\n"
78 L"Threshold syntax:\n\n"
79 L"-w THRESHOLD\n"
80 L"warn if threshold is broken, which means VALUE > THRESHOLD\n"
81 L"(unless stated differently)\n\n"
82 L"-w !THRESHOLD\n"
83 L"inverts threshold check, VALUE < THRESHOLD (analogous to above)\n\n"

Callers 1

wmainFunction · 0.70

Calls 5

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

Tested by

no test coverage detected