Data Types¶
Bro/Zeek Types¶
Boolean¶
- class zlogging.types.BoolType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
booldata type.- Parameters:
- parse(data)[source]¶
Parse
datafrom string.- Overloads:
self, data (Literal[“T”, b”T”]) → Literal[True]
self, data (Literal[“F”, b”F”]) → Literal[False]
self, data (AnyStr) → Optional[bool]
- Parameters:
- Returns:
The parsed boolean data. If
datais unset,Nonewill be returned.- Raises:
ZeekValueError – If
datais NOT unset and NOTT(True) norF(False) in Bro/Zeek script language.- Return type:
bool | None
Numeric Types¶
- class zlogging.types.CountType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
countdata type.- Parameters:
- class zlogging.types.IntType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
intdata type.- Parameters:
Time Types¶
- class zlogging.types.TimeType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
timedata type.- Parameters:
- class zlogging.types.IntervalType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
intervaldata type.- Parameters:
- Variables:
- parse(data)[source]¶
Parse
datafrom string.
String¶
- class zlogging.types.StringType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
stringdata type.- Parameters:
Network Types¶
- class zlogging.types.PortType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
portdata type.- Parameters:
- class zlogging.types.AddrType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
addrdata type.- Parameters:
- parse(data)[source]¶
Parse
datafrom string.- Overloads:
self, data (AnyStr) → Optional[IPAddress]
self, data (IPAddress) → IPAddress
- Parameters:
data (
str|bytes|IPv4Address|IPv6Address) – raw data- Returns:
The parsed IP address. If
datais unset,Nonewill be returned.- Return type:
IPv4Address | IPv6Address | None
- tojson(data)[source]¶
Serialize
dataas JSON log format.- Overloads:
self, data (IPAddress) → str
self, data (None) → None
- Parameters:
data (
IPv4Address|IPv6Address|None) – raw data- Returns:
The JSON serialisable IP address string.
- Return type:
- toascii(data)[source]¶
Serialize
dataas ASCII log format.- Parameters:
data (
IPv4Address|IPv6Address|None) – raw data- Returns:
The ASCII representation of the IP address.
- Return type:
- class zlogging.types.SubnetType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
subnetdata type.- Parameters:
- parse(data)[source]¶
Parse
datafrom string.- Overloads:
self, data (AnyStr) → Optional[IPNetwork]
self, data (IPNetwork) → IPNetwork
- Parameters:
data (
str|bytes|IPv4Network|IPv6Network) – raw data- Returns:
The parsed IP network. If
datais unset,Nonewill be returned.- Return type:
IPv4Network | IPv6Network | None
- tojson(data)[source]¶
Serialize
dataas JSON log format.- Overloads:
self, data (IPNetwork) → str
self, data (None) → None
- Parameters:
data (
IPv4Network|IPv6Network|None) – raw data- Returns:
The JSON serialisable IP network string.
- Return type:
- toascii(data)[source]¶
Serialize
dataas ASCII log format.- Parameters:
data (
IPv4Network|IPv6Network|None) – raw data- Returns:
The ASCII representation of the IP network.
- Return type:
Enumeration¶
- class zlogging.types.EnumType(empty_field=None, unset_field=None, set_separator=None, namespaces=None, bare=False, enum_hook=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
enumdata type.- Parameters:
empty_field (
str|bytes|None) – Placeholder for empty field.unset_field (
str|bytes|None) – Placeholder for unset field.set_separator (
str|bytes|None) – Separator forset/vectorfields.bare (
bool) – IfTrue, do not loadzeeknamespace by default.enum_hook (
dict[str,Enum] |None) – Additional enum to be included in the namespace.*args (
Any) – Arbitrary positional arguments.**kwargs (
Any) – Arbitrary keyword arguments.
- parse(data)[source]¶
Parse
datafrom string.
Container Types¶
- class zlogging.types.SetType(empty_field=None, unset_field=None, set_separator=None, element_type=None, *args, **kwargs)[source]¶
Bases:
_GenericType,Generic[_S]Bro/Zeek
setdata type.- Parameters:
empty_field (
str|bytes|None) – Placeholder for empty field.unset_field (
str|bytes|None) – Placeholder for unset field.set_separator (
str|bytes|None) – Separator forset/vectorfields.element_type (
TypeVar(_S, bound= _SimpleType) |Type[TypeVar(_S, bound= _SimpleType)] |None) – Data type of container’s elements.*args (
Any) – Arbitrary positional arguments.**kwargs (
Any) – Arbitrary keyword arguments.
- Raises:
ZeekTypeError – If
element_typeis not supplied.ZeekValueError – If
element_typeis not a valid Bro/Zeek data type.
Example
As a generic data type, the class supports the typing proxy as introduced PEP 484:
>>> SetType[StringType]
which is the same at runtime as following:
>>> SetType(element_type=StringType())
Note
A valid
element_typeshould be a simple data type, i.e. a subclass of_SimpleType.
- class zlogging.types.VectorType(empty_field=None, unset_field=None, set_separator=None, element_type=None, *args, **kwargs)[source]¶
Bases:
_GenericType,Generic[_S]Bro/Zeek
vectordata type.- Parameters:
empty_field (
str|bytes|None) – Placeholder for empty field.unset_field (
str|bytes|None) – Placeholder for unset field.set_separator (
str|bytes|None) – Separator forset/vectorfields.element_type (
TypeVar(_S, bound= _SimpleType) |Type[TypeVar(_S, bound= _SimpleType)] |None) – Data type of container’s elements.*args (
Any) – Arbitrary positional arguments.**kwargs (
Any) – Arbitrary keyword arguments.
- Raises:
ZeekTypeError – If
element_typeis not supplied.ZeekValueError – If
element_typeis not a valid Bro/Zeek data type.
Example
As a generic data type, the class supports the typing proxy as introduced PEP 484:
>>> VectorType[StringType]
which is the same at runtime as following:
>>> VectorType(element_type=StringType())
Note
A valid
element_typeshould be a simple data type, i.e. a subclass of_SimpleType.
- class zlogging.types.RecordType(empty_field=None, unset_field=None, set_separator=None, *args, **element_mapping)[source]¶
Bases:
_VariadicTypeBro/Zeek
recorddata type.- Parameters:
empty_field (
str|bytes|None) – Placeholder for empty field.unset_field (
str|bytes|None) – Placeholder for unset field.set_separator (
str|bytes|None) – Separator forset/vectorfields.element_mapping (
Type[_SimpleType] |_SimpleType|_GenericType) – Data type of container’s elements.*args (Any) – Arbitrary positional arguments.
**kwargs (Any) – Arbitrary keyword arguments.
- Raises:
ZeekTypeError – If
element_mappingis not supplied.ZeekValueError – If
element_mappingis not a valid Bro/Zeek data type; or in case of inconsistency fromempty_field,unset_fieldandset_separatorof each field.
- Return type:
Note
A valid
element_mappingshould be a simple or generic data type, i.e. a subclass of_SimpleTypeor_GenericType.See also
See
_aux_expand_typing()for more information about processing the fields.
Any type¶
- class zlogging.types.AnyType(empty_field=None, unset_field=None, set_separator=None, json_encoder=None, *args, **kwargs)[source]¶
Bases:
_SimpleTypeBro/Zeek
anydata type.- Parameters:
empty_field (
str|bytes|None) – Placeholder for empty field.unset_field (
str|bytes|None) – Placeholder for unset field.set_separator (
str|bytes|None) – Separator forset/vectorfields.json_encoder (
Type[JSONEncoder] |None) – JSON encoder class fortojson()method calls.*args (
Any) – Arbitrary positional arguments.**kwargs (
Any) – Arbitrary keyword arguments.
Note
The
AnyTypeis only used for arbitrary typing as required inJSONParser. It is NOT a valid type of Bro/Zeek logging framework.- json_encoder: Type[JSONEncoder]¶
JSON encoder class for
tojson()method calls.
Abstract Base Types¶
- class zlogging.types.BaseType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
objectBase Bro/Zeek data type.
- Parameters:
- __call__(data)[source]¶
Parse
datafrom string.This is a proxy method which calls to
parse()of the type implementation.
- class zlogging.types._SimpleType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
BaseTypeSimple data type.
In Bro/Zeek script language, such simple type includes
bool,count,int,double,time,interval,string,addr,port,subnetandenum.To support arbitrary typing as required in
JSONParser,any, the arbitrary date type is also included.
- class zlogging.types._GenericType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
-
Generic data type.
In Bro/Zeek script language, such generic type includes
setandvector, which are also known as container types.- element_type: _S¶
Data type of container’s elements.
- class zlogging.types._VariadicType(empty_field=None, unset_field=None, set_separator=None, *args, **kwargs)[source]¶
Bases:
BaseTypeVariadic data type.
In Bro/Zeek script language, such variadic type refers to
record, which is also a container type.- element_mapping: OrderedDict[str, _SimpleType | _GenericType]¶
Data type of container’s elements.