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

Fixed the number of results in triggered alerts. (backport #1895) #1896

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
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
38 changes: 36 additions & 2 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13977,6 +13977,41 @@ handle_get_preferences (gmp_parser_t *gmp_parser, GError **error)
set_client_state (CLIENT_AUTHENTIC);
}

/**
* @brief Init some data of the get_data_t structure of an alert.
*
* @param[in] alert_id Id of the alert the get_data_t structure
* belongs to.
* @param[in] get The get_data_t structure where some components
* are to be initialized
*/
static void
init_alert_get_data(const char *alert_id, get_data_t *get)
{
alert_t alert = 0;
alert_method_t method;
char *to_free;

/* Always enable details when using a report to test an alert. */
get->details = 1;
get->ignore_pagination = 0;

if (get->filter == NULL)
return;
if (strstr(get->filter, " rows="))
return;
if (find_alert_with_permission (alert_id, &alert, "get_alerts"))
return;
if (alert == 0)
return;

method = alert_method (alert);
to_free = get->filter;
get->filter = g_strdup_printf ("%s rows=%d", get->filter,
method == ALERT_METHOD_EMAIL ? 1000 : -1);
g_free(to_free);
}

/**
* @brief Handle end of GET_REPORTS element.
*
Expand Down Expand Up @@ -14377,9 +14412,8 @@ handle_get_reports (gmp_parser_t *gmp_parser, GError **error)
if (request_report)
cleanup_iterator (&reports);

/* Always enable details when using a report to test an alert. */
if (get_reports_data->alert_id)
get_reports_data->get.details = 1;
init_alert_get_data(get_reports_data->alert_id, &get_reports_data->get);

ret = manage_send_report (report,
delta_report,
Expand Down
3 changes: 3 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ event_name (event_t);
gchar*
event_description (event_t, const void *, const char *);

alert_method_t
alert_method (alert_t alert);

const char*
alert_method_name (alert_method_t);

Expand Down
6 changes: 3 additions & 3 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -8047,7 +8047,7 @@ alert_condition (alert_t alert)
*
* @return Method.
*/
static alert_method_t
alert_method_t
alert_method (alert_t alert)
{
return sql_int ("SELECT method FROM alerts WHERE id = %llu;",
Expand Down Expand Up @@ -12580,7 +12580,7 @@ escalate_2 (alert_t alert, task_t task, report_t report, event_t event,
* anyway, to make it easier for the compiler to see. */
filter = 0;
ret = report_content_for_alert
(alert, 0, task, get,
(alert, report, task, get,
"notice_report_format",
NULL,
/* TXT fallback */
Expand Down Expand Up @@ -12660,7 +12660,7 @@ escalate_2 (alert_t alert, task_t task, report_t report, event_t event,
* anyway, to make it easier for the compiler to see. */
filter = 0;
ret = report_content_for_alert
(alert, 0, task, get,
(alert, report, task, get,
"notice_attach_format",
NULL,
/* TXT fallback */
Expand Down