Skip to content

Commit

Permalink
asksocfortress class for connector (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorwalton authored Jul 18, 2023
1 parent 9d38a15 commit 214e7a8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions backend/app/models/connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
1 change: 1 addition & 0 deletions backend/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Connectors(db.Model):
"velociraptor": True,
"sublime": True,
"influxdb": True,
"ask-socfortress": True,
}

def __init__(
Expand Down

0 comments on commit 214e7a8

Please sign in to comment.