mirror of
https://github.com/infinition/Bjorn.git
synced 2026-03-16 01:01:58 +00:00
Add Loki and Sentinel utility classes for web API endpoints
- Implemented LokiUtils class with GET and POST endpoints for managing scripts, jobs, and payloads. - Added SentinelUtils class with GET and POST endpoints for managing events, rules, devices, and notifications. - Both classes include error handling and JSON response formatting.
This commit is contained in:
51
db_utils/loki.py
Normal file
51
db_utils/loki.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
Loki DB operations — HID scripts and job tracking.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from logger import Logger
|
||||
|
||||
logger = Logger(name="db_utils.loki", level=logging.DEBUG)
|
||||
|
||||
|
||||
class LokiOps:
|
||||
def __init__(self, base):
|
||||
self.base = base
|
||||
|
||||
def create_tables(self):
|
||||
"""Create all Loki tables."""
|
||||
|
||||
# User-saved HID scripts
|
||||
self.base.execute("""
|
||||
CREATE TABLE IF NOT EXISTS loki_scripts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
description TEXT DEFAULT '',
|
||||
content TEXT NOT NULL DEFAULT '',
|
||||
category TEXT DEFAULT 'general',
|
||||
target_os TEXT DEFAULT 'any',
|
||||
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TEXT DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
|
||||
# Job execution history
|
||||
self.base.execute("""
|
||||
CREATE TABLE IF NOT EXISTS loki_jobs (
|
||||
id TEXT PRIMARY KEY,
|
||||
script_id INTEGER,
|
||||
script_name TEXT DEFAULT '',
|
||||
status TEXT DEFAULT 'pending',
|
||||
output TEXT DEFAULT '',
|
||||
error TEXT DEFAULT '',
|
||||
started_at TEXT,
|
||||
finished_at TEXT,
|
||||
created_at TEXT DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
self.base.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_loki_jobs_status "
|
||||
"ON loki_jobs(status)"
|
||||
)
|
||||
|
||||
logger.debug("Loki tables created/verified")
|
||||
Reference in New Issue
Block a user