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

Function parseArguments

plugins/check_procs.cpp:24–128  ·  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 ("user,u", po::wvalue<std::wstring>(), "Count only processes of user")
37 ("warning,w", po::wvalue<std::wstring>(), "Warning threshold")
38 ("critical,c", po::wvalue<std::wstring>(), "Critical threshold")
39 ;
40
41 po::wcommand_line_parser parser(ac, av);
42
43 try {
44 po::store(
45 parser
46 .options(desc)
47 .style(
48 po::command_line_style::unix_style |
49 po::command_line_style::allow_long_disguise)
50 .run(),
51 vm);
52 vm.notify();
53 } catch (const std::exception& e) {
54 std::cout << e.what() << '\n' << desc << '\n';
55 return 3;
56 }
57
58 if (vm.count("help")) {
59 std::wcout << progName << " Help\n\tVersion: " << VERSION << '\n';
60 wprintf(
61 L"%s is a simple program to check a machines processes.\n"
62 L"You can use the following options to define its behaviour:\n\n", progName);
63 std::cout << desc;
64 wprintf(
65 L"\nIt will then output a string looking something like this:\n\n"
66 L"\tPROCS WARNING 67 | load=67;50;90;0\n\n"
67 L"\"PROCS\" being the type of the check, \"WARNING\" the returned status\n"
68 L"and \"67\" is the returned value.\n"
69 L"The performance data is found behind the \"|\", in order:\n"
70 L"returned value, warning threshold, critical threshold, minimal value and,\n"
71 L"if applicable, the maximal value. Performance data will only be displayed when\n"
72 L"you set at least one threshold\n\n"
73 L"For \"-user\" option keep in mind you need root to see other users processes\n\n"
74 L"%s' exit codes denote the following:\n"
75 L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n"
76 L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n"
77 L" 2\tCRITICAL,\n\tThe critical threshold was broken\n"
78 L" 3\tUNKNOWN, \n\tThe program experienced an internal or input error\n\n"
79 L"Threshold syntax:\n\n"
80 L"-w THRESHOLD\n"
81 L"warn if threshold is broken, which means VALUE > 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