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

Function main

plugins/check_nscp_api.cpp:427–513  ·  view source on GitHub ↗

* Main function * * @param argc * @param argv * @return exit code */

Source from the content-addressed store, hash-verified

425 * @return exit code
426 */
427int main(int argc, char **argv)
428{
429 po::variables_map vm;
430 po::options_description desc("Options");
431
432 desc.add_options()
433 ("help,h", "Print usage message and exit")
434 ("version,V", "Print version and exit")
435 ("debug,d", "Verbose/Debug output")
436 ("host,H", po::value<std::string>()->required(), "REQUIRED: NSCP API Host")
437 ("port,P", po::value<std::string>()->default_value("8443"), "NSCP API Port (Default: 8443)")
438 ("password", po::value<std::string>()->required(), "REQUIRED: NSCP API Password")
439 ("query,q", po::value<std::string>()->required(), "REQUIRED: NSCP API Query endpoint")
440 ("arguments,a", po::value<std::vector<std::string>>()->multitoken(), "NSCP API Query arguments for the endpoint");
441
442 po::command_line_parser parser(argc, argv);
443
444 try {
445 po::store(
446 parser
447 .options(desc)
448 .style(
449 po::command_line_style::unix_style |
450 po::command_line_style::allow_long_disguise)
451 .run(),
452 vm);
453
454 if (vm.count("version")) {
455 std::cout << "Version: " << VERSION << '\n';
456 Application::Exit(0);
457 }
458
459 if (vm.count("help")) {
460 std::cout << argv[0] << " Help\n\tVersion: " << VERSION << '\n';
461 std::cout << "check_nscp_api is a program used to query the NSClient++ API.\n";
462 std::cout << desc;
463 std::cout << "For detailed information on possible queries and their arguments refer to the NSClient++ documentation.\n";
464 Application::Exit(0);
465 }
466
467 vm.notify();
468 } catch (const std::exception& e) {
469 std::cout << e.what() << '\n' << desc << '\n';
470 Application::Exit(3);
471 }
472
473 l_Debug = vm.count("debug") > 0;
474
475 // Initialize logger
476 if (l_Debug)
477 Logger::SetConsoleLogSeverity(LogDebug);
478 else
479 Logger::SetConsoleLogSeverity(LogWarning);
480
481 // Create the URL string and escape certain characters since Url() follows RFC 3986
482 String endpoint = "/query/" + vm["query"].as<std::string>();
483 if (!vm.count("arguments"))
484 endpoint += '/';

Callers

nothing calls this directly

Calls 7

FetchDataFunction · 0.85
FormatOutputFunction · 0.85
optionsMethod · 0.80
countMethod · 0.80
FindFirstOfMethod · 0.80
SubStrMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected