/obstudio:splunk-detector-publishfrom Splunk Observability Studio
Compares local Splunk detector specs from .observe/terraform/detectors.tf against live Splunk Observability Cloud detectors, classifying each as covered or a gap, then creates only confirmed gaps idempotently via the Splunk REST API. Useful after running $splunk-configure to push missing monitors without duplicating existing ones.
Ships in Splunk Observability Studio. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Compare locally-generated signalfx_detector specs (from $splunk-configure)
against live Splunk Observability Cloud detectors for the same service.
Create only the genuine gaps; skip anything already covered. Write a persistent
ledger so re-runs are idempotent and auditable.
$splunk-configure has already produced .observe/terraform/detectors.tfWhen NOT to use: If no local spec exists yet, instruct the user to run
$splunk-configure first.
Shared reference:
../references/splunk-api.mdis the single source of truth for auth, the skip-on-500 paginated fetch loop, and HTTP-status handling used by all Splunk sync skills. The detector-specific concrete steps below restate the parts this skill depends on.
All Splunk O11y data calls use the Splunk REST API directly. Read the token from the environment:
| Variable | Purpose |
|---|---|
SPLUNK_ACCESS_TOKEN | Org access token; sent as X-SF-Token header |
SPLUNK_REALM | Optional fallback realm (e.g. lab0, us0, us1) |
Resolve the realm using ../references/splunk-api.md: keep
SPLUNK_ACCESS_TOKEN paired with a non-empty SPLUNK_REALM when it is set;
otherwise call observer_splunk_connection_realm and use the connected Splunk
Observability Studio destination's non-empty realm. The read-only tool returns
only the non-secret region.
If SPLUNK_ACCESS_TOKEN is missing, or neither realm source is available, stop
and tell the user. Before creating detectors, include the resolved realm and its
source in the confirmation.
Base URL: https://api.${realm}.signalfx.com
Important: The /v2/detector list endpoint has a known server-side bug where
certain offset values return HTTP 500. Always skip-on-500 when paginating — do
not treat it as an auth or hard failure. See Step 3 for the pagination pattern.
Look for .observe/terraform/detectors.tf in the repository root.
No local detector spec found at
.observe/terraform/detectors.tf. Please run$splunk-configurefirst to generate the detector Terraform.
Also read .observe/detectors.md if it exists — it provides the human summary
and classification rationale that helps resolve ambiguous UNCERTAIN cases.
Parse every signalfx_detector resource block in detectors.tf. For each one
extract:
latency_http_server_request_duration)name field (may reference ${var.service_name})program_text fieldrule block: severity, detect_label, notificationsdata('metric.name', ...) argument in program_textfilter('service.name', '...') value in program_text;
resolve ${var.service_name} by reading terraform.tfvars (if present) or
terraform.tfvars.example and prompting the user if still unresolvableHCL field name is program_text; live API field is programText — normalize
when comparing.
Fail fast if the file is not parseable (malformed HCL) and tell the user.
program_text to valid SignalFlow (required before create)Shared reference:
../references/terraform-normalization.mddocuments this normalization (heredoc dedent + resolve every${var.*}) once for all sync skills. The detector-specific restatement below is what this skill applies.
The raw program_text value extracted from HCL is not valid SignalFlow and
must be normalized before it is sent in any POST /v2/detector body. The
Splunk API runs the string through the SignalFlow parser as-is and rejects it
with HTTP 400 if either of the following is left unhandled. Do this once,
during parsing, and carry the normalized string forward:
Strip indented-heredoc whitespace (<<-EOF). Terraform's <<-EOF
"indented heredoc" deletes the leading whitespace of the least-indented
line at apply time, but the raw bytes between the <<-EOF and EOF markers
still carry the editor indentation. SignalFlow treats a leading-whitespace
line as a syntax error, so reproduce Terraform's behavior: find the smallest
leading-whitespace run across all non-blank lines and strip exactly that many
leading characters from every line (i.e. textwrap.dedent after trimming the
trailing marker line). Plain <<EOF (no dash) is already flush-left — leave
it unchanged. Always .strip() the final result so a leading/trailing blank
line never reaches the parser.
Resolve every ${var.*} reference, not just service.name. Detector
program text routinely interpolates thresholds, stddev counts, and windows —
threshold(${var.saturation_queue_depth_threshold}),
fire_num_stddev=${var...._stddev}, etc. A literal ${var...} token is
invalid SignalFlow. Resolve all of them, in this precedence order, before
create:
terraform.tfvars (then *.auto.tfvars, then
terraform.tfvars.example), elsedefault value of the matching variable "<name>" { ... } block in
variables.tf, elseSubstitute the resolved literal for the whole ${var.<name>} span. Numbers
are emitted bare (50.0), strings keep their SignalFlow quoting as written
in the surrounding program text.
import re, textwrap
def dedent_heredoc(raw: str) -> str:
# Mirrors Terraform <<-EOF: strip common leading whitespace, trim blank edges.
return textwrap.dedent(raw).strip()
def resolve_vars(program_text: str, tf_vars: dict, var_defaults: dict) -> str:
# tf_vars: name->value from terraform.tfvars / *.auto.tfvars / .example
# var_defaults: name->default from variables.tf `variable` blocks
unresolved = []
def repl(m):
name = m.group(1)
if name in tf_vars:
return str(tf_vars[name])
if name in var_defaults:
return str(var_defaults[name])
unresolved.append(name)
return m.group(0)
out = re.sub(r"\$\{var\.([A-Za-z0-9_]+)\}", repl, program_text)
if unresolved:
raise ValueError(
"Unresolved Terraform variables in program_text "
f"(no tfvars assignment and no default): {sorted(set(unresolved))}. "
"Prompt the user for these before POSTing the detector."
)
return out
# Per spec, during parsing:
program_text = resolve_vars(dedent_heredoc(raw_program_text), tf_vars, var_defaults)
Both transforms are pure-string and deterministic; the result is the exact
SignalFlow Splunk would have received had the Terraform been terraform apply-d.
Use this normalized program_text everywhere downstream — both for COVERED/GAP
comparison and for the create body in Step 6.
Retrieve all live detectors in the org using the Splunk O11y REST API:
import urllib.request, json, sys
from collections import defaultdict
token = "<SPLUNK_ACCESS_TOKEN>"
realm = "<resolved realm>"
base = f"https://api.{realm}.signalfx.com/v2/detector"
limit = 50 # keep small; large limits hit the 500 bug more often
offset = 0
all_detectors = []
seen_ids = set()
consecutive_empty = 0 # counts genuinely empty pages (real end-of-list signal)
consecutive_500 = 0 # counts 500 pages separately — does NOT advance empty counter
while consecutive_empty < 5 and consecutive_500 < 10:
url = f"{base}?limit={limit}&offset={offset}"
req = urllib.request.Request(url, headers={"X-SF-Token": token})
try:
with urllib.request.urlopen(req, timeout=15) as resp:
data = json.load(resp)
except urllib.error.HTTPError as e:
if e.code == 500:
# Skip-on-500: the API has a known bug at certain offsets.
# Do NOT increment consecutive_empty here — a 500 is not an empty
# page; incrementing it would stop the loop after just 5 bad offsets
# and hide detectors on later pages.
offset += limit
consecutive_500 += 1
continue
raise RuntimeError(f"Splunk API error {e.code} fetching detectors: {e}") from e
except (urllib.error.URLError, json.JSONDecodeError, OSError) as e:
raise RuntimeError(f"Failed to fetch detectors: {e}") from e
consecutive_500 = 0 # a successful response resets the 500 streak
batch = data.get("results", [])
if not batch:
consecutive_empty += 1
offset += limit
continue
consecutive_empty = 0
for d in batch:
if d["id"] not in seen_ids:
seen_ids.add(d["id"])
all_detectors.append(d)
offset += limit
Each detector object from the list endpoint includes id, name,
programText, detectorOrigin, and rules. That is sufficient for
classification — no second per-detector GET is required unless programText
is absent or truncated (in that case fetch GET /v2/detector/{id}).
If the org has zero detectors, all local specs are GAPs — proceed to Step 4 with an empty live list.
Apply the coverage model from references/coverage-model.md (which builds on the
shared ../references/coverage-decision-tree.md verdict vocabulary) to assign
each local spec one of four statuses:
COVERED
A live Standard (detectorOrigin != "AutoDetect") detector's programText
references the same OTel metric name AND filters the same service.name or
sf_service value. Both conditions must hold simultaneously.
GAP No live Standard detector matches on both the metric name AND the service filter. This spec must be created.
UNCERTAIN The metric name appears in a live detector's programText but the service filter is absent, uses a different dimension key, or the filter value is ambiguous (e.g. a wildcard). Show to the user; do not auto-create and do not auto-cover.
Offline / fetch-unavailable fallback Always attempt the live detector fetch (Step 3) before declaring any verdict. Do NOT skip the fetch and jump straight to any classification — the fetch is the authoritative signal. When the fetch genuinely fails (network error, auth failure, API unreachable, or a non-500 HTTP error), mark every local spec UNCERTAIN (not GAP). A failed fetch proves neither absence nor presence of a live detector: classifying as GAP when the fetch fails would cause duplicate creates once connectivity returns. Show the UNCERTAIN specs in the confirmation diff, stop at the confirmation gate, explicitly state that the live inventory could not be fetched, and require the user to re-run once the API is reachable before any POST is attempted. Do not create detectors from an incomplete inventory.
AutoDetect advisory (informational only)
For latency or error specs: note any live detector with
detectorOrigin == "AutoDetect" that references service.request metrics as a
possible overlap advisory line. AutoDetect detectors are org-wide and never
filter by service.name, so they cannot count as COVERED for a specific service.
They are advisory only and do NOT change the spec's classification.
Always include the ### AutoDetect Advisory section in the confirmation diff,
even when offline or when no AutoDetect detectors were fetched. In offline
context, write: "Live inventory not fetched — AutoDetect detectors (if any)
are org-wide and advisory only; they would not count as COVERED for
service-specific specs." This section is required in every diff output.
See references/coverage-model.md for worked examples and edge cases.
Print a structured diff table before any writes. Do not proceed until the user explicitly confirms.
## Detector Publish Diff — <service-name>
### COVERED (N) — no action needed
| Local Spec | Metric | Matched Live Detector |
|------------|--------|----------------------|
| latency_<id> | <metric> | <live detector name (id)> |
### GAP (N) — will be created
| Local Spec | Metric | Severity | Why no match |
|------------|--------|----------|--------------|
| error_<id> | <metric> | Critical | no live detector with this metric + service filter |
### UNCERTAIN (N) — review manually
| Local Spec | Metric | Live Detector | Issue |
|------------|--------|---------------|-------|
| saturation_<id> | <metric> | <name> | service filter absent in live programText |
### AutoDetect Advisory (N) — informational
| Local Spec | Metric | AutoDetect Detector | Note |
|------------|--------|---------------------|------|
| latency_<id> | <metric> | <org-wide detector name> | org-wide AutoDetect, not service-scoped; does not substitute for a custom detector |
---
N GAPs will be created. N UNCERTAIN specs need manual review.
Confirm? (yes/no)
If there are zero GAPs and zero UNCERTAINs, respond:
All N local detector specs are already COVERED by live Splunk detectors. Nothing to create. Ledger written to
.observe/detector-sync.md.
Then skip to Step 7 (write the ledger).
After the user confirms, for each GAP spec:
https://api.${realm}.signalfx.com/v2/detector using the resolved realm:
body = {
"name": resolved_name, # ${var.service_name} substituted
"programText": program_text, # NORMALIZED per Step 2a: heredoc dedented
# AND all ${var.*} resolved — never the raw
# HCL value, or Splunk returns HTTP 400
"rules": [
{
"severity": rule["severity"],
"detectLabel": rule["detect_label"],
"notifications": rule.get("notifications", []),
"disabled": False,
}
for rule in rules
],
"description": f"Created by splunk-detector-publish from {hcl_label}",
"tags": ["obstudio"],
}
data = json.dumps(body).encode("utf-8")
req = urllib.request.Request(
f"https://api.{realm}.signalfx.com/v2/detector",
data=data,
method="POST",
headers={"X-SF-Token": token, "Content-Type": "application/json"},
)
try:
with urllib.request.urlopen(req, timeout=30) as resp:
status = resp.status
created = json.load(resp)
except urllib.error.HTTPError as e:
status = e.code # branch on status below; do not raise blindly
created = None
Note: HCL uses detect_label; the REST API uses detectLabel — normalize.
urllib raises HTTPError for any non-2xx response, so branch on status:created["id"] and created["name"] plus
https://app.${realm}.signalfx.com/#/detector/{id} for the ledger.Create GAPs sequentially, not in parallel, to make progress visible and errors attributable.
Shared reference:
../references/ledger-template.mddefines the resumable ledger shape (summary counts + per-item status table with a required non-empty Reason column) used by all sync skills. The detector ledger below follows it.
Write or overwrite .observe/detector-sync.md after every run (success, partial
failure, or zero-gap no-op):
# Detector Publish Ledger: <service-name>
**Date:** <YYYY-MM-DD>
**Local spec:** `.observe/terraform/detectors.tf`
**Service filter resolved to:** `<service_name_value>`
## Summary
| Status | Count |
|--------|-------|
| COVERED | N |
| GAP → Created | N |
| GAP → Failed | N |
| UNCERTAIN | N |
| AutoDetect Advisory | N |
## Detector Status
| Local Spec | Metric | Status | Detector ID | Link | Notes |
|------------|--------|--------|-------------|------|-------|
| latency_<id> | <metric> | COVERED | <id> | | matched live detector "<name>" |
| error_<id> | <metric> | CREATED | <id> | <link> | |
| saturation_<id> | <metric> | UNCERTAIN | | | service filter absent in live programText |
| latency_<id2> | <metric> | AutoDetect Advisory | | | org-wide AutoDetect detector noted |
---
*Generated by splunk-detector-publish on <YYYY-MM-DD>*
A re-run on a fully-synced service will re-read the live state and produce an all-COVERED ledger — it will not re-create anything because the GAP check is re-evaluated fresh.
After the ledger is written, present a concise summary:
## Detector Publish Complete — <service-name>
| Status | Count |
|--------|-------|
| Already covered | N |
| Created | N |
| Uncertain (manual review) | N |
| AutoDetect advisory | N |
Ledger: `.observe/detector-sync.md`
If any GAPs failed to create, list them explicitly with the error message.
If UNCERTAIN specs remain, recommend running $splunk-detector-publish again after
reviewing and resolving the ambiguous live detectors manually.
.observe/terraform/detectors.tf missing — run $splunk-configure firstSPLUNK_ACCESS_TOKEN not set — stop and tell the userSPLUNK_REALM or the connected Splunk Observability Studio — stop and tell the userservice_name not resolvable from terraform.tfvars or .example — prompt
the user before fetching live detectorsprogramText missing or empty — treat as not-a-match
(cannot verify service filter); classify as UNCERTAIN, not COVEREDprogramText vs program_text and detectLabel vs detect_labelprogram_text was sent un-normalized. Re-check Step 2a: the
<<-EOF heredoc must be dedented and every ${var.*} (thresholds, stddev,
windows — not just service.name) must be resolved before the POST. A literal
${var...} token or a leading-whitespace program line both parse-fail as 400.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (signalfx/obstudio) — no native marketplace selected
npx claudepluginhub p/signalfx-obstudio-plugins-obstudio13 skills in this plugin
/connect-splunk-observability-cloudOpen the already-running local Splunk Observability Studio Cloud tab so a user can connect an existing or newly ready Splunk Observability Cloud organization by entering its URL and access token outside agent context. Use when a user asks to connect, configure, or provide credentials for Splunk Observability Cloud, Splunk O11y, or SignalFx outside the Splunk Observability Studio IDE extension. Do not use this skill to create a Free Edition account./create-splunk-free-accountSubmit a consent-gated Splunk Observability Cloud Free Edition signup intake in a detected or user-selected supported signup region through Splunk Observability Studio's browserless MCP backend. Use when a user asks to create, provision, register, start, or sign up for a free Splunk Observability Cloud, Splunk O11y, or SignalFx account or organization, or explicitly asks to submit another intake with the same details or email, including requests to avoid the Splunk web form./observer-openOpen the local Splunk Observability Studio at http://127.0.0.1:17900/ using a host-provided browser when available, with a safe clickable-URL fallback./observer-restartExplain how to refresh or restart the local Splunk Observability Studio when the UI is stale, the MCP endpoint is unavailable, or the bootstrap state needs to be refreshed./observer-statusReport whether the local Splunk Observability Studio is installed, bootstrapped, and reachable, including the MCP endpoint and browser URL./observer-stopExplain how to stop or disconnect from a local Splunk Observability Studio when the user intentionally wants to shut down the managed runtime or leave a shared Splunk Observability Studio alone.Other plugins' skills for the same job