1#!/usr/bin/perl 2# 3# Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4# 5# This Source Code Form is subject to the terms of the Mozilla Public 6# License, v. 2.0. If a copy of the MPL was not distributed with this 7# file, You can obtain one at http://mozilla.org/MPL/2.0/. 8# 9# See the COPYRIGHT file distributed with this work for additional 10# information regarding copyright ownership. 11 12# traffic-xml.pl: 13# Parses the XML version of the RSSAC002 traffic stats into a 14# normalized format. 15 16use XML::Simple; 17 18my $file = $ARGV[0]; 19 20my $ref = XMLin($file); 21 22my $udp = $ref->{traffic}->{ipv4}->{udp}->{counters}; 23foreach $group (@$udp) { 24 my $type = "udp " . $group->{type} . " "; 25 if (exists $group->{counter}->{name}) { 26 print $type . $group->{counter}->{name} . ": " . $group->{counter}->{content} . "\n"; 27 } else { 28 foreach $key (keys %{$group->{counter}}) { 29 print $type . $key . ": ". $group->{counter}->{$key}->{content} ."\n"; 30 } 31 } 32} 33 34my $tcp = $ref->{traffic}->{ipv4}->{tcp}->{counters}; 35foreach $group (@$tcp) { 36 my $type = "tcp " . $group->{type} . " "; 37 if (exists $group->{counter}->{name}) { 38 print $type . $group->{counter}->{name} . ": " . $group->{counter}->{content} . "\n"; 39 } else { 40 foreach $key (keys %{$group->{counter}}) { 41 print $type . $key . ": ". $group->{counter}->{$key}->{content} ."\n"; 42 } 43 } 44} 45