mentat.datatype.sqldb module

Datatype model library for PostgreSQL backend storages.

Overview

The implementation is based on the great sqlalchemy library. This module provides models for following datatypes/objects:

mentat.datatype.sqldb.UserModel

Database representation of user account objects.

mentat.datatype.sqldb.GroupModel

Database representation of group objects.

mentat.datatype.sqldb.FilterModel

Database representation of group reporting filter objects.

mentat.datatype.sqldb.NetworkModel

Database representation of network record objects for internal whois.

mentat.datatype.sqldb.SettingsReportingModel

Database representation of group settings objects.

mentat.datatype.sqldb.EventStatisticsModel

Database representation of event statistics objects.

mentat.datatype.sqldb.EventReportModel

Database representation of report objects.

mentat.datatype.sqldb.ItemChangeLogModel

Database representation of object changelog.

Warning

Current implementation is for optimalization purposes using some advanced features provided by the PostgreSQL database and no other engines are currently supported.

class mentat.datatype.sqldb.EventReportModel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Class representing event report objects within the SQL database mapped to reports_events table.

calculate_delta()[source]

Calculate delta between internal time interval boundaries.

children
createtime

Common table column for object creation timestamps, implementation is based on declared_attr pattern.

delta
dt_from
dt_to
evcount_all
evcount_flt
evcount_flt_blk
evcount_new
evcount_rep
evcount_rlp
evcount_thr
evcount_thr_blk
filtering
flag_mailed
flag_testdata
generate_label()[source]

Generate and set label from internal attributes.

groups
id

Common table column for unique numeric identifier, implementation is based on declared_attr pattern.

label
mail_dt
mail_res
mail_to
message
parent_id
severity
statistics
structured_data
to_dict()[source]

Interface implementation: Implementation of mentat.datatype.sqldb.MODEL.to_dict() method.

type
class mentat.datatype.sqldb.EventStatisticsModel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Class representing event statistics objects within the SQL database mapped to statistics_events table.

calculate_delta()[source]

Calculate and set delta between internal time interval boundaries.

calculate_interval()[source]

Calculate and set internal interval label.

count
createtime

Common table column for object creation timestamps, implementation is based on declared_attr pattern.

delta
dt_from
dt_to
static format_interval(dtl, dth)[source]

Format two given timestamps into single string desribing the interval between them. This string can be then used as a form of a label.

Parameters
  • dtl (datetime.datetime) – Lower interval boundary.

  • dth (datetime.datetime) – Upper interval boundary.

Returns

Interval between timestamps.

Return type

str

id

Common table column for unique numeric identifier, implementation is based on declared_attr pattern.

interval
stats_external
stats_internal
stats_overall
to_dict()[source]

Interface implementation: Implementation of mentat.datatype.sqldb.MODEL.to_dict() method.

class mentat.datatype.sqldb.FilterModel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Class representing reporting filters objects within the SQL database mapped to filters table.

categories
createtime

Common table column for object creation timestamps, implementation is based on declared_attr pattern.

description
detectors
enabled
filter
group
group_id
hits
id

Common table column for unique numeric identifier, implementation is based on declared_attr pattern.

is_state_disabled()[source]

Check if current filter state is disabled.

is_state_enabled()[source]

Check if current filter state is enabled.

last_hit
name
set_state_disabled()[source]

Set current filter state to disabled.

set_state_enabled()[source]

Set current filter state to enabled.

sources
to_dict()[source]

Interface implementation: Implementation of mentat.datatype.sqldb.MODEL.to_dict() method.

type
valid_from
valid_to
class mentat.datatype.sqldb.GroupModel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Class representing group objects within the SQL database mapped to groups table.

children
createtime

Common table column for object creation timestamps, implementation is based on declared_attr pattern.

description
enabled
filters
id

Common table column for unique numeric identifier, implementation is based on declared_attr pattern.

is_state_disabled()[source]

Check if current group state is disabled.

is_state_enabled()[source]

Check if current group state is enabled.

managers
members
members_wanted
name
networks
parent_id
reports
set_state_disabled()[source]

Set current group state to disabled.

set_state_enabled()[source]

Set current group state to enabled.

settings_rep
source
to_dict()[source]

Interface implementation: Implementation of mentat.datatype.sqldb.MODEL.to_dict() method.

class mentat.datatype.sqldb.ItemChangeLogModel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Class representing item changelog records within the SQL database mapped to changelogs_items table.

after
author
author_id
before
calculate_diff()[source]

Calculate difference between internal before and after attributes and store it internally into diff attribute.

createtime

Common table column for object creation timestamps, implementation is based on declared_attr pattern.

diff
endpoint
id

Common table column for unique numeric identifier, implementation is based on declared_attr pattern.

model
model_id
module
operation
class mentat.datatype.sqldb.NetworkModel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Class representing network records objects within the SQL database mapped to networks table.

createtime

Common table column for object creation timestamps, implementation is based on declared_attr pattern.

description
group
group_id
id

Common table column for unique numeric identifier, implementation is based on declared_attr pattern.

is_base
netname
network
rank
source
to_dict()[source]

Interface implementation: Implementation of mentat.datatype.sqldb.MODEL.to_dict() method.

class mentat.datatype.sqldb.SettingsReportingModel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Class representing reporting settings objects within the SQL database mapped to settings_reporting table.

createtime

Common table column for object creation timestamps, implementation is based on declared_attr pattern.

emails_critical
emails_high
emails_low
emails_medium
group
group_id
id

Common table column for unique numeric identifier, implementation is based on declared_attr pattern.

locale
mode
redirect
timezone
to_dict()[source]

Interface implementation: Implementation of mentat.datatype.sqldb.MODEL.to_dict() method.

class mentat.datatype.sqldb.UserModel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Class representing user objects within the SQL database mapped to users table.

apikey
changelogs
check_password(password_plain)[source]

Check given plaintext password agains internal password hash.

convert_lower(key, value)[source]

Convert login and email to lowercase.

createtime

Common table column for object creation timestamps, implementation is based on declared_attr pattern.

email
enabled
fullname
get_id()[source]

Mandatory interface required by the flask_login extension.

has_no_role()[source]

Returns True if the user has no role.

has_role(role)[source]

Returns True if the user identifies with the specified role.

Parameters

role (str) – A role name.

id

Common table column for unique numeric identifier, implementation is based on declared_attr pattern.

property is_active

Mandatory interface required by the flask_login extension.

property is_anonymous

Mandatory interface required by the flask_login extension.

property is_authenticated

Mandatory interface required by the flask_login extension.

is_state_disabled()[source]

Check if current user account state is disabled.

is_state_enabled()[source]

Check if current user account state is enabled.

locale
login
logintime
managements
memberships
memberships_wanted
organization
password
roles
set_password(password_plain)[source]

Generate and set password hash from given plain text password.

set_state_disabled()[source]

Set current user account state to disabled.

set_state_enabled()[source]

Set current user account state to enabled.

timezone
to_dict()[source]

Interface implementation: Implementation of mentat.datatype.sqldb.MODEL.to_dict() method.

mentat.datatype.sqldb.dictdiff(dict_obj_a, dict_obj_b)[source]

Calculate the difference between two model objects given as dicts.

mentat.datatype.sqldb.diff(obj_a, obj_b)[source]

Calculate the difference between two model objects given as dicts.

mentat.datatype.sqldb.eventstatsmodel_from_typeddict(structure, defaults=None)[source]

Convenience method for creating mentat.datatype.sqldb.EventStatisticsModel object from mentat.datatype.internal.EventStat objects.

mentat.datatype.sqldb.filtermodel_from_typeddict(structure, defaults=None)[source]

Convenience method for creating mentat.datatype.sqldb.NetworkModel object from mentat.datatype.internal.NetworkRecord objects.

mentat.datatype.sqldb.groupmodel_from_typeddict(structure, defaults=None)[source]

Convenience method for creating mentat.datatype.sqldb.GroupModel object from mentat.datatype.internal.AbuseGroup objects.

mentat.datatype.sqldb.jsondiff(json_obj_a, json_obj_b)[source]

Calculate the difference between two model objects given as JSON strings.

mentat.datatype.sqldb.networkmodel_from_typeddict(structure, defaults=None)[source]

Convenience method for creating mentat.datatype.sqldb.NetworkModel object from mentat.datatype.internal.NetworkRecord objects.

mentat.datatype.sqldb.setrepmodel_from_typeddict(structure, defaults=None)[source]

Convenience method for creating mentat.datatype.sqldb.SettingsReportingModel object from mentat.datatype.internal.AbuseGroup objects.

mentat.datatype.sqldb.usermodel_from_typeddict(structure, defaults=None)[source]

Convenience method for creating mentat.datatype.sqldb.UserModel object from mentat.datatype.internal.User objects.