2018-01-18 01:56:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2022-05-09 08:37:31 +00:00
|
|
|
import pytz
|
|
|
|
|
2019-10-14 03:59:24 +00:00
|
|
|
from datetime import datetime
|
2021-02-22 10:35:53 +00:00
|
|
|
|
2020-03-12 08:24:38 +00:00
|
|
|
from common.utils import get_logger
|
2022-11-04 06:22:38 +00:00
|
|
|
from common.plugins.es import ES
|
2021-04-22 09:25:06 +00:00
|
|
|
|
|
|
|
|
2022-11-04 06:22:38 +00:00
|
|
|
logger = get_logger(__file__)
|
2022-05-18 11:52:22 +00:00
|
|
|
|
|
|
|
|
2022-11-04 06:22:38 +00:00
|
|
|
class CommandStore(ES):
|
2021-02-22 10:35:53 +00:00
|
|
|
def __init__(self, config):
|
2022-04-18 10:45:38 +00:00
|
|
|
properties = {
|
|
|
|
"session": {
|
|
|
|
"type": "keyword"
|
|
|
|
},
|
|
|
|
"org_id": {
|
|
|
|
"type": "keyword"
|
|
|
|
},
|
|
|
|
"@timestamp": {
|
|
|
|
"type": "date"
|
|
|
|
},
|
|
|
|
"timestamp": {
|
|
|
|
"type": "long"
|
2021-08-17 03:20:11 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-04 06:22:38 +00:00
|
|
|
exact_fields = {}
|
|
|
|
match_fields = {'input', 'risk_level', 'user', 'asset', 'system_user'}
|
|
|
|
keyword_fields = {'session', 'org_id'}
|
2021-08-17 03:20:11 +00:00
|
|
|
|
2022-11-04 06:22:38 +00:00
|
|
|
super().__init__(config, properties, keyword_fields, exact_fields, match_fields)
|
2021-04-13 01:18:29 +00:00
|
|
|
|
2021-02-22 10:35:53 +00:00
|
|
|
@staticmethod
|
|
|
|
def make_data(command):
|
|
|
|
data = dict(
|
|
|
|
user=command["user"], asset=command["asset"],
|
2022-12-05 05:27:51 +00:00
|
|
|
account=command["account"], input=command["input"],
|
2021-02-22 10:35:53 +00:00
|
|
|
output=command["output"], risk_level=command["risk_level"],
|
|
|
|
session=command["session"], timestamp=command["timestamp"],
|
|
|
|
org_id=command["org_id"]
|
|
|
|
)
|
|
|
|
data["date"] = datetime.fromtimestamp(command['timestamp'], tz=pytz.UTC)
|
|
|
|
return data
|
2018-01-18 01:56:13 +00:00
|
|
|
|
2022-11-04 06:22:38 +00:00
|
|
|
@staticmethod
|
|
|
|
def handler_time_field(data):
|
|
|
|
timestamp__gte = data.get('timestamp__gte')
|
|
|
|
timestamp__lte = data.get('timestamp__lte')
|
2021-02-22 10:35:53 +00:00
|
|
|
timestamp_range = {}
|
|
|
|
|
|
|
|
if timestamp__gte:
|
|
|
|
timestamp_range['gte'] = timestamp__gte
|
|
|
|
if timestamp__lte:
|
|
|
|
timestamp_range['lte'] = timestamp__lte
|
2022-11-04 06:22:38 +00:00
|
|
|
return 'timestamp', timestamp_range
|