Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Added report config options to alerts. #172

Merged
merged 6 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 86 additions & 2 deletions src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4136,6 +4136,47 @@ new_alert (gvm_connection_t *connection, credentials_t *credentials,
g_free (response);
free_entity (entity);

/* Get Report Configs. */

ret = gmp (connection, credentials, &response, &entity, response_data,
"<get_report_configs filter=\"rows=-1\"/>");
switch (ret)
{
case 0:
case -1:
break;
case 1:
cmd_response_data_set_status_code (response_data,
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (
credentials, "Internal error", __func__, __LINE__,
"An internal error occurred while getting Report "
"Configs for new alert. "
"Diagnostics: Failure to send command to manager daemon.",
response_data);
case 2:
cmd_response_data_set_status_code (response_data,
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (
credentials, "Internal error", __func__, __LINE__,
"An internal error occurred while getting Report "
"Configs for new alert. "
"Diagnostics: Failure to receive response from manager daemon.",
response_data);
default:
cmd_response_data_set_status_code (response_data,
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (credentials, "Internal error", __func__, __LINE__,
"An internal error occurred while getting Report "
"Configs for new alert. It is unclear whether"
" the alert has been saved or not. "
"Diagnostics: Internal Error.",
response_data);
}
g_string_append (xml, response);
g_free (response);
free_entity (entity);

/* Get Report Filters. */

ret = gmp (connection, credentials, &response, &entity, response_data,
Expand Down Expand Up @@ -4445,18 +4486,21 @@ append_alert_method_data (GString *xml, params_t *data, const char *method,
|| (strcmp (method, "Send") == 0
&& (strcmp (name, "send_host") == 0
|| strcmp (name, "send_port") == 0
|| strcmp (name, "send_report_config") == 0
|| strcmp (name, "send_report_format") == 0))
|| (strcmp (method, "SCP") == 0
&& (strcmp (name, "scp_credential") == 0
|| strcmp (name, "scp_host") == 0
|| strcmp (name, "scp_known_hosts") == 0
|| strcmp (name, "scp_path") == 0
|| strcmp (name, "scp_port") == 0
|| strcmp (name, "scp_report_config") == 0
|| strcmp (name, "scp_report_format") == 0))
|| (strcmp (method, "SMB") == 0
&& (strcmp (name, "smb_credential") == 0
|| strcmp (name, "smb_file_path") == 0
|| strcmp (name, "smb_max_protocol") == 0
|| strcmp (name, "smb_report_config") == 0
|| strcmp (name, "smb_report_format") == 0
|| strcmp (name, "smb_share_path") == 0))
|| (strcmp (method, "SNMP") == 0
Expand All @@ -4471,6 +4515,7 @@ append_alert_method_data (GString *xml, params_t *data, const char *method,
|| (strcmp (method, "verinice Connector") == 0
&& (strcmp (name, "verinice_server_credential") == 0
|| strcmp (name, "verinice_server_url") == 0
|| strcmp (name, "verinice_server_report_config") == 0
|| strcmp (name, "verinice_server_report_format") == 0))
|| (strcmp (method, "Alemba vFire") == 0
&& (strcmp (name, "vfire_base_url") == 0
Expand All @@ -4490,8 +4535,12 @@ append_alert_method_data (GString *xml, params_t *data, const char *method,
|| strcmp (name, "notice") == 0
|| (strcmp (name, "notice_report_format") == 0
&& notice == 0)
|| (strcmp (name, "notice_report_config") == 0
&& notice == 0)
|| (strcmp (name, "notice_attach_format") == 0
&& notice == 2)
|| (strcmp (name, "notice_attach_config") == 0
&& notice == 2)
|| (str_equal (name, "recipient_credential")
&& !str_equal (param->value, "0"))))
|| (strcmp (method, "Syslog") == 0
Expand All @@ -4504,8 +4553,10 @@ append_alert_method_data (GString *xml, params_t *data, const char *method,
|| strcmp (name, "composer_include_notes") == 0
|| strcmp (name, "composer_include_overrides") == 0
|| strcmp (name, "composer_ignore_pagination") == 0)
xml_string_append (xml, "<data><name>%s</name>%s</data>", name,
param->value ? param->value : "");
{
xml_string_append (xml, "<data><name>%s</name>%s</data>", name,
param->value ? param->value : "");
}
else if (strcmp (method, "Email") == 0 && notice == 0
&& strcmp (name, "message") == 0)
xml_string_append (xml, "<data><name>message</name>%s</data>",
Expand Down Expand Up @@ -4870,6 +4921,39 @@ edit_alert (gvm_connection_t *connection, credentials_t *credentials,
}
}

if (command_enabled (credentials, "GET_REPORT_CONFIGS"))
{
/* Get the report configs. */

if (gvm_connection_sendf (connection, "<get_report_configs"
" filter=\"rows=-1\"/>")
== -1)
{
g_string_free (xml, TRUE);
cmd_response_data_set_status_code (response_data,
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (
credentials, "Internal error", __func__, __LINE__,
"An internal error occurred while getting report configs. "
"The current list of report configs is not available. "
"Diagnostics: Failure to send command to manager daemon.",
response_data);
}

if (read_string_c (connection, &xml))
{
g_string_free (xml, TRUE);
cmd_response_data_set_status_code (response_data,
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (
credentials, "Internal error", __func__, __LINE__,
"An internal error occurred while getting report configs. "
"The current list of report configs is not available. "
"Diagnostics: Failure to receive response from manager daemon.",
response_data);
}
}

if (command_enabled (credentials, "GET_FILTERS"))
{
/* Get filters. */
Expand Down
Loading