예제 #1
0
    def __init__(self):
        config = Configuration().values

        self.domain_db_path = os.path.join(config.directories.data,
                                           config.hyperscan.domain_db)
        self.rules_db_path = os.path.join(config.directories.data,
                                          config.hyperscan.rules_db)
예제 #2
0
        def _after_request(response: Response):
            """
            Logs every request that has been processed by the application.
            Logs Prometheus metrics for every request except for the status updates. (health and readiness checks)

            Args:
                response: the response to be returned

            Returns:
                the unmodified response
            """
            config = Configuration().values

            Logger() \
                .event(category="requests", action="request received") \
                .url(path=request.path, domain=request.host) \
                .source(ip=request.remote_addr) \
                .http_response(status_code=response.status_code) \
                .out(severity=Severity.INFO)

            if "status" not in request.path:
                REQUESTS_TOTAL.labels(config.node_type,
                                      str(response.status_code)).inc()

            return response
예제 #3
0
def configuration(monkeypatch, mocker):
    """
    This py.test fixture mocks the Configuration object used by the application
    """
    def pass_mock(*args):
        mock = mocker.MagicMock()

        mock.values.deployment: str = 'test'
        mock.values.log_level: str = 'debug'
        mock.values.node_type: str = 'management'

        mock.values.directories.data: str = '/home/test/redirectory_data'
        mock.values.directories.ui: str = '/home/test/redirectory_ui'

        mock.values.service.ip: str = '0.0.0.0'
        mock.values.service.port: int = 8001
        mock.values.service.metrics_port: int = 8002

        mock.values.database.type: str = 'sqlite'
        mock.values.database.path: str = 'redirectory_sqlite.db'

        mock.values.hyperscan.domain_db: str = 'hs_compiled_domain.hsd'
        mock.values.hyperscan.rules_db: str = 'hs_compiled_rules.hsd'

        mock.values.kubernetes.namespace: str = 'redirectory'
        mock.values.kubernetes.worker_selector: str = ''
        mock.values.kubernetes.management_selector: str = ''
        return mock

    from redirectory.libs_int.config import Configuration
    monkeypatch.setattr(Configuration, '__new__', pass_mock)

    from kubi_ecs_logger import Logger, Severity
    Logger().severity_output_level = Severity[str(Configuration().values.log_level).upper()]
예제 #4
0
    def get(self):
        config = Configuration().values
        is_management = config.node_type == "management"

        if HsManager().database.is_loaded or is_management:
            return make_response(jsonify({"status": "ready"}), 200)
        else:
            return api_error(message="Not Ready",
                             errors="Hyperscan database not loaded yet!",
                             status_code=400)
예제 #5
0
    def get(self, path=None):
        if path is None:
            path = "index.html"

        ui_directory = Configuration().values.directories.ui
        does_file_exist = os.path.isfile(os.path.join(ui_directory, path))

        if does_file_exist:
            return send_from_directory(ui_directory, path)
        else:
            return api_error(message="Something went wrong!",
                             errors="File not found",
                             status_code=404)
예제 #6
0
    def __new__(cls):
        if cls.__instance is None:
            cls.__instance = super(Synchronizer, cls).__new__(cls)
            cls.__instance.configuration = Configuration().values

            # Load current db version from SQL
            _, current_version = get_hs_db_version()
            cls.__instance.current_hs_db_version = current_version

            Logger().event(
                category="synchronizer",
                action="synchronizer configured",
                dataset=f"current hs db version: {current_version}").out(
                    severity=Severity.INFO)
        return cls.__instance
예제 #7
0
def start_metrics_server():
    """
    Starts a http server on a port specified in the configuration file
    and exposes Prometheus metrics on it.
    Also removes GC_COLLECTOR metrics because they are not really needed.
    """
    # Remove garbage collection metrics
    REGISTRY.unregister(GC_COLLECTOR)

    # Gather configurations
    config = Configuration().values
    ip = config.service.ip
    metrics_port = config.service.metrics_port

    # Start server
    start_wsgi_server(metrics_port)

    # Log
    Logger() \
        .event(category="runnable", action="run metrics") \
        .server(ip=ip, port=metrics_port) \
        .out(severity=Severity.INFO)
    def get(self):
        config = Configuration().values

        return make_response(jsonify({
            "configuration": config
        }), 200)
예제 #9
0
 def __init__(self):
     self.config = Configuration().values