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

Function parseArguments

plugins/check_service.cpp:23–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21static bool l_Debug;
22
23static int parseArguments(int ac, WCHAR **av, po::variables_map& vm, printInfoStruct& printInfo)
24{
25 WCHAR namePath[MAX_PATH];
26 GetModuleFileName(NULL, namePath, MAX_PATH);
27 WCHAR *progName = PathFindFileName(namePath);
28
29 po::options_description desc;
30
31 desc.add_options()
32 ("help,h", "Print help message and exit")
33 ("version,V", "Print version and exit")
34 ("debug,D", "Verbose/Debug output")
35 ("service,s", po::wvalue<std::wstring>(), "Service name to check")
36 ("description,d", "Use \"service\" to match on description")
37 ("warn,w", "Return warning (1) instead of critical (2),\n when service is not running")
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_guessing |
49 po::command_line_style::allow_long_disguise
50 )
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 the status of a service.\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"\tSERVICE CRITICAL NOT_RUNNING | service=4;!4;!4;1;7\n\n"
68 L"\"SERVICE\" being the type of the check, \"CRITICAL\" the returned status\n"
69 L"and \"1\" is the returned value.\n"
70 L"A service is either running (Code 0x04) or not running (any other).\n"
71 L"For more information consult the msdn on service state transitions.\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"%s' thresholds work differently, since a service is either running or not\n"
78 L"all \"-w\" and \"-c\" do is say whether a not running service is a warning\n"
79 L"or critical state respectively.\n\n"
80 , progName, progName);

Callers 1

wmainFunction · 0.70

Calls 3

optionsMethod · 0.80
countMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected