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
- #filter_action(data) ⇒ Object
- #filter_object(data) ⇒ Object
- #filter_org(data) ⇒ Object
- #filter_user(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) filter_user(data) || filter_action(data) || filter_object(data) || filter_org(data) end |
#filter_action(data) ⇒ Object
84 85 86 87 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 84 def filter_action(data) action_blacklist = Monitor::Config[:action_blacklist] action_blacklist && (data['action'] =~ action_blacklist) end |
#filter_object(data) ⇒ Object
74 75 76 77 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 74 def filter_object(data) object_blacklist = Monitor::Config[:object_blacklist] object_blacklist && (data['object'] =~ object_blacklist) end |
#filter_org(data) ⇒ Object
79 80 81 82 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 79 def filter_org(data) org_blacklist = Monitor::Config[:org_blacklist] org_blacklist && (data['org'] =~ org_blacklist) end |
#filter_user(data) ⇒ Object
69 70 71 72 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 69 def filter_user(data) user_blacklist = Monitor::Config[:user_blacklist] user_blacklist && (data['user'] =~ user_blacklist) 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 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) # 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) sink.receive(data) end end end end end end |
#scan(line) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/chef_deployment_monitor/logmon.rb', line 89 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 |