Skip to content

generic.py

Complex configuration objects

To import...

from dynamite_nsm.services.base.config_objects import generic

Analyzer

Analyzers are packages used for identifying Zeek scripts and signatures as well as Suricata rule-sets

__init__(self, name, enabled=False, content=None) special

Create a simple analyzer object

Parameters:

Name Type Description Default
name str

The name (or often path) to the analyzer

required
enabled Optional[bool]

True, if enabled

False
content Optional[str]

If included the contents of the analyzer will be used to generate a unique hash.

None
Source code in dynamite_nsm/services/base/config_objects/generic.py
def __init__(self, name: str, enabled: Optional[bool] = False, content: Optional[str] = None):
    """
    Create a simple analyzer object

    Args:
        name: The name (or often path) to the analyzer
        enabled: True, if enabled
        content: If included the contents of the analyzer will be used to generate a unique hash.
    """
    self.name = name
    self.enabled = enabled

    if not content:
        self.id = sha256(str(name).encode("utf-8")).hexdigest()[0:7]
    else:
        self.id = sha256(str(content).encode("utf-8")).hexdigest()[0:7]

Analyzers

A Group of Analyzers; provides some basic methods for filtering and display

get_disabled(self)

Get all analyzers that are disabled.

Returns:

Type Description
List[dynamite_nsm.services.base.config_objects.generic.Analyzer]

A list of disabled Analyzer packages

Source code in dynamite_nsm/services/base/config_objects/generic.py
def get_disabled(self) -> List[Analyzer]:
    """Get all analyzers that are disabled.
    Returns:
        A list of disabled `Analyzer` packages
    """
    return [analyzer for analyzer in self.analyzers if not analyzer.enabled]

get_enabled(self)

Get all analyzers that are enabled.

Returns:

Type Description
List[dynamite_nsm.services.base.config_objects.generic.Analyzer]

A list of enabled Analyzer packages

Source code in dynamite_nsm/services/base/config_objects/generic.py
def get_enabled(self) -> List[Analyzer]:
    """Get all analyzers that are enabled.
    Returns:
        A list of enabled `Analyzer` packages
    """
    return [analyzer for analyzer in self.analyzers if analyzer.enabled]

get_raw(self)

Get the analyzers in a format that can be directly written to a corresponding configuration

Returns:

Type Description
List[str]

A list of analyzer names.

Source code in dynamite_nsm/services/base/config_objects/generic.py
def get_raw(self) -> List[str]:
    """
    Get the analyzers in a format that can be directly written to a corresponding configuration
    Returns:
        A list of analyzer names.
    """
    return [analyzer.name for analyzer in self.analyzers if analyzer.enabled]

GenericItem

Empty Class

GenericItemGroup

__init__(self, identifier_attribute, items=None) special

A base class representing simple groups of configuration options, where each group is unique.

Parameters:

Name Type Description Default
identifier_attribute str

The name of an attribute found within the GenericItem list used for identification

required
items Optional[List[dynamite_nsm.services.base.config_objects.generic.GenericItem]]

A list of GenericItems

None
Source code in dynamite_nsm/services/base/config_objects/generic.py
def __init__(self, identifier_attribute: str, items: Optional[List[GenericItem]] = None, ):
    """
    A base class representing simple groups of configuration options, where each group is unique.

    Args:
        identifier_attribute: The name of an attribute found within the GenericItem list used for identification
        items: A list of GenericItems
    """
    self.identifier_attribute = identifier_attribute
    self.items = items
    if items is None:
        self.items = []
    self._idx = 0