External configuration and supervisor child modules
This commit is contained in:
parent
9a6464aa31
commit
af8fad987d
|
@ -13,20 +13,23 @@ init([]) ->
|
||||||
id => mailer,
|
id => mailer,
|
||||||
start => {mailer, start_link, []},
|
start => {mailer, start_link, []},
|
||||||
restart => permanent,
|
restart => permanent,
|
||||||
shutdown => 5000
|
shutdown => 5000,
|
||||||
|
modules => [mailer]
|
||||||
},
|
},
|
||||||
#{
|
#{
|
||||||
id => logfiles_sup,
|
id => logfiles_sup,
|
||||||
start => {logfiles_sup, start_link, []},
|
start => {logfiles_sup, start_link, []},
|
||||||
restart => permanent,
|
restart => permanent,
|
||||||
type => supervisor,
|
type => supervisor,
|
||||||
shutdown => 5000
|
shutdown => 5000,
|
||||||
|
modules => [logfiles_sup]
|
||||||
},
|
},
|
||||||
#{
|
#{
|
||||||
id => config,
|
id => config,
|
||||||
start => {config, start_link, []},
|
start => {config, start_link, []},
|
||||||
restart => permanent,
|
restart => permanent,
|
||||||
shutdown => 5000
|
shutdown => 5000,
|
||||||
|
modules => [config]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
{ok, {SupFlags, ChildSpecs}}.
|
{ok, {SupFlags, ChildSpecs}}.
|
||||||
|
|
|
@ -13,12 +13,14 @@ init([File, ErrorRegex]) ->
|
||||||
id => gatherer,
|
id => gatherer,
|
||||||
start => {gatherer, start_link, [File, ErrorRegex]},
|
start => {gatherer, start_link, [File, ErrorRegex]},
|
||||||
restart => permanent,
|
restart => permanent,
|
||||||
shutdown => 5000
|
shutdown => 5000,
|
||||||
|
modules => [gatherer]
|
||||||
},
|
},
|
||||||
#{
|
#{
|
||||||
id => watcher,
|
id => watcher,
|
||||||
start => {watcher, start_link, [self(), File]},
|
start => {watcher, start_link, [self(), File]},
|
||||||
restart => permanent,
|
restart => permanent,
|
||||||
shutdown => 5000
|
shutdown => 5000,
|
||||||
|
modules => [watcher]
|
||||||
}],
|
}],
|
||||||
{ok, {SupFlags, ChildSpecs}}.
|
{ok, {SupFlags, ChildSpecs}}.
|
||||||
|
|
|
@ -21,10 +21,11 @@ add_child(Args = [File, _ErrorRegex]) ->
|
||||||
supervisor:start_child(
|
supervisor:start_child(
|
||||||
?MODULE,
|
?MODULE,
|
||||||
#{
|
#{
|
||||||
id => File,
|
id => File,
|
||||||
start => {log_sup, start_link, Args},
|
start => {log_sup, start_link, Args},
|
||||||
restart => temporary,
|
restart => temporary,
|
||||||
shutdown => 5000
|
shutdown => 5000,
|
||||||
|
modules => [log_sup]
|
||||||
}
|
}
|
||||||
).
|
).
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,12 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
|
|
||||||
send_email(File, Text) ->
|
send_email(File, Text) ->
|
||||||
{ok, EmailConfig} = application:get_env(log_monitor, email_config),
|
{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),
|
DefaultReceiver = proplists:get_value(default_receiver, EmailConfig),
|
||||||
Relay = proplists:get_value(relay, EmailConfig),
|
Connection = proplists:get_value(connection, EmailConfig),
|
||||||
Username = proplists:get_value(username, EmailConfig),
|
|
||||||
Password = proplists:get_value(password, EmailConfig),
|
|
||||||
error_logger:info_report("Sending email for file ~s with text: ~n~s~n", [File, Text]),
|
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(
|
||||||
io_lib:format("Subject: Error notification\r\nFrom: Fabio\r\n\r\nLogfile: ~s~nError: ~n~s~n", [File, Text])},
|
{Sender, [DefaultReceiver],
|
||||||
[{relay, Relay}, {username, Username}, {password, Password}]).
|
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,
|
{ log_monitor, []
|
||||||
[
|
}, "/home/fsalvini/gitRepos/log_monitor/config/log_monitor.config"
|
||||||
{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, ""}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
].
|
].
|
||||||
|
|
Loading…
Reference in New Issue
Block a user