Node health checks endpoint
* /healthchecks/node * /healthchecks/node/<node>
This commit is contained in:
parent
28b36fa12f
commit
8ea2eb8f75
|
|
@ -778,6 +778,36 @@ or:
|
||||||
repeatedly pinged).
|
repeatedly pinged).
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>X</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td class="path">/api/healthchecks/node</td>
|
||||||
|
<td>
|
||||||
|
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: <pre>{"status":"ok"}</pre> If
|
||||||
|
something fails, will return HTTP status 200 with body:
|
||||||
|
<pre>{"status":"failed","reason":"string"}</pre>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>X</td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
<td class="path">/api/healthchecks/node/<i>node</i></td>
|
||||||
|
<td>
|
||||||
|
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: <pre>{"status":"ok"}</pre> If
|
||||||
|
something fails, will return HTTP status 200 with body:
|
||||||
|
<pre>{"status":"failed","reason":"string"}</pre>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -89,5 +89,7 @@ dispatcher() ->
|
||||||
{["whoami"], rabbit_mgmt_wm_whoami, []},
|
{["whoami"], rabbit_mgmt_wm_whoami, []},
|
||||||
{["permissions"], rabbit_mgmt_wm_permissions, []},
|
{["permissions"], rabbit_mgmt_wm_permissions, []},
|
||||||
{["permissions", vhost, user], rabbit_mgmt_wm_permission, []},
|
{["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, []}
|
||||||
].
|
].
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -905,6 +905,11 @@ aliveness_test() ->
|
||||||
http_delete("/queues/%2f/aliveness-test", ?NO_CONTENT),
|
http_delete("/queues/%2f/aliveness-test", ?NO_CONTENT),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
healthchecks_test() ->
|
||||||
|
[{status, <<"ok">>}] = http_get("/healthchecks/node", ?OK),
|
||||||
|
http_get("/healthchecks/node/foo", ?NOT_FOUND),
|
||||||
|
ok.
|
||||||
|
|
||||||
arguments_test() ->
|
arguments_test() ->
|
||||||
XArgs = [{type, <<"headers">>},
|
XArgs = [{type, <<"headers">>},
|
||||||
{arguments, [{'alternate-exchange', <<"amq.direct">>}]}],
|
{arguments, [{'alternate-exchange', <<"amq.direct">>}]}],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue