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

Function parseArguments

plugins/check_memory.cpp:27–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25static bool l_Debug;
26
27static int parseArguments(int ac, WCHAR ** av, po::variables_map& vm, printInfoStruct& printInfo)
28{
29 WCHAR namePath[MAX_PATH];
30 GetModuleFileName(NULL, namePath, MAX_PATH);
31 WCHAR *progName = PathFindFileName(namePath);
32
33 po::options_description desc;
34
35 desc.add_options()
36 ("help,h", "Print help message and exit")
37 ("version,V", "Print version and exit")
38 ("debug,d", "Verbose/Debug output")
39 ("warning,w", po::wvalue<std::wstring>(), "Warning threshold")
40 ("critical,c", po::wvalue<std::wstring>(), "Critical threshold")
41 ("unit,u", po::wvalue<std::wstring>(), "The unit to use for display (default MB)")
42 ("show-used,U", "Show used memory instead of the free memory")
43 ;
44
45 po::wcommand_line_parser parser(ac, av);
46
47 try {
48 po::store(
49 parser
50 .options(desc)
51 .style(
52 po::command_line_style::unix_style |
53 po::command_line_style::allow_long_disguise)
54 .run(),
55 vm);
56 vm.notify();
57 } catch (const std::exception& e) {
58 std::cout << e.what() << '\n' << desc << '\n';
59 return 3;
60 }
61
62 if (vm.count("help")) {
63 std::wcout << progName << " Help\n\tVersion: " << VERSION << '\n';
64 wprintf(
65 L"%s is a simple program to check a machines physical memory.\n"
66 L"You can use the following options to define its behaviour:\n\n", progName);
67 std::cout << desc;
68 wprintf(
69 L"\nIt will then output a string looking something like this:\n\n"
70 L"\tMEMORY WARNING - 50%% free | memory=2024MB;3000;500;0;4096\n\n"
71 L"\"MEMORY\" being the type of the check, \"WARNING\" the returned status\n"
72 L"and \"50%%\" is the returned value.\n"
73 L"The performance data is found behind the \"|\", in order:\n"
74 L"returned value, warning threshold, critical threshold, minimal value and,\n"
75 L"if applicable, the maximal value. Performance data will only be displayed when\n"
76 L"you set at least one threshold\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"
84 L"warn if threshold is broken, which means VALUE > THRESHOLD\n"

Callers 1

wmainFunction · 0.70

Calls 5

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

Tested by

no test coverage detected