Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Forked from anonymous/gist:3419574
Created August 21, 2012 21:38
Show Gist options
  • Save bil-bas/3419649 to your computer and use it in GitHub Desktop.
Save bil-bas/3419649 to your computer and use it in GitHub Desktop.
Traffic CSV for nullsign
require 'csv'
# Read the list of hosts.
hosts = {}
CSV.open('./datafile.csv', 'r') do |fields|
hosts[fields[0]] = { :location => fields[1], :device_type => fields[3] }
end
# Find out the date to report on.
report_file = './report.csv'
date = `cat #{report_file} | head -30 | grep "Start" | awk -F: '{print $2}'`.strip
CSV.open('./interface-parsed-#{date}.csv', 'a') do |output|
# Write the header.
output << %w<hostname interface date in_avg in_avg location device_type>
# Only read in Monday's traffic.
report = `cat #{report_file} | grep "Monday"`
report = report.gsub('Monday', date).gsub(' - Traffic', '')
CSV.parse(report).each do |fields|
hostname, interface = fields[0].split('-')
inavg = fields[8].gsub(/(?:k|NA)/, '')
outavg = fields[11].gsub(/(?:k|NA)/, '')
host = hosts[hostname]
output << [hostname, interface, fields[2], inavg, outavg, host[:location], host[:device_type]]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment