mirror of
https://github.com/Alkatrazz24/Funk-lab.git
synced 2026-07-08 14:24:42 +02:00
fix(webhook): réponse HTTP 200 immédiate + ask-agent asynchrone
BrokenPipeError corrigé : send_response(200) envoyé avant subprocess. ask-agent lancé en threading.Thread daemon — AlertManager n'attend plus. NO_COLOR=1 + TERM=dumb pour éviter les codes ANSI dans les logs. docs: alertmanager-webhook.md — architecture, flux, test, dépannage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c97e895b87
commit
3a013834aa
3 changed files with 384 additions and 13 deletions
|
|
@ -7,6 +7,7 @@ import json
|
|||
import os
|
||||
import subprocess
|
||||
import logging
|
||||
import threading
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
from datetime import datetime
|
||||
|
||||
|
|
@ -63,21 +64,27 @@ class WebhookHandler(BaseHTTPRequestHandler):
|
|||
|
||||
log.info(f"Forwarding {len(firing)} firing + {len(resolved)} resolved alerts to ask-agent monitor")
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["/usr/local/bin/ask-agent", "monitor", message],
|
||||
capture_output=True, text=True, timeout=120
|
||||
)
|
||||
log.info(f"ask-agent response: {result.stdout[:200]}")
|
||||
except subprocess.TimeoutExpired:
|
||||
log.error("ask-agent timed out")
|
||||
except Exception as e:
|
||||
log.error(f"ask-agent error: {e}")
|
||||
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(b"ok")
|
||||
|
||||
def run_agent():
|
||||
try:
|
||||
env = {**os.environ, "NO_COLOR": "1", "TERM": "dumb"}
|
||||
result = subprocess.run(
|
||||
["/usr/local/bin/ask-agent", "monitor", message],
|
||||
capture_output=True, text=True, timeout=120, env=env
|
||||
)
|
||||
log.info(f"ask-agent response: {result.stdout[:200]}")
|
||||
if result.returncode != 0:
|
||||
log.error(f"ask-agent stderr: {result.stderr[:200]}")
|
||||
except subprocess.TimeoutExpired:
|
||||
log.error("ask-agent timed out")
|
||||
except Exception as e:
|
||||
log.error(f"ask-agent error: {e}")
|
||||
|
||||
threading.Thread(target=run_agent, daemon=True).start()
|
||||
|
||||
def log_message(self, format, *args):
|
||||
pass # silence HTTP access logs
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue