External configuration and supervisor child modules
This commit is contained in:
parent
9a6464aa31
commit
af8fad987d
|
@ -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}}.
|
||||
|
|
|
@ -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}}.
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
).
|
||||
|
||||
|
|
|
@ -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
|
||||
).
|
||||
|
|
20
config/log_monitor.config
Normal file
20
config/log_monitor.config
Normal 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, ""}]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
].
|
|
@ -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"
|
||||
].
|
||||
|
|
Loading…
Reference in New Issue
Block a user