mentat.datatype.sqldb

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.

group
group_id
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
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.

name
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.

managers
members
name
networks
parent_id
reports
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.

netname
network
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.

attachments
compress
createtime

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

emails
group
group_id
id

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

locale
max_attachment_size
mode
mute
redirect
template
timezone
timing
timing_per_cr
timing_per_hi
timing_per_lo
timing_per_md
timing_rel_cr
timing_rel_hi
timing_rel_lo
timing_rel_md
timing_thr_cr
timing_thr_hi
timing_thr_lo
timing_thr_md
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
createtime

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

email
enabled
fullname
id

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

locale
login
logintime
managements
memberships
organization
roles
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.