1012 int exit_status = -1;
1015 static gboolean print_version = FALSE;
1016 static gboolean be_verbose = FALSE;
1017 static gchar *manager_host_string = NULL;
1019 static gchar *omp_username = NULL;
1020 static gchar *omp_password = NULL;
1022 static gboolean cmd_ping = FALSE;
1024 static gboolean cmd_status = FALSE;
1025 static gboolean status_trend = FALSE;
1026 static gboolean status_last_report = FALSE;
1027 static gchar *task_string = NULL;
1028 static gchar *host_filter = NULL;
1029 static gboolean connection_details = FALSE;
1030 static gboolean report_link = FALSE;
1031 static gboolean display_dfn_ids = FALSE;
1032 static gboolean display_oids = FALSE;
1033 static gboolean display_descriptions = FALSE;
1034 static gboolean display_log_messages = FALSE;
1035 static gboolean display_scan_end = FALSE;
1036 static guint autofp = 0;
1037 static gboolean empty_as_unknown = FALSE;
1038 static gboolean use_asset_management = FALSE;
1040 static gchar **rest = NULL;
1042 GError *error = NULL;
1044 GOptionContext *option_context;
1045 static GOptionEntry option_entries[] = {
1047 {
"host",
'H', 0, G_OPTION_ARG_STRING, &manager_host_string,
1048 "Connect to manager on host <host>",
"<host>"},
1049 {
"port",
'p', 0, G_OPTION_ARG_INT, &manager_port,
1050 "Use port number <number>",
"<number>"},
1051 {
"version",
'V', 0, G_OPTION_ARG_NONE, &print_version,
1052 "Print version.", NULL},
1053 {
"verbose",
'v', 0, G_OPTION_ARG_NONE, &be_verbose,
1054 "Verbose messages (WARNING: may reveal passwords).", NULL},
1055 {
"Werror", 0, 0, G_OPTION_ARG_NONE, &warnings_are_errors,
1056 "Turn status UNKNOWN into status CRITICIAL.", NULL},
1057 {
"username",
'u', 0, G_OPTION_ARG_STRING, &omp_username,
1058 "OMP username",
"<username>"},
1059 {
"password",
'w', 0, G_OPTION_ARG_STRING, &omp_password,
1060 "OMP password",
"<password>"},
1061 {
"ping",
'O', 0, G_OPTION_ARG_NONE, &cmd_ping,
1062 "Ping the manager", NULL},
1063 {
"timeout",
't', 0, G_OPTION_ARG_INT, &timeout,
1064 "Wait <seconds> for response (0 disables timeout)",
"<seconds>"},
1068 {
"ping-timeout", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &timeout,
1070 {
"status", 0, 0, G_OPTION_ARG_NONE, &cmd_status,
1071 "Report status of task", NULL},
1072 {
"trend", 0, 0, G_OPTION_ARG_NONE, &status_trend,
1073 "Report status by trend (default)", NULL},
1074 {
"last-report", 0, 0, G_OPTION_ARG_NONE, &status_last_report,
1075 "Report status by last report", NULL},
1076 {
"task",
'T', 0, G_OPTION_ARG_STRING, &task_string,
1077 "Report status of task <task>",
"<task>"},
1078 {
"host-filter",
'F', 0, G_OPTION_ARG_STRING, &host_filter,
1079 "Report last report status of host <ip>",
"<ip>"},
1080 {
"overrides", 0, 0, G_OPTION_ARG_INT, &overrides_flag,
1081 "Include overrides (N: 0=no, 1=yes)",
"N"},
1082 {
"details",
'd', 0, G_OPTION_ARG_NONE, &connection_details,
1083 "Include connection details in output", NULL},
1084 {
"report-link",
'l', 0, G_OPTION_ARG_NONE, &report_link,
1085 "Include URL of report in output", NULL},
1086 {
"dfn", 0, 0, G_OPTION_ARG_NONE, &display_dfn_ids,
1087 "Include DFN-CERT IDs on vulnerabilities in output", NULL},
1088 {
"oid", 0, 0, G_OPTION_ARG_NONE, &display_oids,
1089 "Include OIDs of NVTs finding vulnerabilities in output", NULL},
1090 {
"descr", 0, 0, G_OPTION_ARG_NONE, &display_descriptions,
1091 "Include descriptions of NVTs finding vulnerabilities in output", NULL},
1092 {
"showlog", 0, 0, G_OPTION_ARG_NONE, &display_log_messages,
1093 "Include log messages in output", NULL},
1094 {
"scanend", 0, 0, G_OPTION_ARG_NONE, &display_scan_end,
1095 "Include timestamp of scan end in output", NULL},
1096 {
"autofp", 0, 0, G_OPTION_ARG_INT, &autofp,
1097 "Trust vendor security updates for automatic false positive filtering (0=No, 1=full match, 2=partial).",
"<n>"},
1098 {
"empty-as-unknown",
'e', 0, G_OPTION_ARG_NONE, &empty_as_unknown,
1099 "Respond with UNKNOWN on empty results", NULL},
1100 {
"use-asset-management",
'A', 0, G_OPTION_ARG_NONE, &use_asset_management,
1101 "Request host status via Asset Management", NULL},
1102 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &rest,
1104 {NULL, 0, 0, 0, NULL, NULL, NULL}
1107 if (setlocale (LC_ALL,
"") == NULL)
1113 g_option_context_new (
"- OpenVAS OMP Command Line Interface");
1114 g_option_context_add_main_entries (option_context, option_entries, NULL);
1115 if (!g_option_context_parse (option_context, &argc, &argv, &error))
1117 printf (
"%s\n\n", error->message);
1120 g_option_context_free (option_context);
1124 printf (
"Check-OMP Nagios Command Plugin %s\n", OPENVASCLI_VERSION);
1125 printf (
"Copyright (C) 2016 Greenbone Networks GmbH\n");
1126 printf (
"License GPLv2+: GNU GPL version 2 or later\n");
1128 (
"This is free software: you are free to change and redistribute it.\n" 1129 "There is NO WARRANTY, to the extent permitted by law.\n\n");
1130 do_exit (EXIT_SUCCESS);
1136 commands = (int) cmd_ping + (
int) cmd_status;
1139 respond (
NAGIOS_UNKNOWN,
"One command option must be present.\n");
1144 respond (
NAGIOS_UNKNOWN,
"Only one command option must be present.\n");
1150 if (!status_trend && !status_last_report)
1151 status_trend = TRUE;
1152 if (status_trend && status_last_report)
1154 respond (
NAGIOS_UNKNOWN,
"--trend and --last-report are exclusive.\n");
1160 connection = g_malloc0 (
sizeof (*connection));
1162 if (manager_host_string != NULL)
1167 if (manager_port <= 0 || manager_port >= 65536)
1170 "Manager port must be a number between 0 and 65536.\n");
1174 connection->
port = manager_port;
1176 if (omp_username != NULL)
1177 connection->
username = omp_username;
1178 if (omp_password != NULL)
1179 connection->
password = omp_password;
1184 "Timeout must be a non-negative number.\n");
1188 connection->
timeout = timeout;
1193 fprintf (stderr,
"Will try to connect to host %s, port %d...\n",
1199 g_log_set_default_handler (openvas_log_silent, NULL);
1208 manager_open (connection);
1214 exit_status = respond (
NAGIOS_OK,
"Alive and kicking!\n");
1228 manager_close (connection);
1230 else if (cmd_status)
1234 if (use_asset_management)
1236 if (host_filter == NULL)
1239 respond (
NAGIOS_UNKNOWN,
"Status request via Asset Management requires host filter\n");
1243 entity_t asset_report;
1244 entity_t host_detail;
1245 entities_t host_details;
1246 gchar *report_id = NULL;
1247 entity_t full_report;
1252 int medium_count = 0;
1255 omp_get_report_opts_t asset_opts = omp_get_report_opts_defaults;
1256 omp_get_report_opts_t report_opts = omp_get_report_opts_defaults;
1258 asset_opts.overrides = overrides_flag;
1259 asset_opts.autofp = autofp;
1260 asset_opts.timeout = timeout;
1261 asset_opts.type =
"assets";
1262 asset_opts.host = host_filter;
1264 manager_open (connection);
1265 res = omp_get_report_ext (&(connection->
session), asset_opts, &asset_report);
1268 asset_report = entity_child (asset_report,
"report");
1269 if (asset_report == NULL)
1271 exit_status = respond (
NAGIOS_UNKNOWN,
"Failed to get first asset report wrapper\n");
1275 asset_report = entity_child (asset_report,
"report");
1276 if (asset_report == NULL)
1278 exit_status = respond (
NAGIOS_UNKNOWN,
"Failed to get first asset report\n");
1282 asset_report = entity_child (asset_report,
"host");
1283 if (asset_report == NULL)
1285 exit_status = respond (
NAGIOS_UNKNOWN,
"Failed to get asset host element\n");
1289 host_details = asset_report->entities;
1290 while ((host_detail = first_entity (host_details)))
1292 if (strcmp (entity_name (host_detail),
"detail") == 0)
1297 name = entity_child (host_detail,
"name");
1298 value = entity_child (host_detail,
"value");
1300 if (strcmp (entity_text (name),
"report/@id") == 0)
1301 report_id = g_strdup (entity_text (value));
1302 if (strcmp (entity_text (name),
"report/result_count/high") == 0)
1303 high_count = atoi (entity_text (value));
1304 if (strcmp (entity_text (name),
"report/result_count/medium") == 0)
1305 medium_count = atoi (entity_text (value));
1306 if (strcmp (entity_text (name),
"report/result_count/low") == 0)
1307 low_count = atoi (entity_text (value));
1309 host_details = next_entities (host_details);
1312 if (report_id == NULL)
1314 exit_status = respond (
NAGIOS_UNKNOWN,
"Failed to get report_id via Asset Management\n");
1318 if ((high_count + medium_count) == 0)
1321 exit_status = respond (response_code,
1322 "%i vulnerabilities found - High: 0 Medium: 0 Low: %i\n",
1323 low_count, low_count);
1326 respond_data (
"https://%s/omp?cmd=get_report&report_id=%s\n",
1327 (gchar *) (gpointer) connection->
host_string, report_id);
1329 if (display_scan_end)
1330 respond_data (
"SCAN_END: %s\n", entity_text (entity_child (asset_report,
"end")));
1332 respond_perf_data (
"|High=%i Medium=%i Low=%i\n",
1333 high_count, medium_count, low_count);
1337 report_opts.report_id = report_id;
1340 status_opts.
dfn_ids = display_dfn_ids;
1341 status_opts.
oids = display_oids;
1343 status_opts.
descr = display_descriptions;
1345 status_opts.
scan_end = display_scan_end;
1346 status_opts.
autofp = autofp;
1347 status_opts.
timeout = timeout;
1350 report_opts.apply_overrides = overrides_flag;
1351 report_opts.autofp = status_opts.
autofp;
1352 report_opts.timeout = status_opts.
timeout;
1354 if (!display_log_messages)
1355 report_opts.levels =
"hml";
1357 res = omp_get_report_ext (&(connection->
session), report_opts, &full_report);
1360 full_report = entity_child (full_report,
"report");
1361 if (full_report == NULL)
1364 "Failed to get first full report wrapper\n");
1368 full_report = entity_child (full_report,
"report");
1369 if (full_report == NULL)
1372 "Failed to get first full report\n");
1377 exit_status = filter_report (full_report, host_filter, status_opts);
1384 "Timeout while getting full report.\n");
1389 "Failed to get full report.\n");
1399 exit_status = respond (
NAGIOS_UNKNOWN,
"Timeout while getting asset report.\n");
1403 exit_status = respond (
NAGIOS_UNKNOWN,
"Failed to get asset report.\n");
1407 else if (task_string == NULL)
1414 manager_open (connection);
1415 omp_get_tasks_opts_t opts;
1418 opts = omp_get_tasks_opts_defaults;
1421 opts.filter = g_strdup_printf (
"permission=any owner=any rows=1 name=\"%s\"", task_string);
1422 opts.timeout = timeout;
1424 if (display_descriptions)
1425 display_oids = TRUE;
1427 if (display_dfn_ids)
1428 display_oids = TRUE;
1431 status_opts.
dfn_ids = display_dfn_ids;
1432 status_opts.
oids = display_oids;
1434 status_opts.
descr = display_descriptions;
1436 status_opts.
scan_end = display_scan_end;
1437 status_opts.
autofp = autofp;
1438 status_opts.
timeout = timeout;
1442 switch (omp_get_tasks_ext (&(connection->
session), opts, &status))
1446 cmd_status_impl (connection, task_string, status->entities,
1452 exit_status = respond (
NAGIOS_UNKNOWN,
"Timeout while getting tasks\n");
1459 manager_close (connection);
1468 if (connection_details)
1471 respond_data (
"GSM_Host: %s:%d\n", connection->
host_string,
1472 (
int) connection->
port);
1474 respond_data (
"OMP_User: %s\n", connection->
username);
1475 if (task_string && cmd_status)
1476 respond_data (
"Task: %s\n", task_string);
1482 respond_data (
"Command failed.\n");
1484 respond_data (
"Command completed successfully.\n");
1487 do_exit (exit_status);
gpointer manager_host
Pointer to name of the manager host for use in the report link.
gchar * password
Password for user with which to connect.
#define STATUS_BY_LAST_REPORT
#define NAGIOS_OK
The plugin was able to contact the OpenVAS Manager. The returned results did not indicate a medium or...
#define OPENVASMD_PORT
Default Manager port.
gboolean log_messages
TRUE if log messages should be included.
Information needed to handle a connection to a server.
gboolean report_link
TRUE if the report URL should be included.
#define OPENVASMD_ADDRESS
Default Manager (openvasmd) address.
Options for status display.
gint timeout
Timeout of request.
gboolean descr
TRUE if NVT descriptions should be included.
guint autofp
Whether to trust vendor security updates. 0 No, 1 full match, 2 partial.
#define NAGIOS_UNKNOWN
The plugin was not able to contact the OpenVAS Manager or was unable to parse the returned results....
gboolean oids
TRUE if NVT OIDs should be included.
gchar * username
Username with which to connect.
gnutls_session_t session
GnuTLS Session to use.
gchar * host_string
Server host string.
#define DEFAULT_SOCKET_TIMEOUT
gint timeout
Timeout of request.
gboolean dfn_ids
TRUE if DFN-CERT-IDs should be included.
#define NAGIOS_CRITICAL
The plugin was able to contact the OpenVAS Manager. The returned results did indicate a high threat o...
gboolean empty_as_unknown
TRUE if empty results should produce an UNKNOWN response instead of OK.
gboolean scan_end
TRUE if the time the scan finished should be included.