0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#!/usr/bin/perl
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
e44e0ff3850931e7a79e4c86363f52990536f7bfDavid Lawrence# License, v. 2.0. If a copy of the MPL was not distributed with this
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater# file, You can obtain one at http://mozilla.org/MPL/2.0/.
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrews# traffic-json.pl:
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrews# Parses the JSON version of the RSSAC002 traffic stats into a
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrews# normalized format.
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrews
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrewsuse JSON;
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrews
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrewsmy $file = $ARGV[0];
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrewsopen(INPUT, "<$file");
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrewsmy $text = do{local$/;<INPUT>};
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrewsclose(INPUT);
e7ddc97b4578c281de6559fcd26aa1d68de4531fMark Andrews
my $ref = decode_json($text);
my $tcprcvd = $ref->{traffic}->{"dns-tcp-requests-sizes-received-ipv4"};
my $type = "tcp request-size ";
foreach $key (keys %{$tcprcvd}) {
print $type . $key . ": ". $tcprcvd->{$key} ."\n";
}
my $tcpsent = $ref->{traffic}->{"dns-tcp-responses-sizes-sent-ipv4"};
my $type = "tcp response-size ";
foreach $key (keys %{$tcpsent}) {
print $type . $key . ": ". $tcpsent->{$key} ."\n";
}
my $udprcvd = $ref->{traffic}->{"dns-udp-requests-sizes-received-ipv4"};
my $type = "udp request-size ";
foreach $key (keys %{$udprcvd}) {
print $type . $key . ": ". $udprcvd->{$key} ."\n";
}
my $udpsent = $ref->{traffic}->{"dns-udp-responses-sizes-sent-ipv4"};
my $type = "udp response-size ";
foreach $key (keys %{$udpsent}) {
print $type . $key . ": ". $udpsent->{$key} ."\n";
}