mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-23 12:39:24 -07:00
refactor(subscriptions): extract SNAPSHOT_ACTIONS/COLLECT_ACTIONS to subscriptions/queries.py
Moves the subscription query dicts out of tools/live.py into a new subscriptions/queries.py module so subscriptions/resources.py can import them without creating a cross-layer subscriptions→tools dependency.
This commit is contained in:
@@ -116,3 +116,10 @@ async def test_subscribe_collect_returns_multiple_events(mock_ws):
|
|||||||
|
|
||||||
assert len(result) == 2
|
assert len(result) == 2
|
||||||
assert result[0]["notificationAdded"]["id"] == "1"
|
assert result[0]["notificationAdded"]["id"] == "1"
|
||||||
|
|
||||||
|
|
||||||
|
def test_snapshot_actions_importable_from_subscriptions() -> None:
|
||||||
|
from unraid_mcp.subscriptions.queries import COLLECT_ACTIONS, SNAPSHOT_ACTIONS
|
||||||
|
|
||||||
|
assert "cpu" in SNAPSHOT_ACTIONS
|
||||||
|
assert "log_tail" in COLLECT_ACTIONS
|
||||||
|
|||||||
40
unraid_mcp/subscriptions/queries.py
Normal file
40
unraid_mcp/subscriptions/queries.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
"""GraphQL subscription query strings for snapshot and collect operations."""
|
||||||
|
|
||||||
|
SNAPSHOT_ACTIONS = {
|
||||||
|
"cpu": """
|
||||||
|
subscription { systemMetricsCpu { id percentTotal cpus { percentTotal percentUser percentSystem percentIdle } } }
|
||||||
|
""",
|
||||||
|
"memory": """
|
||||||
|
subscription { systemMetricsMemory { id total used free available active buffcache percentTotal swapTotal swapUsed swapFree percentSwapTotal } }
|
||||||
|
""",
|
||||||
|
"cpu_telemetry": """
|
||||||
|
subscription { systemMetricsCpuTelemetry { id totalPower power temp } }
|
||||||
|
""",
|
||||||
|
"array_state": """
|
||||||
|
subscription { arraySubscription { id state capacity { kilobytes { free used total } } parityCheckStatus { status progress speed errors } } }
|
||||||
|
""",
|
||||||
|
"parity_progress": """
|
||||||
|
subscription { parityHistorySubscription { date status progress speed errors correcting paused running } }
|
||||||
|
""",
|
||||||
|
"ups_status": """
|
||||||
|
subscription { upsUpdates { id name model status battery { chargeLevel estimatedRuntime health } power { inputVoltage outputVoltage loadPercentage } } }
|
||||||
|
""",
|
||||||
|
"notifications_overview": """
|
||||||
|
subscription { notificationsOverview { unread { info warning alert total } archive { info warning alert total } } }
|
||||||
|
""",
|
||||||
|
"owner": """
|
||||||
|
subscription { ownerSubscription { username url avatar } }
|
||||||
|
""",
|
||||||
|
"server_status": """
|
||||||
|
subscription { serversSubscription { id name status guid wanip lanip localurl remoteurl } }
|
||||||
|
""",
|
||||||
|
}
|
||||||
|
|
||||||
|
COLLECT_ACTIONS = {
|
||||||
|
"notification_feed": """
|
||||||
|
subscription { notificationAdded { id title subject description importance type timestamp } }
|
||||||
|
""",
|
||||||
|
"log_tail": """
|
||||||
|
subscription LogTail($path: String!) { logFile(path: $path) { path content totalLines startLine } }
|
||||||
|
""",
|
||||||
|
}
|
||||||
@@ -15,50 +15,12 @@ from fastmcp import FastMCP
|
|||||||
|
|
||||||
from ..config.logging import logger
|
from ..config.logging import logger
|
||||||
from ..core.exceptions import ToolError, tool_error_handler
|
from ..core.exceptions import ToolError, tool_error_handler
|
||||||
|
from ..subscriptions.queries import COLLECT_ACTIONS, SNAPSHOT_ACTIONS
|
||||||
from ..subscriptions.snapshot import subscribe_collect, subscribe_once
|
from ..subscriptions.snapshot import subscribe_collect, subscribe_once
|
||||||
|
|
||||||
|
|
||||||
_ALLOWED_LOG_PREFIXES = ("/var/log/", "/boot/logs/", "/mnt/")
|
_ALLOWED_LOG_PREFIXES = ("/var/log/", "/boot/logs/", "/mnt/")
|
||||||
|
|
||||||
SNAPSHOT_ACTIONS = {
|
|
||||||
"cpu": """
|
|
||||||
subscription { systemMetricsCpu { id percentTotal cpus { percentTotal percentUser percentSystem percentIdle } } }
|
|
||||||
""",
|
|
||||||
"memory": """
|
|
||||||
subscription { systemMetricsMemory { id total used free available active buffcache percentTotal swapTotal swapUsed swapFree percentSwapTotal } }
|
|
||||||
""",
|
|
||||||
"cpu_telemetry": """
|
|
||||||
subscription { systemMetricsCpuTelemetry { id totalPower power temp } }
|
|
||||||
""",
|
|
||||||
"array_state": """
|
|
||||||
subscription { arraySubscription { id state capacity { kilobytes { free used total } } parityCheckStatus { status progress speed errors } } }
|
|
||||||
""",
|
|
||||||
"parity_progress": """
|
|
||||||
subscription { parityHistorySubscription { date status progress speed errors correcting paused running } }
|
|
||||||
""",
|
|
||||||
"ups_status": """
|
|
||||||
subscription { upsUpdates { id name model status battery { chargeLevel estimatedRuntime health } power { inputVoltage outputVoltage loadPercentage } } }
|
|
||||||
""",
|
|
||||||
"notifications_overview": """
|
|
||||||
subscription { notificationsOverview { unread { info warning alert total } archive { info warning alert total } } }
|
|
||||||
""",
|
|
||||||
"owner": """
|
|
||||||
subscription { ownerSubscription { username url avatar } }
|
|
||||||
""",
|
|
||||||
"server_status": """
|
|
||||||
subscription { serversSubscription { id name status guid wanip lanip localurl remoteurl } }
|
|
||||||
""",
|
|
||||||
}
|
|
||||||
|
|
||||||
COLLECT_ACTIONS = {
|
|
||||||
"notification_feed": """
|
|
||||||
subscription { notificationAdded { id title subject description importance type timestamp } }
|
|
||||||
""",
|
|
||||||
"log_tail": """
|
|
||||||
subscription LogTail($path: String!) { logFile(path: $path) { path content totalLines startLine } }
|
|
||||||
""",
|
|
||||||
}
|
|
||||||
|
|
||||||
ALL_LIVE_ACTIONS = set(SNAPSHOT_ACTIONS) | set(COLLECT_ACTIONS)
|
ALL_LIVE_ACTIONS = set(SNAPSHOT_ACTIONS) | set(COLLECT_ACTIONS)
|
||||||
|
|
||||||
LIVE_ACTIONS = Literal[
|
LIVE_ACTIONS = Literal[
|
||||||
|
|||||||
Reference in New Issue
Block a user