CESNET / Nemea-Framework

Nemea framework is the heart of the Nemea system. It contains implementation of common communication interfaces, UniRec data format and useful datastructures and algorithms.
11 stars 24 forks source link

pytrap: add read_nemea() returns pandas.DataFrame or list(dict) #185

Closed cejkato2 closed 2 years ago

cejkato2 commented 2 years ago

The new method read_nemea() works as follows:

Read `nrows` records from NEMEA TRAP interface given by `ifc_spec` and convert then into Pandas DataFrame.

Args:
  ifc_spec (str): IFC specifier for TRAP input IFC, see https://nemea.liberouter.org/trap-ifcspec/
  nrows (int): Number of records, read until end of stream (zero size message) if -1.
  array (bool): Set output type to list of dictionary instead of pandas.DataFrame

Returns:
  pandas.DataFrame or list of dictionary: DataFrame if array is False, otherwise, list of dictionary

Raises:
  ModuleNotFoundError: When pandas is not installed.

The patch also adds UnirecTemplate::getDict() that converts the single UniRec record into dict().

Example of use:

import pytrap

print(pytrap.read_nemea("f:~/osquery.trapcap"))
codecov-commenter commented 2 years ago

Codecov Report

Merging #185 (cac3773) into master (9eab911) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #185   +/-   ##
=======================================
  Coverage   80.00%   80.00%           
=======================================
  Files           2        2           
  Lines          10       10           
=======================================
  Hits            8        8           
  Misses          2        2           
Flag Coverage Δ
tests 80.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9eab911...cac3773. Read the comment docs.