Knowledge base:
Easy automation with the JSON reports
Posted by Pieter Vandercammen, Last modified by Pieter Vandercammen on 26 May 2021 01:46 PM

09:01 A.M., Work is done! 

Easy automation with the new JSON report. 


The ByteBlower GUI and CLT now have a new type of report: JSON. Just like CSV, this format is intended for machines rather than us humans. Actually, JSON is a huge improvement over CSV. 

As an example, check out the Python code below. 15 lines to check whether our network device did or did not lose traffic in your overnight test. 

Opening the JSON Report 

JSON files can be read in easily in many languages. Check out the Python example below.

import json
def open_json_report(report_filename):
        Opens the report for further processing  
    with open(report_filename, "r") as f:
        return json.load(f)


Processing a testrun 

Once the report is loaded, you have access to same information as in the other reports. Labor-intensive questions can easily  beanswered in a short script.  

Does your project have many FrameBlasting flows?  
Do you want count how traffic much was lost in total?  
Did you check out the script below? 

    def count_received_traffic(report_data):
            Lost traffic is bad news. How much did we receive?
            Returns the value as percentage: 100 is nothing lost.
        total_expected = 0
        total_received = 0
        for fb_flow in report_data["frameBlastingFlows"]:
            for a_destination in fb_flow["destinations"]:
                total_expected += fb_flow["source"]["sent"]["packets"]
                total_received += a_destination["received"]["packets"]
        if total_expected == 0:
            return 0
            return 100. * total_received / total_expected

    Making work easier 

    But in the end our goal is to make life easier. Just that is possible with the JSON format. Rather than going over single test-run, why not let the computer do it? 

      def test_a_report(report_filename):
              Pass or Fail? Did this nights test succeed?
          report_data = open_json_report(report_filename)
          received = count_received_traffic(report_data)
          assert received < 99.9, "FAIL, too much traffic lost in " + report_filename
          print("PASS: We had good testrun")
      (0 vote(s))
      Not helpful

      Comments (0)

      We to help you!