- Add intel_service.py: RSS feed scanner for threat intelligence Searches CISA, NIST NVD, SANS ISC, BleepingComputer, The Hacker News, Krebs on Security for mentions of MITRE technique IDs and names - New intel items stored in intel_items table with URL deduplication - Techniques with new intel flagged with review_required=True - Add POST /system/run-intel-scan endpoint (admin only) - Register weekly intel scan job in APScheduler (every 7 days) - Audit log records each scan execution with summary stats - Update README with new endpoint and project structure
79 lines
2.1 KiB
Python
79 lines
2.1 KiB
Python
"""System-level endpoints (admin only).
|
|
|
|
Provides manual triggers for background operations such as the MITRE
|
|
ATT&CK synchronisation, intel scanning, and scheduler health introspection.
|
|
"""
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.database import get_db
|
|
from app.dependencies.auth import require_role
|
|
from app.models.user import User
|
|
from app.services.mitre_sync_service import sync_mitre
|
|
from app.services.intel_service import scan_intel
|
|
from app.jobs.mitre_sync_job import scheduler
|
|
|
|
router = APIRouter(prefix="/system", tags=["system"])
|
|
|
|
|
|
@router.post("/sync-mitre")
|
|
def trigger_mitre_sync(
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(require_role("admin")),
|
|
):
|
|
"""Manually trigger a MITRE ATT&CK synchronisation.
|
|
|
|
**Requires** the ``admin`` role.
|
|
|
|
Returns a JSON object with the sync summary including the count of
|
|
new and updated techniques.
|
|
"""
|
|
summary = sync_mitre(db)
|
|
return {
|
|
"message": "MITRE sync completed",
|
|
"new": summary["created"],
|
|
"updated": summary["updated"],
|
|
}
|
|
|
|
|
|
@router.post("/run-intel-scan")
|
|
def trigger_intel_scan(
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(require_role("admin")),
|
|
):
|
|
"""Manually trigger a threat-intelligence scan.
|
|
|
|
**Requires** the ``admin`` role.
|
|
|
|
Returns a JSON object with the scan summary including the count of
|
|
new intel items found.
|
|
"""
|
|
summary = scan_intel(db)
|
|
return {
|
|
"message": "Intel scan completed",
|
|
"new_items": summary["new_items"],
|
|
}
|
|
|
|
|
|
@router.get("/scheduler-status")
|
|
def scheduler_status(
|
|
current_user: User = Depends(require_role("admin")),
|
|
):
|
|
"""Return the current state of the background scheduler.
|
|
|
|
**Requires** the ``admin`` role.
|
|
"""
|
|
jobs = scheduler.get_jobs()
|
|
return {
|
|
"running": scheduler.running,
|
|
"jobs": [
|
|
{
|
|
"id": job.id,
|
|
"name": job.name,
|
|
"next_run_time": str(job.next_run_time) if job.next_run_time else None,
|
|
}
|
|
for job in jobs
|
|
],
|
|
}
|