57 lines
1.9 KiB
Erlang
57 lines
1.9 KiB
Erlang
%%%-------------------------------------------------------------------
|
|
%%% @author Fabio Salvini <fs@fabiosalvini.com>
|
|
%%% @copyright (C) 2017, Fabio Salvini
|
|
%%% @doc
|
|
%%%
|
|
%%% @end
|
|
%%% Created : 2 Jul 2017 by Fabio Salvini <fs@fabiosalvini.com>
|
|
%%%-------------------------------------------------------------------
|
|
-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
|
|
%%%===================================================================
|