diff --git a/TODO.md b/TODO.md index 5789005..d4f5684 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,7 @@ TODO ===== - - Manage problem of "infinite" consecutive errors. + - Allow to enable / disabled logfiles. - Limit number of emails that can be sent in a period of time. - Store the logfiles in a configuration file. - gen_fsm for gatherer? diff --git a/apps/log_monitor/src/gatherer.erl b/apps/log_monitor/src/gatherer.erl index c28e21b..6501b62 100644 --- a/apps/log_monitor/src/gatherer.erl +++ b/apps/log_monitor/src/gatherer.erl @@ -17,19 +17,22 @@ handle_info({log_line, Text}, [off, Log = #log{error_regex = ErrorRegex}]) -> case isError(Text, ErrorRegex) of true -> {ok, Timer} = timer:send_after(1000, {timeout}), - {noreply, [on, Log, Text, Timer]}; + {ok, SafeTimer} = timer:send_after(30000, {timeout}), + {noreply, [on, Log, Text, Timer, SafeTimer]}; false -> {noreply, [off, Log]} end; -handle_info({log_line, Text}, [on, Log = #log{error_regex = ErrorRegex}, Error, Timer]) -> +handle_info({log_line, Text}, [on, Log = #log{error_regex = ErrorRegex}, Error, Timer, SafeTimer]) -> case isError(Text, ErrorRegex) of true -> - timer:clean(Timer), + timer:cancel(Timer), {ok, NewTimer} = timer:send_after(1000, {timeout}), - {noreply, [on, Log, Error ++ "\n" ++ Text, NewTimer]}; + {noreply, [on, Log, Error ++ "\n" ++ Text, NewTimer, SafeTimer]}; false -> - {noreply, [on, Log, Error ++ "\n" ++ Text, Timer]} + {noreply, [on, Log, Error ++ "\n" ++ Text, Timer, SafeTimer]} end; -handle_info({timeout}, [on, Log = #log{file = File}, Error, _Timer]) -> +handle_info({timeout}, [on, Log = #log{file = File}, Error, Timer, SafeTimer]) -> + timer:cancel(Timer), + timer:cancel(SafeTimer), mailer ! {error, File, Error}, {noreply, [off, Log]}. diff --git a/apps/log_monitor/src/mailer.erl b/apps/log_monitor/src/mailer.erl index 796b0ad..fb1a41a 100644 --- a/apps/log_monitor/src/mailer.erl +++ b/apps/log_monitor/src/mailer.erl @@ -6,7 +6,6 @@ -export([start_link/0, init/1, terminate/2]). -export([handle_info/2, handle_cast/2, handle_call/3]). -export([code_change/3]). --export([email_subject/2]). start_link() -> gen_server:start_link(?MODULE, [], []).