Skip to content

Commit

Permalink
mkdocs up to graylog (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorwalton authored Jul 11, 2023
1 parent bd9522f commit a8a0f6b
Show file tree
Hide file tree
Showing 89 changed files with 28,076 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
#max-complexity = 18
max-line-length = 120
max-line-length = 140
#select = B,C,E,F,W,T4,B9
#ignore = E203, E266, E501, W503, F403, F401
ignore = W503, E231, W605
Expand Down
Empty file added backend/app/models/__init__.py
Empty file.
3 changes: 2 additions & 1 deletion backend/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class Connectors(db.Model):
connector_type: Column[String] = db.Column(db.String(100))
connector_url: Column[String] = db.Column(db.String(100))
connector_last_updated: Column[DateTime] = db.Column(
db.DateTime, default=datetime.utcnow,
db.DateTime,
default=datetime.utcnow,
)
connector_username: Column[String] = db.Column(db.String(100))
connector_password: Column[String] = db.Column(db.String(100))
Expand Down
Empty file added backend/app/routes/__init__.py
Empty file.
78 changes: 29 additions & 49 deletions backend/app/routes/agents.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from flask import Blueprint
from flask import jsonify

Expand All @@ -7,35 +9,27 @@
from app.services.WazuhManager.universal import UniversalService
from app.services.WazuhManager.vulnerability import VulnerabilityService

# from loguru import logger


bp = Blueprint("agents", __name__)


@bp.route("/agents", methods=["GET"])
def get_agents():
def get_agents() -> Any:
"""
Endpoint to list all available agents.
It processes each agent to verify the connection and returns the results.
Endpoint to get a list of all agents. It processes each agent and returns the results.
Returns:
json: A JSON response containing the list of all available agents along with their connection
verification status.
json: A JSON response containing the list of all available agents along with their connection verification status.
"""
service = AgentService()
agents = service.get_all_agents()
return agents


@bp.route("/agents/<agent_id>", methods=["GET"])
def get_agent(agent_id):
def get_agent(agent_id: str) -> Any:
"""
Endpoint to get the details of a agent.
Endpoint to get the details of a specific agent.
Args:
id (str): The id of the agent to be fetched.
agent_id (str): The ID of the agent to retrieve.
Returns:
json: A JSON response containing the details of the agent.
"""
Expand All @@ -45,91 +39,77 @@ def get_agent(agent_id):


@bp.route("/agents/<agent_id>/critical", methods=["POST"])
def mark_as_critical(agent_id):
def mark_as_critical(agent_id: str) -> Any:
"""
Endpoint to mark a agent as critical.
Endpoint to mark an agent as critical.
Args:
id (str): The id of the agent to be marked as critical.
agent_id (str): The ID of the agent to mark as critical.
Returns:
json: A JSON response containing the updated agent information.
json: A JSON response containing the updated agent information after being marked as critical.
"""
service = AgentService()
result = service.mark_agent_as_critical(agent_id=agent_id)
return result


@bp.route("/agents/<agent_id>/noncritical", methods=["POST"])
def unmark_agent_critical(agent_id):
def unmark_agent_critical(agent_id: str) -> Any:
"""
Endpoint to unmark a agent as critical.
Endpoint to unmark an agent as critical.
Args:
id (str): The id of the agent to be unmarked as critical.
agent_id (str): The ID of the agent to unmark as critical.
Returns:
json: A JSON response containing the updated agent information.
json: A JSON response containing the updated agent information after being unmarked as critical.
"""
service = AgentService()
result = service.mark_agent_as_non_critical(agent_id=agent_id)
return result


@bp.route("/agents/sync", methods=["POST"])
def sync_agents():
def sync_agents() -> Any:
"""
Endpoint to sync all agents.
Endpoint to synchronize all agents.
Returns:
json: A JSON response containing the updated agent information.
json: A JSON response containing the updated information of all synchronized agents.
"""
service = AgentSyncService()
result = service.sync_agents()
return jsonify(result)


@bp.route("/agents/<agent_id>/delete", methods=["POST"])
def delete_agent(agent_id):
def delete_agent(agent_id: str) -> Any:
"""
Endpoint to delete a agent.
Endpoint to delete an agent.
Args:
id (str): The id of the agent to be deleted.
agent_id (str): The ID of the agent to be deleted.
Returns:
json: A JSON response containing the updated agent information.
json: A JSON response indicating whether the deletion was successful.
"""
service = AgentService()
result = service.delete_agent_db(agent_id=agent_id)

# Delete from WazuhManager
# Create instance of UniversalService
universal_service = UniversalService()

# Pass universal_service to WazuhManagerAgentService
agent_service = WazuhManagerAgentService(universal_service)
agent_service.delete_agent(agent_id=agent_id)

return result


@bp.route("/agents/<agent_id>/vulnerabilities", methods=["GET"])
def get_agent_vulnerabilities(agent_id):
def get_agent_vulnerabilities(agent_id: str) -> Any:
"""
Endpoint to get the vulnerabilities of a agent.
Endpoint to get the vulnerabilities of a specific agent.
Args:
id (str): The id of the agent to be fetched.
agent_id (str): The ID of the agent whose vulnerabilities are to be fetched.
Returns:
json: A JSON response containing the vulnerabilities of the agent.
"""
# Create instance of UniversalService
universal_service = UniversalService()

# Pass universal_service to VulnerabilityService
vulnerability_service = VulnerabilityService(universal_service)

agent_vulnerabilities = vulnerability_service.agent_vulnerabilities(agent_id=agent_id)
agent_vulnerabilities = vulnerability_service.agent_vulnerabilities(
agent_id=agent_id,
)
return agent_vulnerabilities
16 changes: 10 additions & 6 deletions backend/app/routes/alerts.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
from flask import Blueprint
from flask import jsonify

from app.services.WazuhIndexer.alerts import AlertsService

bp = Blueprint("alerts", __name__)


@bp.route("/alerts", methods=["GET"])
def get_alerts():
def get_alerts() -> jsonify:
"""
Endpoint to list all available alerts.
It processes each alert to verify the connection and returns the results.
Retrieves all alerts from the AlertsService.
This endpoint retrieves all available alerts from the AlertsService. It does this by creating an instance of
the AlertsService class and calling its `collect_alerts` method. The result is a list of all alerts currently
available.
Returns:
json: A JSON response containing the list of all available alerts along with their connection
verification status.
jsonify: A JSON response containing a list of alerts. Each item in the list is a dictionary representing an alert,
containing all its associated data.
"""
service = AlertsService()
alerts = service.collect_alerts()
return alerts
return jsonify(alerts)
80 changes: 35 additions & 45 deletions backend/app/routes/connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
@bp.route("/connectors", methods=["GET"])
def list_connectors_available():
"""
Endpoint to list all available connectors.
It processes each connector to verify the connection and returns the results.
Endpoint to retrieve all available connectors.
Returns:
json: A JSON response containing the list of all available connectors along
with their connection verification status.
json: A JSON response containing the list of all available connectors along with their connection verification status.
"""
connectors_service = ConnectorService(db)
connectors = ConnectorsAvailable.query.all()
Expand All @@ -36,67 +34,59 @@ def list_connectors_available():


@bp.route("/connectors/<id>", methods=["GET"])
def get_connector_details(id):
def get_connector_details(id: str):
"""
Endpoint to get the details of a connector.
Endpoint to retrieve the details of a connector.
Args:
id (str): The id of the connector to be fetched.
id (str): The ID of the connector to retrieve.
Returns:
json: A JSON response containing the details of the connector.
"""
# Call service function instead of direct function call
service = ConnectorService(db)
connector_validated = service.validate_connector_exists(
int(id),
) # convert id to integer
logger.info(connector_validated)
if connector_validated["success"] is False:
return jsonify(connector_validated), 404
connector = service.validate_connector_exists(int(id))

# Fetch connector using the ID
connector = Connectors.query.get(id)
# Call service function instead of direct function call
instantiated_connector = service.process_connector(connector.connector_name)
return jsonify(instantiated_connector)
if connector["success"]:
connector = Connectors.query.get(id)
instantiated_connector = service.process_connector(connector.connector_name)
return jsonify(instantiated_connector)
else:
return jsonify(connector), 404


@bp.route("/connectors/<id>", methods=["PUT"])
def update_connector_route(id):
def update_connector_route(id: str):
"""
Endpoint to update a connector.
Endpoint to update the details of a connector.
Args:
id (str): The id of the connector to be updated.
id (str): The ID of the connector to update.
Returns:
json: A JSON response containing the success status of the update operation and
a message indicating the status. If the update operation was successful,
it returns the connector name and the status of the connection verification.
json: A JSON response containing the success status of the update operation and a message indicating the status.
If the update operation was successful, it returns the connector name and the status of the connection verification.
"""
api_key_connector = ["Shuffle", "DFIR-IRIS", "Velociraptor"]

request_data = request.get_json()
service = ConnectorService(db)
connector_validated = service.validate_connector_exists(
int(id),
) # convert id to integer
logger.info(connector_validated)
if connector_validated["success"] is False:
return jsonify(connector_validated), 404

if connector_validated["connector_name"] in api_key_connector:
data_validated = service.validate_request_data_api_key(request_data)
if data_validated["success"] is False:
return jsonify(data_validated), 400
connector = service.validate_connector_exists(int(id))

if connector["success"]:
if connector["connector_name"] in api_key_connector:
data_validated = service.validate_request_data_api_key(request_data)
if data_validated["success"]:
service.update_connector(int(id), request_data)
return service.verify_connector_connection(int(id))
else:
return jsonify(data_validated), 400
else:
service.update_connector(int(id), request_data)
return service.verify_connector_connection(int(id))

data_validated = service.validate_request_data(request_data)
if data_validated["success"] is False:
return jsonify(data_validated), 400

service.update_connector(int(id), request_data)
return service.verify_connector_connection(int(id))
data_validated = service.validate_request_data(request_data)
if data_validated["success"]:
service.update_connector(int(id), request_data)
return service.verify_connector_connection(int(id))
else:
return jsonify(data_validated), 400
else:
return jsonify(connector), 404
Loading

0 comments on commit a8a0f6b

Please sign in to comment.