Class: AirportEvents::KernelLogParser
- Inherits:
-
Object
- Object
- AirportEvents::KernelLogParser
- Includes:
- Publisher
- Defined in:
- lib/airport_events/kernel_log_parser.rb
Instance Method Summary collapse
-
#initialize ⇒ KernelLogParser
constructor
A new instance of KernelLogParser.
- #match_event(line) ⇒ Object
Methods included from Publisher
Constructor Details
#initialize ⇒ KernelLogParser
Returns a new instance of KernelLogParser.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/airport_events/kernel_log_parser.rb', line 8 def initialize Thread.new do File.open('/var/log/kernel.log') do |log| log.extend(File::Tail) log.interval = 10 log.backward(0) log.tail do |line| if event = match_event(line) publish event, DateTime.strptime(line[0..15], '%b %d %H:%M:%S') end end end end end |
Instance Method Details
#match_event(line) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/airport_events/kernel_log_parser.rb', line 24 def match_event line if line.match /AirPort: Link Up.*/ :connected elsif line.match /AirPort: Link Down.*/ :disconnected end end |