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

@@ -21,10 +21,11 @@ add_child(Args = [File, _ErrorRegex]) ->
supervisor:start_child(
?MODULE,
#{
id => File,
start => {log_sup, start_link, Args},
restart => temporary,
shutdown => 5000
id => File,
start => {log_sup, start_link, Args},
restart => temporary,
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],
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}]).
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])},
Connection
).