diff --git a/src/gmp.c b/src/gmp.c index 5af16cb1c..1d24f2fa2 100644 --- a/src/gmp.c +++ b/src/gmp.c @@ -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. * @@ -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, diff --git a/src/manage.h b/src/manage.h index 03a11b83d..903ed7053 100644 --- a/src/manage.h +++ b/src/manage.h @@ -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); diff --git a/src/manage_sql.c b/src/manage_sql.c index e5127b647..09e1fdfa7 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -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;", @@ -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 */ @@ -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 */