Skip to content
Snippets Groups Projects
Commit 710f35d5 authored by Rajmund Hruška's avatar Rajmund Hruška
Browse files

Feature: Add internal structure for detectors. (Redmine issue: #7577)

parent b036337b
No related branches found
No related tags found
No related merge requests found
...@@ -949,6 +949,51 @@ class EventStat(typedcols.TypedDict): ...@@ -949,6 +949,51 @@ class EventStat(typedcols.TypedDict):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def typedef_detector(flavour, list_flavour, addon = None):
"""
Typedef generator for detector records.
"""
tdef = {
'_id': {
'type': flavour['String'],
'required': True
},
'ts': {
'type': flavour['Datetime'],
'required': True,
'default': time.time
},
'name': {
'type': flavour['String'],
'required': True
},
'source': {
'type': flavour['String'],
'required': True
},
'description': {
'type': flavour['String']
},
'credibility': {
'type': flavour['Float'],
'required': True
}
}
if addon is not None:
tdef.update(addon)
return tdef
class Detector(typedcols.TypedDict):
"""
Implementation of detector structure.
"""
allow_unknown = True
typedef = typedef_detector(types_internal, types_internal_list)
#-------------------------------------------------------------------------------
def typedef_report(flavour, list_flavour, addon = None): def typedef_report(flavour, list_flavour, addon = None):
""" """
Typedef generator for report records. Typedef generator for report records.
......
...@@ -212,6 +212,14 @@ class TestMentatDatatypeInternal(unittest.TestCase): ...@@ -212,6 +212,14 @@ class TestMentatDatatypeInternal(unittest.TestCase):
"name" : "Jan Mach" "name" : "Jan Mach"
} }
detector_raw = {
"_id" : "1",
"ts" : 1388577600,
"source" : "warden",
"credibility" : 0.73,
"name" : "Test detector"
}
def setUp(self): def setUp(self):
pass pass
...@@ -306,6 +314,20 @@ class TestMentatDatatypeInternal(unittest.TestCase): ...@@ -306,6 +314,20 @@ class TestMentatDatatypeInternal(unittest.TestCase):
if self.verbose: if self.verbose:
pprint(uac) pprint(uac)
def test_05_detector(self):
"""
Perform tests of parsing detectors.
"""
self.maxDiff = None
det = mentat.datatype.internal.Detector(self.detector_raw)
self.assertEqual(det['_id'], '1')
self.assertEqual(det['credibility'], 0.73)
self.assertEqual(det['name'], 'Test detector')
self.assertEqual(det['source'], 'warden')
if self.verbose:
pprint(det)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment