regions = {}
ordering = [ ]
filename = ""
puts Time.now.to_s + " Running findy grepy command"
%x[find /home/gravitystorm/public_html/redactions/logs-live/ -name "*.log" -type f -print0 | xargs -0 grep -F "Processing region" | sort --stable --buffer-size=1G].each_with_index do |line, line_no |
# break if line_no==200
filename = line.split(":")[0]
filename = filename.split("logs-live/")[1]
status = "UNKNOWN"
tail = `tail /home/gravitystorm/public_html/redactions/logs-live/#{filename}`
if tail.include?(': Summary')
tail = tail.split(': Summary')[1]
summary = ""
successful_changesets = true
successful_candidates = true
failed_changesets = true
failed_candidates = true
tail.lines.each do | tailline |
if tailline.include?('-- :')
summary += tailline.split('-- : ')[1].strip + "
"
successful_changesets = false if tailline.include?(" 0 successful changesets")
successful_candidates = false if tailline.include?(" 0 successful candidates")
failed_changesets = false if tailline.include?(" 0 failed changesets")
failed_candidates = false if tailline.include?(" 0 failed candidates")
end
end
status = "SUCCESS"
status = "ZEROS" if not successful_changesets and not successful_candidates
status = "ERRORS" if failed_changesets or failed_candidates
elsif tail.include?('Marking region failed')
status="FAIL"
summary="Region failed"
end
line = line.split("[")[1]
time = line.split(".")[0]
region_hash = line.split("region {")[1]
region_hash.gsub!(":","")
region_hash.gsub!("=>",":")
#line = "{ filename:\"" + filename + "\", status:\"" + status + "\", summary:\"" + summary.to_s + "\", time:\"" + time + "\", " + region_hash.strip
# output_lines << line
chomped_string = region_hash.split("lat:")[1]
lat = chomped_string.split(", ")[0]
chomped_string = chomped_string.split("lon:")[1]
lon = chomped_string.split("}")[0]
log_data = { :filename => filename,
:status => status,
:summary => summary.to_s,
:time => time,
:lat => lat,
:lon => lon }
description = "Region (" + lat + ", " + lon + ")
" +
"Started time:" + log_data[:time] + "
" +
log_data[:summary] + "
" +
"Detailed logs: " + log_data[:filename].to_s + ""
if status=="UNKNOWN" and log_data[:summary]==""
status="CURRENT"
description = "No summary yet. This region appears to be 'in progress'.
" + description
end
latlon = lat + "," + lon
puts "filename: " + filename + " line_no " + line_no.to_s + " latlon=" + latlon if line_no % 500 ==0
if regions[latlon].nil?
#We didn't encounter these coords before. New region
regions[latlon] = [lat,lon,status, description];
ordering << latlon
else
#We encountered these coords before. Modify this region data
regions[latlon][3] = description + "