Skip to content

Commit

Permalink
Fix: The number of results in triggered alerts. (#1895) (#1896)
Browse files Browse the repository at this point in the history
* Fixed the number of results in triggered alerts.

Now the number of results for automatically triggered alerts and
manually triggered alerts are the same.

* Fixed small memory bug.

* Use selected report for manually triggered alert.

Now the selected report is used for the manually triggered alert.
Previously only the latest report (not the selected one) was used
for the alert.

* Refactoring of the first solution.

* Added the header comment for the function "init_alert_get_data".

(cherry picked from commit ea67ea3)

Co-authored-by: Johannes Helmold <83279292+jhelmold@users.noreply.github.com>
  • Loading branch information
mergify[bot] and jhelmold authored Jan 13, 2023
1 parent dd22e5d commit f3e6f5e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
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

0 comments on commit f3e6f5e

Please sign in to comment.