@cryptotaxi247 / CoPilot / commits / 214e7a87

asksocfortress class for connector (#45)

taylor_socfortress committed Jul 17, 2023 at 18:07 UTC 214e7a8736f55a3ea826223009ad38c8d9264017
2 files changed +56
backend/app/models/connectors.py
+55
@@ -425,6 +425,60 @@ class SublimeConnector(Connector):
425 return {"connectionSuccessful": False, "response": None}
426
427
428 +class AskSOCFortressConnector(Connector):
429 + """
430 + A connector for the ASK SOCFortress service, a subclass of Connector.
431 +
432 + Args:
433 + connector_name (str): The name of the connector.
434 + """
435 +
436 + def __init__(self, connector_name: str):
437 + super().__init__(attributes=self.get_connector_info_from_db(connector_name))
438 +
439 + def verify_connection(self) -> Dict[str, Any]:
440 + """
441 + Verifies the connection to ASK SOCFortress service.
442 +
443 + Returns:
444 + dict: A dictionary containing 'connectionSuccessful' status and 'response' if the connection is successful.
445 + """
446 + logger.info(
447 + f"Verifying the ASK SOCFortress connection to {self.attributes['connector_url']}",
448 + )
449 + try:
450 + headers = {
451 + "Content-Type": "application/json",
452 + "x-api-key": f"{self.attributes['connector_api_key']}",
453 + "module-version": "1.0",
454 + }
455 + payload = {
456 + "rule_description": "Summary event of the report's signatures.",
457 + }
458 + ask_socfortress = requests.post(
459 + f"{self.attributes['connector_url']}",
460 + headers=headers,
461 + data=json.dumps(payload),
462 + verify=False,
463 + timeout=60,
464 + )
465 + if ask_socfortress.status_code == 200:
466 + logger.info(
467 + f"Connection to {self.attributes['connector_url']} successful",
468 + )
469 + return {"connectionSuccessful": True}
470 + else:
471 + logger.error(
472 + f"Connection to {self.attributes['connector_url']} failed with error: {ask_socfortress.text}",
473 + )
474 + return {"connectionSuccessful": False, "response": None}
475 + except Exception as e:
476 + logger.error(
477 + f"Connection to {self.attributes['connector_url']} failed with error: {e}",
478 + )
479 + return {"connectionSuccessful": False, "response": None}
480 +
481 +
482 class InfluxDBConnector(Connector):
483 """
484 A connector for the InfluxDB service, a subclass of Connector.
@@ -578,3 +632,4 @@ connector_factory.register_creator("RabbitMQ", "RabbitMQConnector")
632 connector_factory.register_creator("Shuffle", "ShuffleConnector")
633 connector_factory.register_creator("Sublime", "SublimeConnector")
634 connector_factory.register_creator("InfluxDB", "InfluxDBConnector")
635 +connector_factory.register_creator("AskSocfortress", "AskSOCFortressConnector")
backend/app/models/models.py
+1
@@ -110,6 +110,7 @@ class Connectors(db.Model):
110 "velociraptor": True,
111 "sublime": True,
112 "influxdb": True,
113 + "ask-socfortress": True,
114 }
115
116 def __init__(