Class: Chef::Deployment::Monitor::Logmon
- Inherits:
-
Object
- Object
- Chef::Deployment::Monitor::Logmon
- Defined in:
- lib/chef_deployment_monitor/logmon.rb
Instance Method Summary collapse
- #digest(data) ⇒ Object
- #filter(data) ⇒ Object
- #format(data) ⇒ Object
- #run ⇒ Object
- #scan(line) ⇒ Object
Instance Method Details
#digest(data) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 57 def digest(data) md5 = Digest::MD5.new md5.update data.to_s data = data.dup data['digest'] = md5.hexdigest data end |
#filter(data) ⇒ Object
65 66 67 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 65 def filter(data) Monitor::Config[:blacklisted?].call(data) end |
#format(data) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 49 def format(data) # convert to timestamp data_dup = data.dup data_dup['time'] = DateTime.strptime(data['time'], '%d/%b/%C:%T %z').to_time.to_i data_dup['server'] = data['server'].strip data_dup end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 25 def run sinks = [MarkerFileSink.new, HistoryFile.new] begin File.open(Monitor::Config[:mon_file]) do |mon| mon.extend(File::Tail) mon.interval = 5 mon.backward(1) mon.tail do |line| data = scan(line) # skipping the objects 'checksum-.*' and 'reports' unless data.nil? || data['org'].nil? || data['object'] =~ /(^checksum-.*$|^reports$)/ data = format(data) unless filter(data) Monitor::Log.new(data.to_json, 'INFO') data = digest(data) sinks.each { |sink| sink.receive(data) } end end end end end end |
#scan(line) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 69 def scan(line) @regex = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - (.{0})- \[([^\]]+?)\] "(\w+) ([^\s]+?) (HTTP\/1\.1)" (\d+) "(.*)" (\d+) "-" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)" "(.*)"/ if line =~ @regex data = {} data['time'] = Regexp.last_match(3) data['user'] = Regexp.last_match(16) data['server'] = LOGMONNAME data['org'] = Regexp.last_match(5).split('/')[2] unless Regexp.last_match(5).split('/')[2].nil? data['object'] = Regexp.last_match(5).split('/')[3] unless Regexp.last_match(5).split('/')[3].nil? data['name'] = Regexp.last_match(5).split('/')[4] unless Regexp.last_match(5).split('/')[4].nil? data['version'] = Regexp.last_match(5).split('/')[5] unless Regexp.last_match(5).split('/')[5].nil? data['action'] = Regexp.last_match(4) return data end nil end |