diff --git a/backend/app/models/connectors.py b/backend/app/models/connectors.py index 7738aee7..6fec999b 100644 --- a/backend/app/models/connectors.py +++ b/backend/app/models/connectors.py @@ -425,6 +425,60 @@ def verify_connection(self) -> Dict[str, Any]: return {"connectionSuccessful": False, "response": None} +class AskSOCFortressConnector(Connector): + """ + A connector for the ASK SOCFortress service, a subclass of Connector. + + Args: + connector_name (str): The name of the connector. + """ + + def __init__(self, connector_name: str): + super().__init__(attributes=self.get_connector_info_from_db(connector_name)) + + def verify_connection(self) -> Dict[str, Any]: + """ + Verifies the connection to ASK SOCFortress service. + + Returns: + dict: A dictionary containing 'connectionSuccessful' status and 'response' if the connection is successful. + """ + logger.info( + f"Verifying the ASK SOCFortress connection to {self.attributes['connector_url']}", + ) + try: + headers = { + "Content-Type": "application/json", + "x-api-key": f"{self.attributes['connector_api_key']}", + "module-version": "1.0", + } + payload = { + "rule_description": "Summary event of the report's signatures.", + } + ask_socfortress = requests.post( + f"{self.attributes['connector_url']}", + headers=headers, + data=json.dumps(payload), + verify=False, + timeout=60, + ) + if ask_socfortress.status_code == 200: + logger.info( + f"Connection to {self.attributes['connector_url']} successful", + ) + return {"connectionSuccessful": True} + else: + logger.error( + f"Connection to {self.attributes['connector_url']} failed with error: {ask_socfortress.text}", + ) + return {"connectionSuccessful": False, "response": None} + except Exception as e: + logger.error( + f"Connection to {self.attributes['connector_url']} failed with error: {e}", + ) + return {"connectionSuccessful": False, "response": None} + + class InfluxDBConnector(Connector): """ A connector for the InfluxDB service, a subclass of Connector. @@ -578,3 +632,4 @@ def create(self, key, connector_name): connector_factory.register_creator("Shuffle", "ShuffleConnector") connector_factory.register_creator("Sublime", "SublimeConnector") connector_factory.register_creator("InfluxDB", "InfluxDBConnector") +connector_factory.register_creator("AskSocfortress", "AskSOCFortressConnector") diff --git a/backend/app/models/models.py b/backend/app/models/models.py index fc03b844..727bf925 100644 --- a/backend/app/models/models.py +++ b/backend/app/models/models.py @@ -110,6 +110,7 @@ class Connectors(db.Model): "velociraptor": True, "sublime": True, "influxdb": True, + "ask-socfortress": True, } def __init__(