Class: Chef::Deployment::Monitor::Logmon
- Inherits:
-
Object
- Object
- Chef::Deployment::Monitor::Logmon
- Defined in:
- lib/chef_deployment_monitor/logmon.rb
Instance Method Summary collapse
- #filter(data) ⇒ Object
- #filter_action(data) ⇒ Object
- #filter_user(data) ⇒ Object
- #format(data) ⇒ Object
- #run ⇒ Object
- #scan(line) ⇒ Object
Instance Method Details
#filter(data) ⇒ Object
54 55 56 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 54 def filter(data) filter_user(data) || filter_action(data) end |
#filter_action(data) ⇒ Object
63 64 65 66 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 63 def filter_action(data) action_blacklist = Monitor::Config[:action_blacklist] action_blacklist && (data['action'] =~ action_blacklist) end |
#filter_user(data) ⇒ Object
58 59 60 61 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 58 def filter_user(data) user_blacklist = Monitor::Config[:user_blacklist] user_blacklist && (data['user'] =~ user_blacklist) end |
#format(data) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 47 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 end |
#run ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 24 def run sink = MarkerFileSink.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) data = format(data) # skipping the objects 'checksum-.*' and 'reports' unless data.nil? || data['org'].nil? || data['object'] =~ /(^checksum-.*$|^reports$)/ unless filter(data) Monitor::Log.new(data.to_json, 'INFO') sink.receive(data) end end end end end end |
#scan(line) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 68 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 |