fix restart issue
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,11 +1,34 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import contextlib
|
||||||
import json
|
import json
|
||||||
|
import signal
|
||||||
import ssl
|
import ssl
|
||||||
|
import threading
|
||||||
from urllib import error, request
|
from urllib import error, request
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def _hard_timeout(seconds: int):
|
||||||
|
if seconds <= 0 or threading.current_thread() is not threading.main_thread() or not hasattr(signal, "SIGALRM"):
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
previous_handler = signal.getsignal(signal.SIGALRM)
|
||||||
|
previous_timer = signal.getitimer(signal.ITIMER_REAL)
|
||||||
|
|
||||||
|
def _raise_timeout(_signum, _frame):
|
||||||
|
raise TimeoutError(f"mcp_call_timeout_{seconds}s")
|
||||||
|
|
||||||
|
signal.signal(signal.SIGALRM, _raise_timeout)
|
||||||
|
signal.setitimer(signal.ITIMER_REAL, seconds)
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
signal.setitimer(signal.ITIMER_REAL, previous_timer[0], previous_timer[1])
|
||||||
|
signal.signal(signal.SIGALRM, previous_handler)
|
||||||
|
|
||||||
|
|
||||||
class GraylogMcpClient:
|
class GraylogMcpClient:
|
||||||
"""Small Streamable HTTP MCP client used for Graylog connection checks."""
|
"""Small Streamable HTTP MCP client used for Graylog connection checks."""
|
||||||
|
|
||||||
@@ -42,6 +65,7 @@ class GraylogMcpClient:
|
|||||||
req = request.Request(self.url, data=json.dumps(payload).encode("utf-8"), method="POST", headers=headers)
|
req = request.Request(self.url, data=json.dumps(payload).encode("utf-8"), method="POST", headers=headers)
|
||||||
try:
|
try:
|
||||||
context = None if self.verify_tls else ssl._create_unverified_context()
|
context = None if self.verify_tls else ssl._create_unverified_context()
|
||||||
|
with _hard_timeout(self.timeout + 1):
|
||||||
with self._open(req, context) as response:
|
with self._open(req, context) as response:
|
||||||
self.session_id = response.headers.get("Mcp-Session-Id", self.session_id)
|
self.session_id = response.headers.get("Mcp-Session-Id", self.session_id)
|
||||||
body = response.read().decode("utf-8")
|
body = response.read().decode("utf-8")
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ class DashboardTests(unittest.TestCase):
|
|||||||
self.assertIn("function mcpCapability", HTML)
|
self.assertIn("function mcpCapability", HTML)
|
||||||
self.assertIn("connected, ${suffix}", HTML)
|
self.assertIn("connected, ${suffix}", HTML)
|
||||||
|
|
||||||
|
def test_dashboard_has_visible_incident_action_status(self):
|
||||||
|
self.assertIn("incidentNotice", HTML)
|
||||||
|
self.assertIn("Incident marked", HTML)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user