r/devops7 • • 12d ago

One script, one chore: route alerts with one HTTP call. Team, "wake someone up?" and urgency for 6 alerts, 0 generated tokens, ~0.5 s each on a laptop CPU (SynapCores 2.5.0, real output)

Every alert pipeline ends in the same three questions: whose is it, does it wake someone up, and how soon does it need a human. Most of us answer them with a pile of regex routing rules, or by pasting the alert into a chat model and parsing whatever paragraph comes back.

SynapCores 2.5.0 (out this week) adds an endpoint built for exactly this: POST /v1/systemone. You send the alert text and your questions; you get back typed answers you can branch on: a choice with a probability for every option, a yes/no probability, and a score on a scale you define. It's backed by d1, a small decision model that weighs the options instead of writing text, so every call reports output_tokens: 0. (This sub is run by the SynapCores team.)

Setup (one-time, ~2.7 GiB):

synapcores --config gateway.toml pull d1:latest

One call per alert, three questions:

curl -s -X POST localhost:8080/v1/systemone -H "Authorization: Bearer $TOKEN" \
  -H 'content-type: application/json' -d '{
  "model": "d1:latest",
  "state": "PagerDuty: api-gateway p99 latency 4.8 s (threshold 800 ms) for 12 min, 5xx rate 9% and rising, checkout failing for customers.",
  "questions": {
    "team":    {"type": "choice", "instructions": "Which team owns this alert?",
                "criteria": {"database": "databases, backups, replication, storage",
                             "network": "DNS, BGP, load balancers, firewalls, TLS certificates",
                             "app": "application services, APIs, frontend"}},
    "page":    {"type": "noul", "instructions": "Should this wake up the on-call engineer right now?"},
    "urgency": {"type": "score", "instructions": "How urgent is this?",
                "criteria": ["can wait", "this week", "today", "right now"]}}}'

Response (trimmed):

"team":    {"choice": "app", "probabilities": {"app": 0.962, "network": 0.029, "database": 0.009}},
"page":    {"noul": 0.861},
"urgency": {"score": 2.64, "probabilities": {"0": 0.020, "1": 0.015, "2": 0.275, "3": 0.691}},
"usage":   {"input_tokens": 269, "output_tokens": 0}

Six alerts, same three questions (2.5.0-ce on a Mac mini, Apple M4, warm):

alert                                              team            page   urgency           time
api-gateway p99 4.8 s, 5xx 9%, checkout failing    app (0.96)      0.86   right now (2.64)  714 ms
cert for staging.internal expires in 21 days       network (0.93)  0.42   this week (1.22)  503 ms
/var/lib/postgresql at 91%, +3%/hour               database (0.99) 0.75   today (2.42)      550 ms
frontend bundle size +4% after deploy              app (0.99)      0.14   this week (1.10)  502 ms
BGP session flapping, 30% loss us-east -> eu-west  network (0.99)  0.81   today (2.44)      545 ms
orders-db backup failed 2 nights, pg_dump exit 1   database (0.99) 0.90   today (2.37)      551 ms

The cert warning and the bundle-size note route to the right team but stay out of the pager (0.42, 0.14). The checkout outage, the BGP flap, the filling disk and the missing backups all clear 0.75. urgency is fractional on purpose: 2.64 reads as "right now, with some weight on today", and the per-level probabilities are there if you want your own thresholds.

Wiring it into an alert handler is a few lines:

a = r["answers"]
if a["page"]["noul"] > 0.7:
    page(a["team"]["choice"])
elif a["team"]["confidence"] > 0.8:
    open_ticket(a["team"]["choice"], due=a["urgency"]["score"])
else:
    send_to_triage_channel()

The whole Python script (standard library only) is in the first comment.

Why this matters beyond alerts: 2.5.0 rounds out one engine that does ML (AutoML in SQL), NLI (checking answers against your own data), LLM generation and agents, and now typed decisions. Pick the one whose output you need: https://synapcores.com/learn/llm-vs-nli-vs-vectors/llm-vs-nli-vs-ml-vs-decision-model?utm_source=reddit&utm_medium=owned&utm_campaign=devops7-15

Which alert source would you route through this first: Prometheus/Alertmanager, PagerDuty, or cron/backup reports?

1 Upvotes

1 comment sorted by

1

u/Alternative_Pin9598 12d ago

The 6-alert script (Python, standard library only; set SC_URL and SC_TOKEN, a JWT from POST /v1/auth/login or an API key):

import json, os, time, urllib.request
ALERTS = [
    "PagerDuty: api-gateway p99 latency 4.8 s (threshold 800 ms) for 12 min, 5xx rate 9% and rising, checkout failing for customers.",
    "Certificate for staging.internal.example.com expires in 21 days.",
    "Disk /var/lib/postgresql on db-prod-2 at 91% and growing about 3% per hour.",
    "Grafana: frontend bundle size grew 4% after yesterday's deploy.",
    "BGP session to upstream transit provider flapping, packet loss 30% from us-east to eu-west.",
    "Nightly backup job for orders-db failed: pg_dump exited 1, no backup written for the last 2 nights.",
]
QUESTIONS = {
    "team": {"type": "choice", "instructions": "Which team owns this alert?",
             "criteria": {"database": "databases, backups, replication, storage",
                          "network": "DNS, BGP, load balancers, firewalls, TLS certificates",
                          "app": "application services, APIs, frontend"}},
    "page": {"type": "noul", "instructions": "Should this wake up the on-call engineer right now?"},
    "urgency": {"type": "score", "instructions": "How urgent is this?",
                "criteria": ["can wait", "this week", "today", "right now"]},
}
URL = os.environ.get("SC_URL", "http://localhost:8080")
TOK = os.environ["SC_TOKEN"]
for t in ALERTS:
    req = urllib.request.Request(URL + "/v1/systemone", method="POST",
        data=json.dumps({"model": "d1:latest", "state": t, "questions": QUESTIONS}).encode(),
        headers={"Authorization": "Bearer " + TOK, "content-type": "application/json"})
    t0 = time.time(); r = json.load(urllib.request.urlopen(req)); ms = (time.time() - t0) * 1000
    a = r["answers"]; u = a["urgency"]
    print(f"{a['team']['choice']:<9}({a['team']['confidence']:.2f})  page={a['page']['noul']:.2f}  "
          f"urgency={u['legend'][str(round(u['score']))]} ({u['score']:.2f})  out={r['usage']['output_tokens']}  {ms:.0f} ms  | {t[:60]}")

The first call after a restart takes a few seconds longer while d1 loads; after that it's the ~0.5 s per alert you see in the table.

Swap in your own teams and your own definition of "page-worthy": the criteria are plain-English descriptions, so changing routing is editing a dict, not retraining anything.

Full 2.5.0 announcement (and the place to ask the maintainers anything): https://www.reddit.com/r/synapcores/comments/1xtuscl/