Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/datastore' into datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
Linko91 committed Sep 19, 2024
2 parents 64f6932 + b094ee6 commit 33bc543
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
21 changes: 21 additions & 0 deletions backend/app/connectors/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,24 @@ async def get_connector_info_from_db(
else:
logger.warning("No connector found.")
return None

async def is_connector_verified(connector_name: str, db: AsyncSession) -> bool:
"""
Checks if a connector is verified.
Args:
connector_name (str): The name of the connector to check.
db (AsyncSession): The database session.
Returns:
bool: True if the connector is verified, otherwise False.
"""
logger.info(f"Checking if connector {connector_name} is verified")
query = select(Connectors).where(Connectors.connector_name == connector_name)
result = await db.execute(query)
connector = result.scalars().first()
if connector:
return connector.connector_verified
else:
logger.warning("No connector found.")
return False
12 changes: 10 additions & 2 deletions backend/app/schedulers/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,14 @@ async def initialize_job_metadata():
"function": agent_sync,
"description": "Synchronizes agents with the Wazuh Manager and Velociraptor server.",
},
# {
# "job_id": "wazuh_index_fields_resize",
# "time_interval": 1,
# "function": resize_wazuh_index_fields,
# "description": "Resizes the Wazuh index fields.",
# },
{
"job_id": "wazuh_index_fields_resize",
"job_id": "resize_wazuh_index_fields",
"time_interval": 1,
"function": resize_wazuh_index_fields,
"description": "Resizes the Wazuh index fields.",
Expand Down Expand Up @@ -195,6 +201,7 @@ async def schedule_enabled_jobs(scheduler):
"invoke_suricata_monitoring_alert",
"invoke_office365_exchange_online_alert",
"invoke_office365_threat_intel_alert",
"wazuh_index_fields_resize",
]

# Disable each job in the list
Expand Down Expand Up @@ -241,7 +248,8 @@ def get_function_by_name(function_name: str):
"""
function_map = {
"agent_sync": agent_sync,
"wazuh_index_fields_resize": resize_wazuh_index_fields,
#"wazuh_index_fields_resize": resize_wazuh_index_fields,
"resize_wazuh_index_fields": resize_wazuh_index_fields,
"invoke_alert_creation_collect": invoke_alert_creation_collect,
"invoke_sigma_queries_collect": invoke_sigma_queries_collect,
"invoke_mimecast_integration": invoke_mimecast_integration,
Expand Down
11 changes: 8 additions & 3 deletions backend/app/schedulers/services/wazuh_index_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)
from app.db.db_session import get_db_session
from app.schedulers.models.scheduler import JobMetadata
from app.connectors.utils import is_connector_verified


async def resize_wazuh_index_fields():
Expand All @@ -18,13 +19,17 @@ async def resize_wazuh_index_fields():
to synchronize agents, and updates the job metadata with the last success timestamp.
If the token retrieval fails, it prints a failure message. If the job metadata for
'wazuh_index_fields_resize' does not exist, it prints a message indicating the absence of the metadata.
'resize_wazuh_index_fields' does not exist, it prints a message indicating the absence of the metadata.
"""
logger.info("Resizing Wazuh index fields via scheduler...")
async with get_db_session() as session:
if not await is_connector_verified("Wazuh-Indexer", session):
logger.warning("Wazuh Indexer connector is not verified.")
return None
logger.info("Wazuh Indexer connector is verified.")
await resize_wazuh_index_fields_route()

stmt = select(JobMetadata).where(JobMetadata.job_id == "wazuh_index_fields_resize")
stmt = select(JobMetadata).where(JobMetadata.job_id == "resize_wazuh_index_fields")
result = await session.execute(stmt)
job_metadata = result.scalars().first()

Expand All @@ -34,4 +39,4 @@ async def resize_wazuh_index_fields():
await session.commit() # Asynchronously commit the transaction
logger.info("Updated job metadata with the last success timestamp.")
else:
logger.warning("JobMetadata for 'wazuh_index_fields_resize' not found.")
logger.warning("JobMetadata for 'resize_wazuh_index_fields' not found.")

0 comments on commit 33bc543

Please sign in to comment.