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