From 1cb2783106d3efcac730d5ad60b8515a7a910614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 5 May 2017 11:59:46 +0300 Subject: [PATCH] MXS-1220: Implement /maxscale/logs resource The /maxscale/logs resource exposes information about the state of logging in MaxScale. --- include/maxscale/log_manager.h | 4 ++++ server/core/log_manager.cc | 31 ++++++++++++++++++++++++++++--- server/core/resource.cc | 3 +-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/include/maxscale/log_manager.h b/include/maxscale/log_manager.h index 329155dc7..fe39cc049 100644 --- a/include/maxscale/log_manager.h +++ b/include/maxscale/log_manager.h @@ -13,11 +13,14 @@ */ #include + #include #include #include #include +#include + MXS_BEGIN_DECLS /** @@ -105,6 +108,7 @@ void mxs_log_set_augmentation(int bits); void mxs_log_set_throttling(const MXS_LOG_THROTTLING* throttling); void mxs_log_get_throttling(MXS_LOG_THROTTLING* throttling); +json_t* mxs_logs_to_json(const char* host); static inline bool mxs_log_priority_is_enabled(int priority) { diff --git a/server/core/log_manager.cc b/server/core/log_manager.cc index da9583749..b9119769c 100644 --- a/server/core/log_manager.cc +++ b/server/core/log_manager.cc @@ -11,10 +11,10 @@ * Public License. */ #include + #include #include #include - #include #include #include @@ -23,14 +23,17 @@ #include #include #include -#include -#include +#include +#include +#include #include +#include #include #include #include #include + #include "maxscale/mlist.h" #define MAX_PREFIXLEN 250 @@ -3013,3 +3016,25 @@ const char* mxs_strerror(int error) return strerror_r(error, errbuf, sizeof(errbuf)); } + +json_t* mxs_logs_to_json(const char* host) +{ + json_t* attr = json_object(); + json_object_set_new(attr, "highprecision", json_boolean(log_config.do_highprecision)); + json_object_set_new(attr, "maxlog", json_boolean(log_config.do_maxlog)); + json_object_set_new(attr, "syslog", json_boolean(log_config.do_syslog)); + + json_t* throttling = json_object(); + json_object_set_new(throttling, "count", json_integer(log_config.throttling.count)); + json_object_set_new(throttling, "suppress_ms", json_integer(log_config.throttling.suppress_ms)); + json_object_set_new(throttling, "window_ms", json_integer(log_config.throttling.window_ms)); + + json_object_set_new(attr, "throttling", throttling); + + json_t* data = json_object(); + json_object_set_new(data, CN_ATTRIBUTES, attr); + json_object_set_new(data, CN_ID, json_string("logs")); + json_object_set_new(data, CN_TYPE, json_string("logs")); + + return mxs_json_resource(host, MXS_JSON_API_LOGS, data); +} diff --git a/server/core/resource.cc b/server/core/resource.cc index 343ecb7a4..70e8207fa 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -359,8 +359,7 @@ HttpResponse cb_maxscale(const HttpRequest& request) HttpResponse cb_logs(const HttpRequest& request) { - // TODO: Show logs - return HttpResponse(MHD_HTTP_OK, mxs_json_resource(request.host(), MXS_JSON_API_LOGS, json_null())); + return HttpResponse(MHD_HTTP_OK, mxs_logs_to_json(request.host())); } HttpResponse cb_flush(const HttpRequest& request)