Beispiel #1
0
def parse_config_file():
    global CONFIG_FILE_CONTENTS
    try:
        CONFIG_FILE_CONTENTS
    except NameError:
        default_config = os.path.join(os.path.dirname(__file__), "config.conf")
        options = DotDict()
        options.configfile = default_config

        options.esservers = list(
            getConfig('esservers', 'http://localhost:9200',
                      options.configfile).split(','))

        options.alertExchange = getConfig('alertexchange', 'alerts',
                                          options.configfile)
        options.queueName = getConfig('alertqueuename', 'alertBot',
                                      options.configfile)
        options.alerttopic = getConfig('alerttopic', 'mozdef.*',
                                       options.configfile)

        options.mquser = getConfig('mquser', 'guest', options.configfile)
        options.mqalertserver = getConfig('mqalertserver', 'localhost',
                                          options.configfile)
        options.mqpassword = getConfig('mqpassword', 'guest',
                                       options.configfile)
        options.mqport = getConfig('mqport', 5672, options.configfile)
        options.mqack = getConfig('mqack', True, options.configfile)
        CONFIG_FILE_CONTENTS = options

    return CONFIG_FILE_CONTENTS
Beispiel #2
0
    def parse_config(self):
        default_config = os.path.join(os.path.dirname(__file__), "config.conf")
        options = DotDict()
        options.configfile = default_config

        options.esservers = list(
            getConfig('esservers', 'http://localhost:9200',
                      options.configfile).split(','))

        options.alertExchange = getConfig('alertexchange', 'alerts',
                                          options.configfile)
        options.queueName = getConfig('alertqueuename', 'alertBot',
                                      options.configfile)
        options.alerttopic = getConfig('alerttopic', 'mozdef.*',
                                       options.configfile)

        options.mquser = getConfig('mquser', 'guest', options.configfile)
        options.mqalertserver = getConfig('mqalertserver', 'localhost',
                                          options.configfile)
        options.mqpassword = getConfig('mqpassword', 'guest',
                                       options.configfile)
        options.mqport = getConfig('mqport', 5672, options.configfile)
        options.mqack = getConfig('mqack', True, options.configfile)

        self.options = options
Beispiel #3
0
 def setup(self):
     sample_config = DotDict()
     sample_config.configfile = os.path.join(os.path.dirname(__file__),
                                             '../../loginput/index.conf')
     OptionParser.parse_args = mock.Mock(return_value=(sample_config, {}))
     from loginput import index
     self.application = index.application
     super(LoginputTestSuite, self).setup()
Beispiel #4
0
 def test_complex_init(self):
     original_dct = {
         'details': {
             'key1': 'value1'
         }
     }
     dct = DotDict(original_dct)
     assert dct.details == {'key1': 'value1'}
     assert dct.details.key1 == 'value1'
Beispiel #5
0
 def setup(self):
     super(TestEsworkerSNSSQS, self).setup()
     mq_conn = 'abc'
     task_queue = 'example-logs-mozdef'
     es_connection = self.es_client
     options = DotDict({
         "esbulksize": 0,
         "mozdefhostname": "unittest.hostname",
         "taskexchange": task_queue,
         'plugincheckfrequency': 120,
     })
     self.consumer = taskConsumer(mq_conn, task_queue, es_connection,
                                  options)
Beispiel #6
0
 def test_complex_get(self):
     original_dct = {
         'details': {
             'key1': 'value1',
             'subkey': {
                 'subkey': 'subvalue'
             }
         }
     }
     dct = DotDict(original_dct)
     assert dct.get('does.not.exist') == None
     assert dct.get('details') == {'key1': 'value1','subkey': {'subkey': 'subvalue'}}
     assert dct.get('details.key1') == 'value1'
     assert dct.get('details.subkey') == {'subkey':'subvalue'}
     assert dct.get('details.subkey.subkey') == 'subvalue'
Beispiel #7
0
    def onMessage(self, message, metadata):
        if 'source' not in message:
            return (message, metadata)

        if not message['source'] == 'guardduty':
            return (message, metadata)

        # reformat the date fields to iosformat
        for date_key in self.date_keys:
            if key_exists(date_key, message):
                message = self.convert_key_date_format(date_key, message)

        # convert the dict to a dot dict for saner deep key/value processing
        message=DotDict(message)
        # pull out the likely source IP address
        for ipaddress_key in self.ipaddress_keys:
            if 'sourceipaddress' not in message['details'].keys():
                if key_exists(ipaddress_key,message):
                    message.details.sourceipaddress = message.get(ipaddress_key)

        # recovert the message back to a plain dict
        return (dict(message), metadata)
import sys
import os

sys.path.append(os.path.join(os.path.dirname(__file__), "../"))
from http_test_suite import HTTPTestSuite

sys.path.append(os.path.join(os.path.dirname(__file__), "../../lib"))
from utilities.dot_dict import DotDict

import mock
from configlib import OptionParser

sample_config = DotDict()
sample_config.configfile = os.path.join(os.path.dirname(__file__),
                                        '../../rest/index.conf')
OptionParser.parse_args = mock.Mock(return_value=(sample_config, {}))

sys.path.append(os.path.join(os.path.dirname(__file__), "../../"))


class RestTestSuite(HTTPTestSuite):
    def setup(self):
        from rest import index
        self.application = index.application
        super(RestTestSuite, self).setup()
Beispiel #9
0
 def test_basic_init(self):
     dct = DotDict({'key1': 'value1', 'key2': 'value2'})
     assert sorted(dct.keys()) == sorted(['key1', 'key2'])
     assert dct.key1 == 'value1'
     assert dct.key2 == 'value2'
Beispiel #10
0
 def test_nonexisting_key(self):
     dct = DotDict()
     with pytest.raises(KeyError):
         dct.abcd
Beispiel #11
0
 def test_blank_init(self):
     dct = DotDict()
     assert dct.keys() == []