External configuration and supervisor child modules

This commit is contained in:
Fabio Salvini 2017-06-12 19:44:06 +02:00
parent 9a6464aa31
commit af8fad987d
6 changed files with 44 additions and 30 deletions

View File

@ -13,20 +13,23 @@ init([]) ->
id => mailer,
start => {mailer, start_link, []},
restart => permanent,
shutdown => 5000
shutdown => 5000,
modules => [mailer]
},
#{
id => logfiles_sup,
start => {logfiles_sup, start_link, []},
restart => permanent,
type => supervisor,
shutdown => 5000
shutdown => 5000,
modules => [logfiles_sup]
},
#{
id => config,
start => {config, start_link, []},
restart => permanent,
shutdown => 5000
shutdown => 5000,
modules => [config]
}
],
{ok, {SupFlags, ChildSpecs}}.

View File

@ -13,12 +13,14 @@ init([File, ErrorRegex]) ->
id => gatherer,
start => {gatherer, start_link, [File, ErrorRegex]},
restart => permanent,
shutdown => 5000
shutdown => 5000,
modules => [gatherer]
},
#{
id => watcher,
start => {watcher, start_link, [self(), File]},
restart => permanent,
shutdown => 5000
shutdown => 5000,
modules => [watcher]
}],
{ok, {SupFlags, ChildSpecs}}.

View File

@ -24,7 +24,8 @@ add_child(Args = [File, _ErrorRegex]) ->
id => File,
start => {log_sup, start_link, Args},
restart => temporary,
shutdown => 5000
shutdown => 5000,
modules => [log_sup]
}
).

View File

@ -34,12 +34,12 @@ code_change(_OldVsn, State, _Extra) ->
send_email(File, Text) ->
{ok, EmailConfig} = application:get_env(log_monitor, email_config),
Sender = proplists:get_value(sender, EmailConfig, "log@monitor.com"),
Sender = proplists:get_value(sender, EmailConfig),
DefaultReceiver = proplists:get_value(default_receiver, EmailConfig),
Relay = proplists:get_value(relay, EmailConfig),
Username = proplists:get_value(username, EmailConfig),
Password = proplists:get_value(password, EmailConfig),
Connection = proplists:get_value(connection, EmailConfig),
error_logger:info_report("Sending email for file ~s with text: ~n~s~n", [File, Text]),
gen_smtp_client:send_blocking({Sender, [DefaultReceiver],
gen_smtp_client:send_blocking(
{Sender, [DefaultReceiver],
io_lib:format("Subject: Error notification\r\nFrom: Fabio\r\n\r\nLogfile: ~s~nError: ~n~s~n", [File, Text])},
[{relay, Relay}, {username, Username}, {password, Password}]).
Connection
).

20
config/log_monitor.config Normal file
View File

@ -0,0 +1,20 @@
[
{ log_monitor,
[
%% File where the list of monitored log files is stored.
%% WARNING: If you leave it inside /tmp, every time the node is restarted the log files will be lost.
{storage, "/tmp/logfiles"},
{email_config,
[
{sender, "log@monitor.com"},
{default_receiver, "salvini.fabio001@gmail.com"},
{connection, [
{relay, "smtp.fabiosalvinii.com"},
{username, "salvini.fabio001@gmail.com"},
{password, ""}]
}
]
}
]
}
].

View File

@ -1,16 +1,4 @@
[
{ log_monitor,
[
{storage, "/tmp/logfiles"},
{email_config,
[
{sender, "me@example.com"},
{default_receiver, "salvini.fabio001@gmail.com"},
{relay, "smtp.fabiosalvinii.com"},
{username, "salvini.fabio001@gmail.com"},
{password, ""}
]
}
]
}
{ log_monitor, []
}, "/home/fsalvini/gitRepos/log_monitor/config/log_monitor.config"
].