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

Function parseArguments

plugins/check_users.cpp:24–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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