diff --git a/apps/log_monitor/src/mailer.erl b/apps/log_monitor/src/mailer.erl index 94cd7bd..39f7a40 100644 --- a/apps/log_monitor/src/mailer.erl +++ b/apps/log_monitor/src/mailer.erl @@ -14,7 +14,6 @@ %% API -export([start_link/0]). --export([test/0]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, @@ -36,26 +35,6 @@ start_link() -> gen_server:start_link(?MODULE, [], []). -%%-------------------------------------------------------------------- -%% @doc -%% Send an email to test the configuration. -%% -%% @spec test() -> binary() | {error, Type, Message} -%% @end -%%-------------------------------------------------------------------- -test() -> - {ok, EmailConfig} = application:get_env(log_monitor, email_config), - Sender = proplists:get_value(sender, EmailConfig), - AdminReceiver = proplists:get_value(admin_receiver, EmailConfig), - Connection = proplists:get_value(connection, EmailConfig), - Subject = "Test", - error_logger:info_msg("Sender: ~s, Receiver: ~s, Subject: ~s~n", [Sender, AdminReceiver, Subject]), - gen_smtp_client:send_blocking( - {Sender, [AdminReceiver], - io_lib:format("Subject: ~s\r\nFrom: ~s\r\n\r\nTest~n", [Subject, Sender])}, - Connection - ). - %%%=================================================================== %%% gen_server callbacks %%%=================================================================== diff --git a/apps/log_monitor/src/test.erl b/apps/log_monitor/src/test.erl new file mode 100644 index 0000000..7d673e6 --- /dev/null +++ b/apps/log_monitor/src/test.erl @@ -0,0 +1,56 @@ +%%%------------------------------------------------------------------- +%%% @author Fabio Salvini +%%% @copyright (C) 2017, Fabio Salvini +%%% @doc +%%% +%%% @end +%%% Created : 2 Jul 2017 by Fabio Salvini +%%%------------------------------------------------------------------- +-module(test). + +%% API +-export([email/0]). +-export([regex/2]). + +%%%=================================================================== +%%% API +%%%=================================================================== + +%%-------------------------------------------------------------------- +%% @doc +%% Send an email to test the configuration. +%% +%% @spec email -> binary() | {error, Type, Message} +%% @end +%%-------------------------------------------------------------------- +email() -> + {ok, EmailConfig} = application:get_env(log_monitor, email_config), + Sender = proplists:get_value(sender, EmailConfig), + AdminReceiver = proplists:get_value(admin_receiver, EmailConfig), + Connection = proplists:get_value(connection, EmailConfig), + Subject = "Test", + error_logger:info_msg("Sender: ~s, Receiver: ~s, Subject: ~s~n", [Sender, AdminReceiver, Subject]), + gen_smtp_client:send_blocking( + {Sender, [AdminReceiver], + io_lib:format("Subject: ~s\r\nFrom: ~s\r\n\r\nTest~n", [Subject, Sender])}, + Connection + ). + +%%-------------------------------------------------------------------- +%% @doc +%% Check if the regex match the line. +%% +%% @spec regex(Regex, Line) -> match | nomatch +%% @end +%%-------------------------------------------------------------------- +regex(Regex, Line) -> + case re:run(Line, Regex) of + {match, _} -> + match; + nomatch -> + nomatch + end. + +%%%=================================================================== +%%% Internal functions +%%%===================================================================