import subprocess
from json import loads
p = subprocess.Popen(
['/usr/local/bin/sflowtool','-j'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
lines = iter(p.stdout.readline,'')
for line in lines:
print line
datagram = loads(line)
localtime = datagram["localtime"]
samples = datagram["samples"]
for sample in samples:
sampleType = sample["sampleType"]
elements = sample["elements"]
if sampleType == "FLOWSAMPLE":
for element in elements:
tag = element["flowBlock_tag"]
if tag == "0:1":
try:
src = element["srcIP"]
dst = element["dstIP"]
pktsize = element["sampledPacketSize"]
print "%s %s %s %s" % (localtime,src,dst,pktsize)
except KeyError:
pass
I think I found the issue in the code sflowtool.c file.
A comma is needed in these instances to make the JSON a valid one:
I am relatively novice in coding C, so will try to fix the bug and push a pull request.
However, any help from the developers is much appreciated.
--
You received this message because you are subscribed to the Google Groups "sFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sflow+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sflow/ea643cae-c81c-46a0-8603-f9475a60f035%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/sflow/CAB1FvaJS-eFsN%2BoafnN7bzCaGQVjieTfKpNawq02ziLWnOiMHg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sflow/CAEhSuGSe9EBVF0%2B7kCfQWnRejBEXcr4ix9%2BbJn_swx5S8Z4gdw%40mail.gmail.com.
Hello Anu , Im sorry im not familiar with python , i used jsonparser in java .Good Luck.
On Wed, Jul 17, 2019 at 11:05 PM anu mercian <freebi...@gmail.com> wrote:
Thank you very much for the quick response. Truly appreciate it.Regards,Anu
To unsubscribe from this group and stop receiving emails from it, send an email to sf...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sflow/ea643cae-c81c-46a0-8603-f9475a60f035%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "sFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sf...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sflow/CAB1FvaJS-eFsN%2BoafnN7bzCaGQVjieTfKpNawq02ziLWnOiMHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "sFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sf...@googlegroups.com.