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

Function parseArguments

plugins/check_uptime.cpp:26–138  ·  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 namePath[MAX_PATH];
29 GetModuleFileName(NULL, namePath, MAX_PATH);
30 WCHAR *progName = PathFindFileName(namePath);
31
32 po::options_description desc;
33
34 desc.add_options()
35 ("help,h", "Print help message and exit")
36 ("version,V", "Print version and exit")
37 ("debug,d", "Verbose/Debug output")
38 ("warning,w", po::wvalue<std::wstring>(), "Warning threshold (Uses -unit)")
39 ("critical,c", po::wvalue<std::wstring>(), "Critical threshold (Uses -unit)")
40 ("unit,u", po::wvalue<std::wstring>(), "Unit to use:\nh\t- hours\nm\t- minutes\ns\t- seconds (default)\nms\t- milliseconds")
41 ;
42
43 po::wcommand_line_parser parser(ac, av);
44
45 try {
46 po::store(
47 parser
48 .options(desc)
49 .style(
50 po::command_line_style::unix_style |
51 po::command_line_style::allow_long_disguise)
52 .run(),
53 vm);
54 vm.notify();
55 } catch (const std::exception& e) {
56 std::cout << e.what() << '\n' << desc << '\n';
57 return 3;
58 }
59
60 if (vm.count("help")) {
61 std::wcout << progName << " Help\n\tVersion: " << VERSION << '\n';
62 wprintf(
63 L"%s is a simple program to check a machines uptime.\n"
64 L"You can use the following options to define its behaviour:\n\n", progName);
65 std::cout << desc;
66 wprintf(
67 L"\nIt will then output a string looking something like this:\n\n"
68 L"\tUPTIME WARNING 712h | uptime=712h;700;1800;0\n\n"
69 L"\"UPTIME\" being the type of the check, \"WARNING\" the returned status\n"
70 L"and \"712h\" is the returned value.\n"
71 L"The performance data is found behind the \"|\", in order:\n"
72 L"returned value, warning threshold, critical threshold, minimal value and,\n"
73 L"if applicable, the maximal value. Performance data will only be displayed when\n"
74 L"you set at least one threshold\n\n"
75 L"Note that the returned time ins always rounded down,\n"
76 L"4 hours and 44 minutes will show as 4h.\n\n"
77 L"%s' exit codes denote the following:\n"
78 L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n"
79 L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n"
80 L" 2\tCRITICAL,\n\tThe critical threshold was broken\n"
81 L" 3\tUNKNOWN, \n\tThe program experienced an internal or input error\n\n"
82 L"Threshold syntax:\n\n"
83 L"-w THRESHOLD\n"

Callers 1

wmainFunction · 0.70

Calls 5

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

Tested by

no test coverage detected