59 #include <openvas/misc/openvas_server.h> 64 #include <openvas/misc/openvas_logging.h> 66 #include <openvas/omp/omp.h> 71 #define OMP_PROGNAME "check_omp" 76 #define OPENVASMD_ADDRESS "127.0.0.1" 81 #define OPENVASMD_PORT 9390 84 #define DEFAULT_SOCKET_TIMEOUT 10 102 #define NAGIOS_WARNING 1 108 #define NAGIOS_CRITICAL 2 115 #define NAGIOS_UNKNOWN 3 117 #define NAGIOS_DEPENDENT 4 127 gnutls_session_t session;
157 __attribute__ ((__noreturn__));
165 static int warnings_are_errors;
168 static gint overrides_flag;
173 static int pipe_symbol_substituted;
179 print_respond_string (
const char *
string)
183 for (s =
string; *s; s++)
188 pipe_symbol_substituted = 1;
199 respond (
int code,
const char *format, ...)
217 status = warnings_are_errors ?
"CRITICAL" :
"UNKNOWN";
220 status =
"DEPENDENT";
223 fputs (
"OMP UNKNOWN: Internal plugin error\n", stdout);
227 va_start (arg_ptr, format);
228 buf = g_strdup_vprintf (format, arg_ptr);
230 printf (
"OMP %s: ", status);
231 print_respond_string (buf);
232 if (!*buf || buf[strlen (buf) - 1] !=
'\n')
242 respond_data (
const char *format, ...)
247 va_start (arg_ptr, format);
248 buf = g_strdup_vprintf (format, arg_ptr);
250 print_respond_string (buf);
251 if (!*buf || buf[strlen (buf) - 1] !=
'\n')
258 respond_perf_data (
const char *format, ...)
263 if (pipe_symbol_substituted)
264 fputs (
"Note: pipe symbol(s) (U+007C) substituted" 265 " by broken bar (U+00A6).\n", stdout);
267 va_start (arg_ptr, format);
268 buf = g_strdup_vprintf (format, arg_ptr);
271 if (!*buf || buf[strlen (buf) - 1] !=
'\n')
309 if (connection->
socket == -1)
311 do_exit (respond (
NAGIOS_UNKNOWN,
"Failed to acquire socket.\n"));
316 omp_authenticate_info_opts_t authenticate_opts;
317 gchar *timezone, *role, *severity, *pw_warning;
319 authenticate_opts = omp_authenticate_info_opts_defaults;
321 authenticate_opts.timeout = connection->
timeout;
322 authenticate_opts.username = connection->
username;
323 authenticate_opts.password = connection->
password;
324 authenticate_opts.timezone = &timezone;
325 authenticate_opts.role = &role;
326 authenticate_opts.severity = &severity;
327 authenticate_opts.pw_warning = &pw_warning;
329 switch (omp_authenticate_info_ext (&connection->
session,
335 openvas_server_close (connection->
socket, connection->
session);
337 "Timeout while trying to authenticate.\n"));
340 openvas_server_close (connection->
socket, connection->
session);
346 g_free (*authenticate_opts.timezone);
347 g_free (*authenticate_opts.role);
348 g_free (*authenticate_opts.severity);
349 g_free (*authenticate_opts.pw_warning);
363 return openvas_server_close (server->
socket, server->
session);
367 #define STATUS_BY_TREND 1 368 #define STATUS_BY_LAST_REPORT 2 371 filter_report (entity_t report,
const char *host_filter,
380 int medium_count = 0;
385 GPtrArray *high_oids = NULL;
386 GPtrArray *medium_oids = NULL;
387 GPtrArray *low_oids = NULL;
388 GPtrArray *log_oids = NULL;
389 GPtrArray *high_names = NULL;
390 GPtrArray *medium_names = NULL;
391 GPtrArray *low_names = NULL;
392 GPtrArray *log_names = NULL;
393 GPtrArray *high_descriptions = NULL;
394 GPtrArray *medium_descriptions = NULL;
395 GPtrArray *low_descriptions = NULL;
396 GPtrArray *log_descriptions = NULL;
397 GPtrArray *high_dfn_ids_array = NULL;
398 GPtrArray *medium_dfn_ids_array = NULL;
399 GPtrArray *low_dfn_ids_array = NULL;
400 GPtrArray *log_dfn_ids_array = NULL;
401 GPtrArray *high_dfn_ids = NULL;
402 GPtrArray *medium_dfn_ids = NULL;
403 GPtrArray *low_dfn_ids = NULL;
404 GPtrArray *log_dfn_ids = NULL;
406 results = entity_child (report,
"results");
412 if (status_opts.
oids)
414 high_oids = g_ptr_array_new ();
415 medium_oids = g_ptr_array_new ();
416 low_oids = g_ptr_array_new ();
417 log_oids = g_ptr_array_new ();
418 high_names = g_ptr_array_new ();
419 medium_names = g_ptr_array_new ();
420 low_names = g_ptr_array_new ();
421 log_names = g_ptr_array_new ();
422 high_descriptions = g_ptr_array_new ();
423 medium_descriptions = g_ptr_array_new ();
424 low_descriptions = g_ptr_array_new ();
425 log_descriptions = g_ptr_array_new ();
426 high_dfn_ids = g_ptr_array_new ();
427 medium_dfn_ids = g_ptr_array_new ();
428 low_dfn_ids = g_ptr_array_new ();
429 log_dfn_ids = g_ptr_array_new ();
434 high_oids = medium_oids = low_oids = log_oids = NULL;
435 high_names = medium_names = low_names = log_names = NULL;
436 high_descriptions = medium_descriptions = NULL;
437 low_descriptions = log_descriptions = NULL;
440 elems = results->entities;
441 while ((elem = first_entity (elems)))
443 if (strcmp (entity_name (elem),
"result") == 0)
446 const char *host, *threat;
448 entity = entity_child (elem,
"host");
452 "Failed to parse result host.\n");
454 host = entity_text (entity);
457 if (host_filter != NULL)
458 if (strcmp (host, host_filter))
459 goto skip_one_filter_report;
462 entity = entity_child (elem,
"threat");
466 "Failed to parse result threat.\n");
468 threat = entity_text (entity);
469 if (!strcmp (threat,
"High"))
472 if (status_opts.
oids)
474 g_ptr_array_add (high_oids,
476 entity_attribute (entity_child (elem,
"nvt"),
478 g_ptr_array_add (high_names,
480 entity_text (entity_child (entity_child (elem,
"nvt"),
"name")));
481 g_ptr_array_add (high_descriptions,
483 entity_text (entity_child (elem,
"description")));
485 high_dfn_ids_array = NULL;
486 entity_t cert_entity = entity_child (entity_child (elem,
"nvt"),
"cert");
487 entities_t cert_refs = cert_entity->entities;
488 if (cert_refs != NULL)
491 while ((cert_ref = first_entity(cert_refs))) {
492 if (strcmp (entity_attribute (cert_ref,
"type"),
"DFN-CERT") == 0)
494 if (high_dfn_ids_array == NULL)
495 high_dfn_ids_array = g_ptr_array_new ();
496 g_ptr_array_add (high_dfn_ids_array,
498 entity_attribute (cert_ref,
"id"));
500 cert_refs = next_entities (cert_refs);
502 g_ptr_array_add (high_dfn_ids,
508 g_ptr_array_add (high_dfn_ids, NULL);
513 else if (!strcmp (threat,
"Medium"))
516 if (status_opts.
oids)
518 g_ptr_array_add (medium_oids,
520 entity_attribute (entity_child (elem,
"nvt"),
522 g_ptr_array_add (medium_names,
524 entity_text (entity_child (entity_child (elem,
"nvt"),
"name")));
525 g_ptr_array_add (medium_descriptions,
527 entity_text (entity_child (elem,
"description")));
529 medium_dfn_ids_array = NULL;
530 entity_t cert_entity = entity_child (entity_child (elem,
"nvt"),
"cert");
531 entities_t cert_refs = cert_entity->entities;
532 if (cert_refs != NULL)
535 while ((cert_ref = first_entity(cert_refs))) {
536 if (strcmp (entity_attribute (cert_ref,
"type"),
"DFN-CERT") == 0)
538 if (medium_dfn_ids_array == NULL)
539 medium_dfn_ids_array = g_ptr_array_new ();
540 g_ptr_array_add (medium_dfn_ids_array,
542 entity_attribute (cert_ref,
"id"));
544 cert_refs = next_entities (cert_refs);
546 g_ptr_array_add (medium_dfn_ids,
548 medium_dfn_ids_array);
552 g_ptr_array_add (medium_dfn_ids, NULL);
557 else if (!strcmp (threat,
"Low"))
560 if (status_opts.
oids)
562 g_ptr_array_add (low_oids,
564 entity_attribute (entity_child (elem,
"nvt"),
566 g_ptr_array_add (low_names,
568 entity_text (entity_child (entity_child (elem,
"nvt"),
"name")));
569 g_ptr_array_add (low_descriptions,
571 entity_text (entity_child (elem,
"description")));
573 low_dfn_ids_array = NULL;
574 entity_t cert_entity = entity_child (entity_child (elem,
"nvt"),
"cert");
575 entities_t cert_refs = cert_entity->entities;
576 if (cert_refs != NULL)
579 while ((cert_ref = first_entity(cert_refs))) {
580 if (strcmp (entity_attribute (cert_ref,
"type"),
"DFN-CERT") == 0)
582 if (low_dfn_ids_array == NULL)
583 low_dfn_ids_array = g_ptr_array_new ();
584 g_ptr_array_add (low_dfn_ids_array,
586 entity_attribute (cert_ref,
"id"));
588 cert_refs = next_entities (cert_refs);
590 g_ptr_array_add (low_dfn_ids,
596 g_ptr_array_add (low_dfn_ids, NULL);
601 else if (!strcmp (threat,
"Log"))
604 if (status_opts.
oids)
606 g_ptr_array_add (log_oids,
608 entity_attribute (entity_child (elem,
"nvt"),
610 g_ptr_array_add (log_names,
612 entity_text (entity_child (entity_child (elem,
"nvt"),
"name")));
613 g_ptr_array_add (log_descriptions,
615 entity_text (entity_child (elem,
"description")));
617 log_dfn_ids_array = NULL;
618 entity_t cert_entity = entity_child (entity_child (elem,
"nvt"),
"cert");
619 entities_t cert_refs = cert_entity->entities;
620 if (cert_refs != NULL)
623 while ((cert_ref = first_entity(cert_refs))) {
624 if (strcmp (entity_attribute (cert_ref,
"type"),
"DFN-CERT") == 0)
626 if (log_dfn_ids_array == NULL)
627 log_dfn_ids_array = g_ptr_array_new ();
628 g_ptr_array_add (log_dfn_ids_array,
630 entity_attribute (cert_ref,
"id"));
632 cert_refs = next_entities (cert_refs);
634 g_ptr_array_add (log_dfn_ids,
640 g_ptr_array_add (log_dfn_ids, NULL);
651 skip_one_filter_report:
652 elems = next_entities (elems);
655 errors = entity_child (report,
"errors");
660 entities_t error_elements;
661 entity_t error_element;
663 error_elements = errors->entities;
664 while ((error_element = first_entity (error_elements)))
666 if (strcmp (entity_name (error_element),
"error") == 0)
670 error_host = entity_child (error_element,
"host");
671 if (strcmp (entity_text (error_host), host_filter) == 0)
674 error_elements = next_entities (error_elements);
679 entity_t count_child;
680 const char *error_text;
682 count_child = entity_child (errors,
"count");
683 error_text = entity_text (count_child);
684 error_count = atoi (error_text);
692 else if (medium_count > 0)
697 if ((results->entities == NULL) || (!any_found && host_filter))
703 if ((error_count > 0) && (response_code ==
NAGIOS_OK))
708 respond (response_code,
"%i vulnerabilities found - High: %i Medium: %i Low: %i\n",
709 (high_count + medium_count + low_count), high_count, medium_count, low_count);
711 if (results->entities == NULL)
712 respond_data (
"Report did not contain any vulnerabilities");
713 else if (!any_found && host_filter)
714 respond_data (
"Report did not contain vulnerabilities for IP %s\n", host_filter);
720 respond_data (
"Report did contain %i errors for IP %s\n", error_count, host_filter);
724 respond_data (
"Report did contain %i errors\n", error_count);
729 respond_data (
"https://%s/omp?cmd=get_report&report_id=%s\n",
730 (gchar *) status_opts.
manager_host, entity_attribute (report,
733 if (status_opts.
oids)
737 for (i = 0; i < high_count; i++)
739 respond_data (
"NVT: %s (High) (%s)\n",
740 (
char *) g_ptr_array_index (high_oids, i),
741 (
char *) g_ptr_array_index (high_names, i));
742 if (status_opts.
descr)
743 respond_data (
"DESCR: %s\n",
744 (
char *) g_ptr_array_index (high_descriptions, i));
745 if (status_opts.
dfn_ids && (g_ptr_array_index (high_dfn_ids, i) != NULL))
747 GPtrArray *dfn_ids_array = (GPtrArray *) g_ptr_array_index (high_dfn_ids, i);
748 GString *dfn_ids_string = NULL;
749 for (j = 0; j < dfn_ids_array->len; j++)
751 if (dfn_ids_string == NULL)
753 dfn_ids_string = g_string_new ((
char *) g_ptr_array_index (dfn_ids_array, j));
757 g_string_append (dfn_ids_string, (
char *) g_ptr_array_index (dfn_ids_array, j));
759 if (j < dfn_ids_array->len - 1)
761 g_string_append (dfn_ids_string,
", ");
764 respond_data (
"DFN-CERT: %s\n", dfn_ids_string->str);
765 g_string_free (dfn_ids_string, FALSE);
769 for (i = 0; i < medium_count; i++)
771 respond_data (
"NVT: %s (Medium) (%s)\n",
772 (
char *) g_ptr_array_index (medium_oids, i),
773 (
char *) g_ptr_array_index (medium_names, i));
774 if (status_opts.
descr)
775 respond_data (
"DESCR: %s\n",
776 (
char *) g_ptr_array_index (medium_descriptions, i));
777 if (status_opts.
dfn_ids && (g_ptr_array_index (medium_dfn_ids, i) != NULL))
779 GPtrArray *dfn_ids_array = (GPtrArray *) g_ptr_array_index (medium_dfn_ids, i);
780 GString *dfn_ids_string = NULL;
781 for (j = 0; j < dfn_ids_array->len; j++)
783 if (dfn_ids_string == NULL)
785 dfn_ids_string = g_string_new ((
char *) g_ptr_array_index (dfn_ids_array, j));
789 g_string_append (dfn_ids_string, (
char *) g_ptr_array_index (dfn_ids_array, j));
791 if (j < dfn_ids_array->len - 1)
793 g_string_append (dfn_ids_string,
", ");
796 respond_data (
"DFN-CERT: %s\n", dfn_ids_string->str);
797 g_string_free (dfn_ids_string, FALSE);
801 for (i = 0; i < low_count; i++)
803 respond_data (
"NVT: %s (Low) (%s)\n",
804 (
char *) g_ptr_array_index (low_oids, i),
805 (
char *) g_ptr_array_index (low_names, i));
806 if (status_opts.
descr)
807 respond_data (
"DESCR: %s\n",
808 (
char *) g_ptr_array_index (low_descriptions, i));
809 if (status_opts.
dfn_ids && (g_ptr_array_index (low_dfn_ids, i) != NULL))
811 GPtrArray *dfn_ids_array = (GPtrArray *) g_ptr_array_index (low_dfn_ids, i);
812 GString *dfn_ids_string = NULL;
813 for (j = 0; j < dfn_ids_array->len; j++)
815 if (dfn_ids_string == NULL)
817 dfn_ids_string = g_string_new ((
char *) g_ptr_array_index (dfn_ids_array, j));
821 g_string_append (dfn_ids_string, (
char *) g_ptr_array_index (dfn_ids_array, j));
823 if (j < dfn_ids_array->len - 1)
825 g_string_append (dfn_ids_string,
", ");
828 respond_data (
"DFN-CERT: %s\n", dfn_ids_string->str);
829 g_string_free (dfn_ids_string, FALSE);
834 for (i = 0; i < log_count; i++)
836 respond_data (
"NVT: %s (Log) (%s)\n",
837 (
char *) g_ptr_array_index (log_oids, i),
838 (
char *) g_ptr_array_index (log_names, i));
839 if (status_opts.
descr)
840 respond_data (
"DESCR: %s\n",
841 (
char *) g_ptr_array_index (log_descriptions, i));
842 if (status_opts.
dfn_ids && (g_ptr_array_index (log_dfn_ids, i) != NULL))
844 GPtrArray *dfn_ids_array = (GPtrArray *) g_ptr_array_index (log_dfn_ids, i);
845 GString *dfn_ids_string = NULL;
846 for (j = 0; j < dfn_ids_array->len; j++)
848 if (dfn_ids_string == NULL)
850 dfn_ids_string = g_string_new ((
char *) g_ptr_array_index (dfn_ids_array, j));
854 g_string_append (dfn_ids_string, (
char *) g_ptr_array_index (dfn_ids_array, j));
856 if (j < dfn_ids_array->len - 1)
858 g_string_append (dfn_ids_string,
", ");
861 respond_data (
"DFN-CERT: %s\n", dfn_ids_string->str);
862 g_string_free (dfn_ids_string, FALSE);
866 g_ptr_array_free (high_oids, TRUE);
867 g_ptr_array_free (medium_oids, TRUE);
868 g_ptr_array_free (low_oids, TRUE);
869 g_ptr_array_free (log_oids, TRUE);
870 g_ptr_array_free (high_names, TRUE);
871 g_ptr_array_free (medium_names, TRUE);
872 g_ptr_array_free (low_names, TRUE);
873 g_ptr_array_free (log_names, TRUE);
874 g_ptr_array_free (high_descriptions, TRUE);
875 g_ptr_array_free (medium_descriptions, TRUE);
876 g_ptr_array_free (low_descriptions, TRUE);
877 g_ptr_array_free (log_descriptions, TRUE);
878 g_ptr_array_free (high_dfn_ids, TRUE);
879 g_ptr_array_free (medium_dfn_ids, TRUE);
880 g_ptr_array_free (low_dfn_ids, TRUE);
881 g_ptr_array_free (log_dfn_ids, TRUE);
885 respond_data (
"SCAN_END: %s\n", entity_text (entity_child (report,
"scan_end")));
887 respond_perf_data (
"|High=%i Medium=%i Low=%i\n",
888 high_count, medium_count, low_count);
889 return response_code;
900 entities_t tasks,
int mode,
char *host_filter,
904 while ((task = first_entity (tasks)))
906 if (strcmp (entity_name (task),
"task") == 0)
908 entity_t entity, report;
915 entity = entity_child (task,
"trend");
918 "Failed to parse task trend.\n");
920 trend = entity_text (entity);
922 if (!strcmp (trend,
"up") || !strcmp (trend,
"more"))
926 else if (!strcmp (trend,
"down") || !strcmp (trend,
"same")
927 || !strcmp (trend,
"less"))
929 return respond (
NAGIOS_OK,
"Trend is %s\n", trend);
931 else if (!strcmp (trend,
""))
937 return (respond (
NAGIOS_UNKNOWN,
"Trend is unknown: %s\n", trend));
943 entity_t full_report;
944 omp_get_report_opts_t opts = omp_get_report_opts_defaults;
946 report = entity_child (task,
"last_report");
950 report = entity_child (report,
"report");
953 "Failed to parse last_report\n");
955 opts.report_id = entity_attribute (report,
"id");
956 if (opts.report_id == NULL)
959 "Failed to parse last_report's " 963 opts.apply_overrides = overrides_flag;
964 opts.autofp = status_opts.
autofp;
965 opts.timeout = status_opts.
timeout;
967 switch (omp_get_report_ext (&(connection->
session), opts, &full_report))
973 "Timeout while getting full report.\n");
976 "Failed to get full report.\n");
979 full_report = entity_child (full_report,
"report");
980 if (full_report == NULL)
982 "Failed to get first full report wrapper\n");
984 full_report = entity_child (full_report,
"report");
985 if (full_report == NULL)
987 "Failed to get first full report\n");
989 return filter_report (full_report, host_filter, status_opts);
998 tasks = next_entities (tasks);
1001 return respond (
NAGIOS_UNKNOWN,
"Unknown task: %s\n", task_filter);
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.
#define NAGIOS_WARNING
The plugin was able to contact the OpenVAS Manager. The returned results did indicate a medium threat...
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.
int socket
Socket to server.
int main(int argc, char **argv)
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.