-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.rb
25 lines (23 loc) · 959 Bytes
/
mail.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'json'
id = 1
hash = { warning: {}, error: {}, fatal: {}, panic: {} }
File.open('mail.log').each_line do |line|
arr = []
arr << line.strip.split(' ')
arr.each do |x|
if x[5].match(/warning|error|fatal|panic/)
error_name = x[5].delete(':').to_sym
hash[error_name]["#{error_name}_#{id}"] = {}
hash[error_name]["#{error_name}_#{id}"][:date] = x[2]
hash[error_name]["#{error_name}_#{id}"][:time] = "#{x[0]} #{x[1]}"
hash[error_name]["#{error_name}_#{id}"][:server] = x[3]
hash[error_name]["#{error_name}_#{id}"][:PID] = x[4].match(/\d+/).to_s
hash[error_name]["#{error_name}_#{id}"][:service_process] = x[4].delete(':')
hash[error_name]["#{error_name}_#{id}"][:description] = ''
6.upto(x.size-1) { |y| hash[error_name]["#{error_name}_#{id}"][:description] << "#{x[y]} " }
hash[error_name]["#{error_name}_#{id}"][:description].strip!
id += 1
end
end
end
puts hash.to_json