Skip to content

Commit 928d635

Browse files
Merge pull request #4 from cloudant/32909-check-clouseau-availability
Add check for search availability
2 parents ff6410c + d544300 commit 928d635

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
%% -------------------------------------------------------------------
2+
%%
3+
%% weatherreport - automated diagnostic tools for CouchDB
4+
%%
5+
%% Copyright (c) 2014 Cloudant
6+
%%
7+
%% This file is provided to you under the Apache License,
8+
%% Version 2.0 (the "License"); you may not use this file
9+
%% except in compliance with the License. You may obtain
10+
%% a copy of the License at
11+
%%
12+
%% http://www.apache.org/licenses/LICENSE-2.0
13+
%%
14+
%% Unless required by applicable law or agreed to in writing,
15+
%% software distributed under the License is distributed on an
16+
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
%% KIND, either express or implied. See the License for the
18+
%% specific language governing permissions and limitations
19+
%% under the License.
20+
%%
21+
%% -------------------------------------------------------------------
22+
23+
%% @doc Diagnostic that checks the local clouseau node is responsive.
24+
%% If clouseau is unresponsive then search will not work. An info
25+
%% message is returned if clouseau responds to pings and an error
26+
%% otherwise.
27+
-module(weatherreport_check_search).
28+
-behaviour(weatherreport_check).
29+
30+
-export([description/0,
31+
valid/0,
32+
check/0,
33+
format/1]).
34+
35+
-spec description() -> string().
36+
description() ->
37+
"Check the local search node is responsive".
38+
39+
-spec valid() -> boolean().
40+
valid() ->
41+
weatherreport_node:can_connect().
42+
43+
-spec check() -> [{atom(), term()}].
44+
check() ->
45+
SearchNode = 'clouseau@127.0.0.1',
46+
case weatherreport_node:local_command(net_adm, ping, [SearchNode]) of
47+
pong ->
48+
[{info, {clouseau_ok, SearchNode}}];
49+
Error ->
50+
[{error, {clouseau_error, SearchNode, Error}}]
51+
end.
52+
53+
-spec format(term()) -> {io:format(), [term()]}.
54+
format({clouseau_ok, SearchNode}) ->
55+
{"Local search node at ~w responding ok", [SearchNode]};
56+
format({clouseau_error, SearchNode, Error}) ->
57+
{"Local search node at ~w not responding: ~w", [SearchNode, Error]}.

0 commit comments

Comments
 (0)