Moved constants to configuration file
This commit is contained in:
parent
85c9443407
commit
0222425c53
|
@ -18,6 +18,8 @@
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
-define(SERVER, ?MODULE).
|
-define(SERVER, ?MODULE).
|
||||||
|
-define(DEFAULT_TIMER_TIME, 1000).
|
||||||
|
-define(DEFAULT_SAFE_TIMER_TIME, 30000).
|
||||||
|
|
||||||
-record(log, {file, error_regex}).
|
-record(log, {file, error_regex}).
|
||||||
%% -record(state, {}).
|
%% -record(state, {}).
|
||||||
|
@ -100,8 +102,8 @@ handle_cast(_Msg, State) ->
|
||||||
handle_info({log_line, Text}, [off, Log = #log{error_regex = ErrorRegex}]) ->
|
handle_info({log_line, Text}, [off, Log = #log{error_regex = ErrorRegex}]) ->
|
||||||
case isError(Text, ErrorRegex) of
|
case isError(Text, ErrorRegex) of
|
||||||
true ->
|
true ->
|
||||||
{ok, Timer} = timer:send_after(1000, {timeout}),
|
{ok, Timer} = timer:send_after(timer_time(), {timeout}),
|
||||||
{ok, SafeTimer} = timer:send_after(30000, {timeout}),
|
{ok, SafeTimer} = timer:send_after(safe_timer_time(), {timeout}),
|
||||||
{noreply, [on, Log, Text, Timer, SafeTimer]};
|
{noreply, [on, Log, Text, Timer, SafeTimer]};
|
||||||
false -> {noreply, [off, Log]}
|
false -> {noreply, [off, Log]}
|
||||||
end;
|
end;
|
||||||
|
@ -109,7 +111,7 @@ handle_info({log_line, Text}, [on, Log = #log{error_regex = ErrorRegex}, Error,
|
||||||
case isError(Text, ErrorRegex) of
|
case isError(Text, ErrorRegex) of
|
||||||
true ->
|
true ->
|
||||||
timer:cancel(Timer),
|
timer:cancel(Timer),
|
||||||
{ok, NewTimer} = timer:send_after(1000, {timeout}),
|
{ok, NewTimer} = timer:send_after(timer_time(), {timeout}),
|
||||||
{noreply, [on, Log, Error ++ Text, NewTimer, SafeTimer]};
|
{noreply, [on, Log, Error ++ Text, NewTimer, SafeTimer]};
|
||||||
false ->
|
false ->
|
||||||
{noreply, [on, Log, Error ++ Text, Timer, SafeTimer]}
|
{noreply, [on, Log, Error ++ Text, Timer, SafeTimer]}
|
||||||
|
@ -155,3 +157,11 @@ isError(Text, ErrorRegex) ->
|
||||||
nomatch ->
|
nomatch ->
|
||||||
false
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
timer_time() ->
|
||||||
|
{ok, ProcessingConfig} = application:get_env(log_monitor, processing_config),
|
||||||
|
proplists:get_value(gathering_time, ProcessingConfig, ?DEFAULT_TIMER_TIME).
|
||||||
|
|
||||||
|
safe_timer_time() ->
|
||||||
|
{ok, ProcessingConfig} = application:get_env(log_monitor, processing_config),
|
||||||
|
proplists:get_value(max_gathering_time, ProcessingConfig, ?DEFAULT_TIMER_TIME).
|
||||||
|
|
|
@ -4,12 +4,19 @@
|
||||||
{email_config,
|
{email_config,
|
||||||
[
|
[
|
||||||
{sender, "log@monitor.com"},
|
{sender, "log@monitor.com"},
|
||||||
|
|
||||||
|
%% The receiver to use for all the groups that do not specify any receiver.
|
||||||
{default_receiver, "salvini.fabio001@gmail.com"},
|
{default_receiver, "salvini.fabio001@gmail.com"},
|
||||||
|
|
||||||
|
%% The receiver to use for the application errors.
|
||||||
|
{admin_receiver, "salvini.fabio001@gmail.com"},
|
||||||
|
|
||||||
%% Subject of the email.
|
%% Subject of the email.
|
||||||
%% Placeholders:
|
%% Placeholders:
|
||||||
%% %f: the full path of the log file (ex. /var/log/myapp.log).
|
%% %f: the full path of the log file (ex. /var/log/myapp.log).
|
||||||
%% %F: the basename of the log file (ex. myapp).
|
%% %F: the basename of the log file (ex. myapp).
|
||||||
{subject, "[%F] Error notification"},
|
{subject, "[%F] Error notification"},
|
||||||
|
|
||||||
{connection, [
|
{connection, [
|
||||||
{relay, "smtp.fabiosalvinii.com"},
|
{relay, "smtp.fabiosalvinii.com"},
|
||||||
{username, "salvini.fabio001@gmail.com"},
|
{username, "salvini.fabio001@gmail.com"},
|
||||||
|
@ -17,9 +24,23 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{processing_config,
|
||||||
|
[
|
||||||
|
%% How long to gather log lines after an error occurs.
|
||||||
|
%% If another error occurs, the time is reset.
|
||||||
|
{gathering_time, 1000},
|
||||||
|
|
||||||
|
%% Max time for gathering log lines.
|
||||||
|
%% Precaution in case of infinite consecutive errors.
|
||||||
|
{max_gathering_time, 30000}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
%% Location of the file that contains the logs to monitor.
|
||||||
{logfiles_config, "/home/fsalvini/gitRepos/log_monitor/config/logfiles.config"}
|
{logfiles_config, "/home/fsalvini/gitRepos/log_monitor/config/logfiles.config"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
%% Directory where the application data is stored.
|
%% Directory where the application data is stored.
|
||||||
%% WARNING: If you leave it inside /tmp, every time the node is restarted the
|
%% WARNING: If you leave it inside /tmp, every time the node is restarted the
|
||||||
%% application will reset.
|
%% application will reset.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user