diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-07-21 11:04:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-21 11:04:36 +0100 |
commit | 91132dd0c187bd422c159ad3f0656e476f99a9b2 (patch) | |
tree | 3e23b01ff6832e7fcf03f8bc8a045466bd6b1b5f /src | |
parent | f1a26377afd6dafb381cc00a65e509eed1ce61cc (diff) | |
parent | 32a6adb5bf6dc5b42b08768a6f7470dfdc31fbdb (diff) | |
download | rspamd-91132dd0c187bd422c159ad3f0656e476f99a9b2.tar.gz rspamd-91132dd0c187bd422c159ad3f0656e476f99a9b2.zip |
Merge pull request #3788 from mrueg/healthcheck
Add health and readiness checks
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.c | 48 | ||||
-rw-r--r-- | src/libserver/cfg_file.h | 5 |
2 files changed, 51 insertions, 2 deletions
diff --git a/src/controller.c b/src/controller.c index e62e42e00..161ab8f1a 100644 --- a/src/controller.c +++ b/src/controller.c @@ -46,11 +46,13 @@ #define PATH_GET_MAP "/getmap" #define PATH_GRAPH "/graph" #define PATH_PIE_CHART "/pie" +#define PATH_HEALTHY "/healthy" #define PATH_HISTORY "/history" #define PATH_HISTORY_RESET "/historyreset" #define PATH_LEARN_SPAM "/learnspam" #define PATH_LEARN_HAM "/learnham" #define PATH_METRICS "/metrics" +#define PATH_READY "/ready" #define PATH_SAVE_ACTIONS "/saveactions" #define PATH_SAVE_SYMBOLS "/savesymbols" #define PATH_SAVE_MAP "/savemap" @@ -1580,6 +1582,46 @@ err: } /* + * Healthy command handler: + * request: /healthy + * headers: Password + * reply: json {"success":true} + */ +static int +rspamd_controller_handle_healthy (struct rspamd_http_connection_entry *conn_ent, + struct rspamd_http_message *msg) +{ + struct rspamd_controller_session *session = conn_ent->ud; + + if (!rspamd_controller_check_password (conn_ent, session, msg, FALSE)) { + return 0; + } + + rspamd_controller_send_string (conn_ent, "{\"success\":true}"); + return 0; +} + +/* + * Ready command handler: + * request: /ready + * headers: Password + * reply: json {"success":true} or {"error":"error message"} + */ +static int +rspamd_controller_handle_ready (struct rspamd_http_connection_entry *conn_ent, + struct rspamd_http_message *msg) +{ + struct rspamd_controller_session *session = conn_ent->ud; + + if (!rspamd_controller_check_password (conn_ent, session, msg, FALSE)) { + return 0; + } + + rspamd_controller_send_string (conn_ent, "{\"success\":true}"); + return 0; +} + +/* * History command handler: * request: /history * headers: Password @@ -3895,6 +3937,12 @@ start_controller_worker (struct rspamd_worker *worker) PATH_GRAPH, rspamd_controller_handle_graph); rspamd_http_router_add_path (ctx->http, + PATH_HEALTHY, + rspamd_controller_handle_healthy); + rspamd_http_router_add_path (ctx->http, + PATH_READY, + rspamd_controller_handle_ready); + rspamd_http_router_add_path (ctx->http, PATH_HISTORY, rspamd_controller_handle_history); rspamd_http_router_add_path (ctx->http, diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 6ee407332..4d865e273 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -481,12 +481,13 @@ struct rspamd_config { GList *classify_headers; /**< list of headers using for statistics */ struct module_s **compiled_modules; /**< list of compiled C modules */ - struct worker_s **compiled_workers; /**< list of compiled C modules */struct rspamd_log_format *log_format; /**< parsed log format */ + struct worker_s **compiled_workers; /**< list of compiled C modules */ + struct rspamd_log_format *log_format; /**< parsed log format */ gchar *log_format_str; /**< raw log format string */ struct rspamd_external_libs_ctx *libs_ctx; /**< context for external libraries */ struct rspamd_monitored_ctx *monitored_ctx; /**< context for monitored resources */ - struct rspamd_redis_pool *redis_pool; /**< redis connectiosn pool */ + struct rspamd_redis_pool *redis_pool; /**< redis connection pool */ struct rspamd_re_cache *re_cache; /**< static regexp cache */ |