Created
August 21, 2012 21:28
-
-
Save anonymous/3419574 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
hash = {} | |
CSV::read('./datafile.csv') do |line| | |
hash[line[0]] = { :location => line[1], :device_type => line[3]} | |
end | |
# device[line[0]] = {:location => line[1], :device_type => line[2]} | |
# end | |
#Dir['/var/www/html/cacti/reports/1/1/*.csv'].each do |line| | |
Dir['./report.csv'].each do |line| | |
date = `cat #{line} | head -30 | grep "Start" | awk -F: '{print $2}'` | |
date = date.gsub(/\s+/, "") | |
header = "hostname interface date in_avg in_avg" | |
report = `cat #{line} | grep "Monday"` | |
report = report.gsub('Monday',"#{date}").gsub(' - Traffic','').gsub('"','') | |
# open("/var/www/html/cacti/reports-parsed/interface-#{date}.csv", 'w') { |f| | |
open("./interface-#{date}.csv", 'w') { |f| | |
f.puts header} | |
report.each_line { |line| | |
fields = line.split(',') | |
hostname = fields[0].split('-')[0] | |
hostname = hostname.gsub(/\s+/, "") | |
interface = fields[0].split('-')[1] | |
interface = interface.gsub(/\s+/, "") | |
inavg = "#{fields[8]}".gsub('k','').gsub(/\s+/, "").gsub('NA','') | |
outavg = "#{fields[11]}".gsub('k','').gsub(/\s+/, "").gsub('NA','') | |
location = hash[hostname][:location] | |
output = "#{hostname},#{interface},#{fields[2]},#{inavg},#{outavg},#{location},#{location}" | |
# open("/var/www/html/cacti/reports-parsed/interface-#{date}.csv", 'a') { |f| | |
open("./interface-parsed-#{date}.csv", 'a') { |f| | |
f.puts output} | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment