Class: LogMonitor::Alerter
- Inherits:
-
Object
- Object
- LogMonitor::Alerter
show all
- Defined in:
- lib/log_monitor/alerter.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Alerter.
3
4
5
|
# File 'lib/log_monitor/alerter.rb', line 3
def initialize
clear_alert
end
|
Instance Method Details
#alert ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/log_monitor/alerter.rb', line 45
def alert
begin
$stdout.puts @alert_body
rescue => e
$stderr.puts "LogMonitor error"
$stderr.puts e.message
2.times $stderr.puts
end
clear_alert
end
|
#check_words ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/log_monitor/alerter.rb', line 26
def check_words
is_alert = false
@words.each do | word |
if @alert_body.match(/#{word}/)
is_alert = true
break
end
end
if is_alert
alert
end
clear_alert
end
|
#clear_alert ⇒ Object
40
41
42
43
|
# File 'lib/log_monitor/alerter.rb', line 40
def clear_alert
@alert_body = ''
@blank_line_count = 0
end
|
#monitor ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/log_monitor/alerter.rb', line 17
def monitor
@in.seek(0, IO::SEEK_END)
begin
revival_monitor
ensure
@in.close
end
end
|
#set_in(io_in) ⇒ Object
7
8
9
10
11
|
# File 'lib/log_monitor/alerter.rb', line 7
def set_in(io_in)
@io_in = io_in
FileUtils.touch(io_in) unless File.exists?(io_in)
@in = File.open(io_in, 'r')
end
|
#set_words(words) ⇒ Object
13
14
15
|
# File 'lib/log_monitor/alerter.rb', line 13
def set_words(words)
@words = words
end
|