in reply to Re: Epoch based parser
in thread Epoch based parser
Hi Ken,
Finally I made some changes and then also added code to read the json string from a file and parse it. However, my file is going to contain the same kind of json output appended to it continuously over time.
When I try to decode_json the entire file, it doesnt allow, as I believe decode_json looks for the braces to see if it finished. How can I parse multiline json from a file?
Heres the code I have now:
The file input would be something like:#!/usr/bin/env perl -l use strict; use warnings; use Time::Local; use JSON; use Time::Piece; use Math::Round; use File::Read; use Text::Table; my $DestIP="192.168.127.111"; my $jsonc = read_file ('C:\Documents and Settings\SonicWALL User\My Do +cuments\Scripts\logs\json.txt'); my $data = decode_json join '' => map { chomp; $_ } ($jsonc); #my $data = decode_json $jsonc; my $tb = Text::Table->new( "Date", "Start Time", "End Time", "Time Taken" , "Egress: Conv +eyed", "Egress : Sent" , "Ingress: Conveyed" , "Ingress: Sent"); for (@{$data->{aaData}}) { my $difftime=(@$_[1] - @$_[0]); my $destip=@$_[6]; my @egress=split(',', @$_[8]); my @ingress=split(',', @$_[9]); my $econveyed=$egress[0]/1000000; my $esent=$egress[1]/1000000; my $iconveyed=$ingress[0]/1000; my $isent=$ingress[1]/1000; my $startTime=scalar(localtime(@$_[0])); my $endTime=scalar(localtime(@$_[1])); #Filter only for required traffic and eliminate any traffic less than + 1MB if ( $destip eq $DestIP && $egress[0]>1000000) { #print "@$_"; my $date = $startTime->mdy; my $stime1 = $startTime->hms; my $etime1 =$endTime->hms; $tb->load( [ $date, $stime1 , $etime1 ,convert_time($difftime) , nearest(.01,$e +conveyed) , nearest(.01,$esent), $iconveyed , $isent ], ); } } print $tb;
{"DisplayRecords":"12","Records":"12","sColumns":"startTime,endTime, remoteNode,srcIP,srcPort,destIP,destPort,egress,ingress","aaData":[["1 +375976271" ,"1375976430","LAN","D0:05:FE","172.20.30.2",1093,"172.20.28.2",1330," +1034,348"]]} {"DisplayRecords":"12","Records":"12","sColumns":"startTime,endTime, remoteNode,srcIP,srcPort,destIP,destPort,egress,ingress","aaData":[["1 +375976271" ,"1375976430","LAN","D0:05:FE","172.20.30.2",1093,"172.20.28.2",1330," +1034,348"]]} .... and so on
I couldnt figure this part out. Thanks for your help so far.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Epoch based parser
by kcott (Archbishop) on Aug 14, 2013 at 06:48 UTC | |
by spikeinc (Acolyte) on Aug 14, 2013 at 07:37 UTC | |
by kcott (Archbishop) on Aug 14, 2013 at 09:26 UTC | |
by spikeinc (Acolyte) on Aug 15, 2013 at 05:41 UTC |
In Section
Seekers of Perl Wisdom