-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_health.erl
40 lines (32 loc) · 1.24 KB
/
mod_health.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
%%% ---------------------------------------
%%% Health check for SSL, MySql on ejabberd
%%% ---------------------------------------
-module(mod_health).
-export([process/2]).
-export([get_all_status/0]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("jlib.hrl").
-include("ejabberd_http.hrl").
-import(lists, [duplicate/2, flatlength/1]).
% application constants
-define(MYSQL, mysql).
-define(EJABBERD, ejabberd).
-define(SSL, ssl).
%% add additional applications
process([], #request{method = 'GET', path = [<<"healthcheck">>]}) ->
StatusList = get_all_status(),
StatusLength = flatlength(StatusList),
ExpectedStatusListResult = duplicate(StatusLength, true),
if
StatusList == ExpectedStatusListResult ->
{204, [], <<"">>};
true ->
{503, [], <<"">>}
end.
get_all_status() ->
EJABBERDStatus = lists:keymember(?EJABBERD, 1, application:which_applications()),
MYSQLStatus = lists:keymember(?MYSQL, 1, application:which_applications()),
SSLStatus = lists:keymember(?SSL, 1, application:which_applications()),
?DEBUG("MOD_HEALTHCHECK checking status of Ejabberd : ~p\nMYSQL : ~p\nSSL : ~p", [EJABBERDStatus,MYSQLStatus,SSLStatus]),
[EJABBERDStatus, MYSQLStatus, SSLStatus].