diff --git a/deps/rabbitmq_management/priv/www/api/index.html b/deps/rabbitmq_management/priv/www/api/index.html index ac43f8ebe1..e71834d166 100644 --- a/deps/rabbitmq_management/priv/www/api/index.html +++ b/deps/rabbitmq_management/priv/www/api/index.html @@ -778,6 +778,36 @@ or: repeatedly pinged). + + X + + + + /api/healthchecks/node + + Runs basic healthchecks in the current node. Checks that the rabbit + application is running, list_channels and list_queues return, and + that no alarms are raised. If everything is working correctly, will + return HTTP status 200 with body:
{"status":"ok"}
If + something fails, will return HTTP status 200 with body: +
{"status":"failed","reason":"string"}
+ + + + X + + + + /api/healthchecks/node/node + + Runs basic healthchecks in the given node. Checks that the rabbit + application is running, list_channels and list_queues return, and + that no alarms are raised. If everything is working correctly, will + return HTTP status 200 with body:
{"status":"ok"}
If + something fails, will return HTTP status 200 with body: +
{"status":"failed","reason":"string"}
+ + diff --git a/deps/rabbitmq_management/src/rabbit_mgmt_dispatcher.erl b/deps/rabbitmq_management/src/rabbit_mgmt_dispatcher.erl index 8104f78381..bb77219fd3 100644 --- a/deps/rabbitmq_management/src/rabbit_mgmt_dispatcher.erl +++ b/deps/rabbitmq_management/src/rabbit_mgmt_dispatcher.erl @@ -89,5 +89,7 @@ dispatcher() -> {["whoami"], rabbit_mgmt_wm_whoami, []}, {["permissions"], rabbit_mgmt_wm_permissions, []}, {["permissions", vhost, user], rabbit_mgmt_wm_permission, []}, - {["aliveness-test", vhost], rabbit_mgmt_wm_aliveness_test, []} + {["aliveness-test", vhost], rabbit_mgmt_wm_aliveness_test, []}, + {["healthchecks", "node"], rabbit_mgmt_wm_healthchecks, []}, + {["healthchecks", "node", node], rabbit_mgmt_wm_healthchecks, []} ]. diff --git a/deps/rabbitmq_management/src/rabbit_mgmt_wm_healthchecks.erl b/deps/rabbitmq_management/src/rabbit_mgmt_wm_healthchecks.erl new file mode 100644 index 0000000000..46fe9369f8 --- /dev/null +++ b/deps/rabbitmq_management/src/rabbit_mgmt_wm_healthchecks.erl @@ -0,0 +1,62 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. +%% +-module(rabbit_mgmt_wm_healthchecks). + +-export([init/1, to_json/2, content_types_provided/2, is_authorized/2]). +-export([resource_exists/2]). + +-include("rabbit_mgmt.hrl"). +-include_lib("webmachine/include/webmachine.hrl"). + +%%-------------------------------------------------------------------- + +init(_Config) -> {ok, #context{}}. + +content_types_provided(ReqData, Context) -> + {[{"application/json", to_json}], ReqData, Context}. + +resource_exists(ReqData, Context) -> + {case node0(ReqData) of + not_found -> false; + _ -> true + end, ReqData, Context}. + +to_json(ReqData, Context) -> + Node = node0(ReqData), + try + rabbit_health_check:node(Node), + rabbit_mgmt_util:reply([{status, ok}], ReqData, Context) + catch + {node_is_ko, ErrorMsg} -> + rabbit_mgmt_util:reply([{status, failed}, {reason, ErrorMsg}], + ReqData, Context) + end. + +is_authorized(ReqData, Context) -> + rabbit_mgmt_util:is_authorized(ReqData, Context). + +node0(ReqData) -> + Node = case rabbit_mgmt_util:id(node, ReqData) of + none -> + node(); + Node0 -> + list_to_atom(binary_to_list(Node0)) + end, + case [N || N <- rabbit_mgmt_wm_nodes:all_nodes(ReqData), + proplists:get_value(name, N) == Node] of + [] -> not_found; + [_] -> Node + end. diff --git a/deps/rabbitmq_management/test/src/rabbit_mgmt_test_http.erl b/deps/rabbitmq_management/test/src/rabbit_mgmt_test_http.erl index 0b2eb53a4d..3f6efe3502 100644 --- a/deps/rabbitmq_management/test/src/rabbit_mgmt_test_http.erl +++ b/deps/rabbitmq_management/test/src/rabbit_mgmt_test_http.erl @@ -905,6 +905,11 @@ aliveness_test() -> http_delete("/queues/%2f/aliveness-test", ?NO_CONTENT), ok. +healthchecks_test() -> + [{status, <<"ok">>}] = http_get("/healthchecks/node", ?OK), + http_get("/healthchecks/node/foo", ?NOT_FOUND), + ok. + arguments_test() -> XArgs = [{type, <<"headers">>}, {arguments, [{'alternate-exchange', <<"amq.direct">>}]}],