Skip to content

Commit

Permalink
Fix: Make report configs optional for new alerts
Browse files Browse the repository at this point in the history
Before trying to get the report configs for new alerts, check if the
get_report_configs command is available.

This prevents errors in case the command is not available.
  • Loading branch information
timopollmeier committed Jul 16, 2024
1 parent 56e015b commit a3ef4ff
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4138,44 +4138,47 @@ new_alert (gvm_connection_t *connection, credentials_t *credentials,

/* Get Report Configs. */

ret = gmp (connection, credentials, &response, &entity, response_data,
"<get_report_configs filter=\"rows=-1\"/>");
switch (ret)
if (command_enabled (credentials, "GET_REPORT_CONFIGS"))
{
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);
ret = gmp (connection, credentials, &response, &entity, response_data,

Check warning on line 4143 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4143

Added line #L4143 was not covered by tests
"<get_report_configs filter=\"rows=-1\"/>");
switch (ret)

Check warning on line 4145 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4145

Added line #L4145 was not covered by tests
{
case 0:

Check warning on line 4147 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4147

Added line #L4147 was not covered by tests
case -1:
break;
case 1:
cmd_response_data_set_status_code (response_data,

Check warning on line 4151 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4149-L4151

Added lines #L4149 - L4151 were not covered by tests
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (

Check warning on line 4153 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4153

Added line #L4153 was not covered by tests
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,

Check warning on line 4160 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4159-L4160

Added lines #L4159 - L4160 were not covered by tests
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (

Check warning on line 4162 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4162

Added line #L4162 was not covered by tests
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,

Check warning on line 4169 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4168-L4169

Added lines #L4168 - L4169 were not covered by tests
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (credentials, "Internal error", __func__, __LINE__,

Check warning on line 4171 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4171

Added line #L4171 was not covered by tests
"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);

Check warning on line 4180 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L4178-L4180

Added lines #L4178 - L4180 were not covered by tests
}
g_string_append (xml, response);
g_free (response);
free_entity (entity);

/* Get Report Filters. */

Expand Down

0 comments on commit a3ef4ff

Please sign in to comment.