From aade60a7745d28a572b22f03f4437ad832c789dd Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 14 Nov 2016 15:57:32 +0000 Subject: [Feature] Add errors exporter to the controller --- src/controller.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/controller.c b/src/controller.c index da0f44dce..c2a486666 100644 --- a/src/controller.c +++ b/src/controller.c @@ -56,7 +56,7 @@ #define PATH_STAT "/stat" #define PATH_STAT_RESET "/statreset" #define PATH_COUNTERS "/counters" - +#define PATH_ERRORS "/errors" #define msg_err_session(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \ session->pool->tag.tagname, session->pool->tag.uid, \ @@ -1364,6 +1364,36 @@ rspamd_controller_handle_history (struct rspamd_http_connection_entry *conn_ent, return 0; } +/* + * Errors command handler: + * request: /errors + * headers: Password + * reply: json [ + * { ts: 100500, type: normal, pid: 100, module: lua, message: bad things }, + * {...} + * ] + */ +static int +rspamd_controller_handle_errors (struct rspamd_http_connection_entry *conn_ent, + struct rspamd_http_message *msg) +{ + struct rspamd_controller_session *session = conn_ent->ud; + struct rspamd_controller_worker_ctx *ctx; + ucl_object_t *top; + + ctx = session->ctx; + + if (!rspamd_controller_check_password (conn_ent, session, msg, TRUE)) { + return 0; + } + + top = rspamd_log_errorbuf_export (ctx->worker->srv->logger); + rspamd_controller_send_ucl (conn_ent, top); + ucl_object_unref (top); + + return 0; +} + static int rspamd_controller_handle_history_reset (struct rspamd_http_connection_entry *conn_ent, struct rspamd_http_message *msg) @@ -3113,6 +3143,9 @@ start_controller_worker (struct rspamd_worker *worker) rspamd_http_router_add_path (ctx->http, PATH_COUNTERS, rspamd_controller_handle_counters); + rspamd_http_router_add_path (ctx->http, + PATH_ERRORS, + rspamd_controller_handle_errors); rspamd_regexp_t *lua_re = rspamd_regexp_new ("^/.*/.*\\.lua$", NULL, NULL); rspamd_http_router_add_regexp (ctx->http, lua_re, -- cgit v1.2.3