-
-
Save bil-bas/3419649 to your computer and use it in GitHub Desktop.
Traffic CSV for nullsign
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' | |
# 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