Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions docs/custom_fences.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import re
import uuid

import yaml # type: ignore

ROBUSTA_REGIONS = (("US", ""), ("EU", "eu"), ("AP", "ap"))
ROBUSTA_DOMAIN_RE = re.compile(r"\b(api|platform)\.robusta\.dev\b")
MARKDOWN_LINK_RE = re.compile(r"^\[([^\]]+)\]\(([^)\s]+)\)(\{[^}]*\})?$")
Expand Down Expand Up @@ -215,3 +217,87 @@ def robusta_region_fence_format(source, language, css_class, options, md, **kwar
f'<div class="tabbed-content">\n{blocks_html}</div>\n'
"</div>"
)


# Central page that documents how multi-instance toolsets work. Linked from every
# rendered ``multi-instance`` block so each toolset page doesn't repeat the prose.
MULTI_INSTANCE_DOC_URL = "/data-sources/multi-instance-toolsets/"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Make this link version-relative.

Hard-coding /data-sources/multi-instance-toolsets/ drops the current docs path prefix, so pages rendered under a versioned docs URL will jump to the site root/latest instead of staying on the same version.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/custom_fences.py` at line 224, The constant MULTI_INSTANCE_DOC_URL is an
absolute path ("/data-sources/multi-instance-toolsets/") which breaks versioned
docs; change it to a relative path by removing the leading slash (e.g.
"data-sources/multi-instance-toolsets/") so any doc path prefix/version is
preserved when this constant is used to build links; update any code that
consumes MULTI_INSTANCE_DOC_URL to join paths without forcing a root-leading
slash.



def _reindent(text: str, spaces: int) -> str:
"""Dedent ``text`` to its common leading whitespace, then indent every
non-empty line by ``spaces``. Used to nest a flat config example under
``instances:`` at the correct YAML depth."""
lines = text.strip("\n").split("\n")
nonempty = [ln for ln in lines if ln.strip()]
base = min((len(ln) - len(ln.lstrip()) for ln in nonempty), default=0)
pad = " " * spaces
return "\n".join(pad + ln[base:] if ln.strip() else "" for ln in lines)


def multi_instance_fence_format(source, language, css_class, options, md, **kwargs):
"""Render the standard "Multiple Instances" section for a toolset.

The fence body is YAML with three keys:

```multi-instance
toolset: grafana/dashboards # the toolset key used in config examples
name: Grafana # human-readable name (optional; derived from toolset)
config: | # a single-instance config example for this toolset
api_url: <your grafana url>
api_key: <your api key>
```

It emits a note admonition that:
- explains the toolset can connect to several instances via ``instances:``;
- shows the supplied config example nested under ``instances:`` (two entries);
- notes the auto-injected ``instance`` parameter and ``<toolset>_list_instances``
tool that appear when more than one instance is configured;
- links to the central Multiple Instances page for the full behaviour.

The same component renders identically for every toolset, so each page imports
it in one fenced block instead of repeating the prose.
"""
spec = yaml.safe_load(source) or {}
toolset = str(spec.get("toolset", "")).strip()
name = str(spec.get("name") or toolset or "this").strip()
config = str(spec.get("config", "")).strip()
if not toolset or not config:
Comment on lines +261 to +265

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
python - <<'PY'
import yaml

source = """
toolset: grafana/dashboards
config:
  api_url: https://prod-grafana.example.com
  api_key: token
"""

spec = yaml.safe_load(source)
print(type(spec).__name__)
print(type(spec["config"]).__name__)
print(str(spec["config"]))
PY

Repository: HolmesGPT/holmesgpt

Length of output: 141


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the relevant section around the reported line numbers
nl -ba docs/custom_fences.py | sed -n '230,310p'

# Find where _reindent is defined/used and whether config is inserted into a YAML snippet
rg -n "_reindent\(" -S docs/custom_fences.py || true
rg -n "config" docs/custom_fences.py | head -n 80

Repository: HolmesGPT/holmesgpt

Length of output: 106


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Display the referenced section with line numbers (using cat -n instead of nl)
cat -n docs/custom_fences.py | sed -n '230,310p'

# Trace how config is used/rendered
rg -n "config" docs/custom_fences.py | head -n 200

# Trace for reindent helper usage
rg -n "_reindent\(" docs/custom_fences.py || true
rg -n "def _reindent" -n docs/custom_fences.py || true

Repository: HolmesGPT/holmesgpt

Length of output: 6112


🏁 Script executed:

#!/bin/bash
set -euo pipefail
python - <<'PY'
import yaml

def _reindent(text: str, spaces: int) -> str:
    lines = text.strip("\n").split("\n")
    nonempty = [ln for ln in lines if ln.strip()]
    base = min((len(ln) - len(ln.lstrip()) for ln in nonempty), default=0)
    pad = " " * spaces
    return "\n".join(pad + ln[base:] if ln.strip() else "" for ln in lines)

def render(source: str):
    spec = yaml.safe_load(source) or {}
    toolset = str(spec.get("toolset", "")).strip()
    config = str(spec.get("config", "")).strip()
    fields = _reindent(config, 10)
    yaml_example = (
        "toolsets:\n"
        f"  {toolset}:\n"
        "    enabled: true\n"
        "    config:\n"
        "      instances:\n"
        f"        - name: prod\n{fields}\n"
        f"        - name: staging\n{fields}\n"
    )
    return yaml_example

# config provided as a YAML mapping (not a block scalar)
source = """
toolset: grafana/dashboards
config:
  api_url: https://prod-grafana.example.com
  api_key: token
"""
y = render(source)
print("=== rendered ===")
print(y)
print("=== safe_load result ===")
try:
    obj = yaml.safe_load(y)
    print("parsed:", type(obj).__name__)
except Exception as e:
    print("parse_error:", type(e).__name__, str(e)[:200])
PY

Repository: HolmesGPT/holmesgpt

Length of output: 613


🏁 Script executed:

#!/bin/bash
set -euo pipefail
python - <<'PY'
import yaml

def _reindent(text: str, spaces: int) -> str:
    lines = text.strip("\n").split("\n")
    nonempty = [ln for ln in lines if ln.strip()]
    base = min((len(ln) - len(ln.lstrip()) for ln in nonempty), default=0)
    pad = " " * spaces
    return "\n".join(pad + ln[base:] if ln.strip() else "" for ln in lines)

def render_with_fix(source: str):
    spec = yaml.safe_load(source) or {}
    if not isinstance(spec, dict):
        raise ValueError("multi-instance fence body must be a YAML mapping")

    toolset = str(spec.get("toolset", "")).strip()
    name = str(spec.get("name") or toolset or "this").strip()

    raw_config = spec.get("config", "")
    if isinstance(raw_config, str):
        config = raw_config.strip()
    elif raw_config:
        config = yaml.safe_dump(raw_config, sort_keys=False).rstrip()
    else:
        config = ""

    if not toolset or not config:
        raise ValueError("multi-instance fence requires 'toolset' and 'config' keys in its YAML body")

    fields = _reindent(config, 10)
    yaml_example = (
        "toolsets:\n"
        f"  {toolset}:\n"
        "    enabled: true\n"
        "    config:\n"
        "      instances:\n"
        f"        - name: prod\n{fields}\n"
        f"        - name: staging\n{fields}\n"
    )
    return yaml_example

source = """
toolset: grafana/dashboards
config:
  api_url: https://prod-grafana.example.com
  api_key: token
"""
rendered = render_with_fix(source)
print(rendered)
yaml.safe_load(rendered)
print("safe_load: OK")
PY

Repository: HolmesGPT/holmesgpt

Length of output: 356


Fix invalid YAML when config is a mapping in docs/custom_fences.py.

multi_instance_fence_format() parses the fence body with yaml.safe_load(), but then does config = str(spec.get("config", "")).strip(). When config is a YAML mapping, str(dict) renders Python dict syntax (e.g. {'api_url': ...}), producing invalid YAML in the generated snippet (lines 261-265).

Possible fix
-    spec = yaml.safe_load(source) or {}
-    toolset = str(spec.get("toolset", "")).strip()
-    name = str(spec.get("name") or toolset or "this").strip()
-    config = str(spec.get("config", "")).strip()
+    spec = yaml.safe_load(source) or {}
+    if not isinstance(spec, dict):
+        raise ValueError("multi-instance fence body must be a YAML mapping")
+
+    toolset = str(spec.get("toolset", "")).strip()
+    name = str(spec.get("name") or toolset or "this").strip()
+
+    raw_config = spec.get("config", "")
+    if isinstance(raw_config, str):
+        config = raw_config.strip()
+    elif raw_config:
+        config = yaml.safe_dump(raw_config, sort_keys=False).rstrip()
+    else:
+        config = ""
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/custom_fences.py` around lines 261 - 265, multi_instance_fence_format
currently converts spec.get("config") to a Python string which turns mappings
into invalid Python-dict syntax; instead detect if spec.get("config") is not
already a string and serialize it to valid YAML (e.g. with yaml.safe_dump)
before trimming—replace config = str(spec.get("config", "")).strip() with logic
that if isinstance(spec.get("config"), str) use it, else set config =
yaml.safe_dump(spec.get("config"), default_flow_style=False).strip() (falling
back to "" when None/empty) so the generated snippet contains valid YAML; update
usages of config in the function accordingly.

raise ValueError(
"multi-instance fence requires 'toolset' and 'config' keys in its YAML body"
)

# The wrapper names the discovery tool by replacing '/' with '_' in the toolset name.
list_tool = spec.get("list_tool") or (toolset.replace("/", "_") + "_list_instances")

fields = _reindent(config, 10)
yaml_example = (
"toolsets:\n"
f" {toolset}:\n"
" enabled: true\n"
" config:\n"
" instances:\n"
f" - name: prod\n{fields}\n"
f" - name: staging\n{fields}\n"
)

name_e = html.escape(name)
list_tool_e = html.escape(str(list_tool))
return (
'<div class="admonition note">\n'
'<p class="admonition-title">Multiple Instances</p>\n'
f"<p>The {name_e} toolset can connect to more than one {name_e} instance. "
"List each one under <code>instances:</code> with a unique <code>name</code>. "
"Any config field set outside <code>instances:</code> becomes a default that "
"every instance inherits, so shared settings only need to be written once.</p>\n"
f'<pre><code class="language-yaml">{html.escape(yaml_example)}</code></pre>\n'
"<p>When more than one instance is configured, HolmesGPT automatically adds an "
f"<code>instance</code> parameter to every {name_e} tool (so it can pick which "
f"instance to query) and a <code>{list_tool_e}</code> tool to list the configured "
"instances. With a single instance — including the flat config without "
"<code>instances:</code> — the tools are unchanged and fully backwards "
"compatible.</p>\n"
f'<p>See <a href="{MULTI_INSTANCE_DOC_URL}">Multiple Instances</a> for the full '
"behaviour, including global defaults and health reporting.</p>\n"
"</div>"
)
1 change: 1 addition & 0 deletions docs/data-sources/.nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ nav:
- index.md
- Recommended Setup: recommended-setup.md
- Built-in Toolsets: builtin-toolsets
- Multiple Instances: multi-instance-toolsets.md
- HTTP Connectors: api-toolsets.md
- Database Connectors: database-connectors.md
- Custom Toolsets: custom-toolsets.md
Expand Down
11 changes: 11 additions & 0 deletions docs/data-sources/builtin-toolsets/azure-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ By enabling this toolset, HolmesGPT can analyze Azure SQL Database performance,

--8<-- "snippets/helm_upgrade_command.md"

```multi-instance
toolset: azure/sql
name: Azure SQL
config: |
database:
subscription_id: "your-subscription-id"
resource_group: "your-resource-group"
server_name: "your-azure-sql-server-name"
database_name: "your-azure-sql-database-name"
```

## Roles / Access controls

The service principal requires these roles:
Expand Down
9 changes: 9 additions & 0 deletions docs/data-sources/builtin-toolsets/confluence.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ HolmesGPT authenticates to a self-hosted Confluence Data Center (or Server) inst

--8<-- "snippets/helm_upgrade_command.md"

```multi-instance
toolset: confluence
name: Confluence
config: |
api_url: "https://yourcompany.atlassian.net"
user: "your-email@example.com"
api_key: "your-api-token"
```

## Configuration Reference

`subtype` is set at the toolset level (sibling of `enabled:` and `config:`); the rest of the fields below go inside `config:`.
Expand Down
8 changes: 8 additions & 0 deletions docs/data-sources/builtin-toolsets/coralogix-logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ Configure both the Coralogix DataPrime toolset (for logs/traces) and the Prometh

**Note**: Both toolsets use the same API key. Helm-tab users only need to create one Kubernetes secret — the env var feeds both the `coralogix` toolset's `api_key` field and the Prometheus toolset's `Authorization` header.

```multi-instance
toolset: coralogix
name: Coralogix
config: |
api_key: "<your Coralogix API key>"
domain: "eu2.coralogix.com"
```

## Recommended: Customize Coralogix Instructions

By specifying details about your Coralogix metrics, logs, and traces, you can significantly speed up and improve investigations. This allows Holmes to work with your environment directly, rather than spending time discovering labels, mappings, and metric names on its own.
Expand Down
9 changes: 9 additions & 0 deletions docs/data-sources/builtin-toolsets/datadog.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ holmes ask "list Datadog monitors"

That's it! You're now connected to Datadog with all toolsets enabled.

```multi-instance
toolset: datadog/logs
name: Datadog
config: |
api_key: "{{ env.DATADOG_API_KEY }}"
app_key: "{{ env.DATADOG_APP_KEY }}"
api_url: https://api.datadoghq.com
```

## Available Toolsets

HolmesGPT provides four specialized Datadog toolsets:
Expand Down
120 changes: 7 additions & 113 deletions docs/data-sources/builtin-toolsets/elasticsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,117 +134,13 @@ Enable only the toolset(s) you need. Most users who just want to search logs onl
!!! tip "Enable only what you need"
You can enable just `elasticsearch/data` or `elasticsearch/cluster` depending on your needs. Most users who just want to search logs only need `elasticsearch/data`.

## Multiple Elasticsearch Instances

If you run a dedicated Elasticsearch cluster per Kubernetes cluster (or want a single HolmesGPT deployment to query several clusters), set `instances` instead of the single-cluster `api_url`/`api_key` fields. The LLM picks the right instance per tool call via the `elasticsearch_instance` parameter (call `elasticsearch_data_list_instances` or `elasticsearch_cluster_list_instances` to see configured names).

Top-level credentials act as **global defaults**. Per-instance settings override them. Use either `api_key` **or** `username` + `password` — they're mutually exclusive both at the top level and per instance. When overriding basic auth on an instance, set both `username` and `password` together.

=== "Holmes CLI"

```yaml
toolsets:
elasticsearch/cluster:
enabled: true
config:
# Global defaults — applied to every instance unless overridden
username: elastic
password: "{{ env.ES_GLOBAL_PASSWORD }}"
timeout_seconds: 15
verify_ssl: true

instances:
- name: prod-eu
api_url: https://prod-eu.es.internal:9200
# Inherits global username + password
- name: prod-us
api_url: https://prod-us.es.internal:9200
# Per-instance override (uses a different basic auth password)
username: elastic
password: "{{ env.ES_US_PASSWORD }}"
- name: staging
api_url: https://staging.es.internal:9200
# Per-instance override (uses an API key instead of basic auth)
api_key: "{{ env.STAGING_ES_API_KEY }}"
elasticsearch/data:
enabled: true
config:
username: elastic
password: "{{ env.ES_GLOBAL_PASSWORD }}"
instances:
- name: prod-eu
api_url: https://prod-eu.es.internal:9200
- name: prod-us
api_url: https://prod-us.es.internal:9200
username: elastic
password: "{{ env.ES_US_PASSWORD }}"
```

=== "Holmes Helm Chart"

```yaml
additionalEnvVars:
- name: ES_GLOBAL_PASSWORD
valueFrom:
secretKeyRef:
name: elasticsearch-credentials
key: global-password
- name: ES_US_PASSWORD
valueFrom:
secretKeyRef:
name: elasticsearch-credentials
key: us-password
- name: STAGING_ES_API_KEY
valueFrom:
secretKeyRef:
name: elasticsearch-credentials
key: staging-api-key

toolsets:
elasticsearch/cluster:
enabled: true
config:
username: elastic
password: "{{ env.ES_GLOBAL_PASSWORD }}"
instances:
- name: prod-eu
api_url: https://prod-eu.es.internal:9200
- name: prod-us
api_url: https://prod-us.es.internal:9200
username: elastic
password: "{{ env.ES_US_PASSWORD }}"
- name: staging
api_url: https://staging.es.internal:9200
api_key: "{{ env.STAGING_ES_API_KEY }}"
```

=== "Robusta Helm Chart"

```yaml
holmes:
additionalEnvVars:
- name: ES_GLOBAL_PASSWORD
valueFrom:
secretKeyRef:
name: elasticsearch-credentials
key: global-password
toolsets:
elasticsearch/cluster:
enabled: true
config:
username: elastic
password: "{{ env.ES_GLOBAL_PASSWORD }}"
instances:
- name: prod-eu
api_url: https://prod-eu.es.internal:9200
- name: prod-us
api_url: https://prod-us.es.internal:9200
```

**Health check is tolerant**: if some instances are unreachable at startup, the toolset still loads with the healthy ones. The unreachable instances are listed in the toolset status string and discoverable via `elasticsearch_data_list_instances` / `elasticsearch_cluster_list_instances`.

!!! note "Backwards compatibility"
Existing single-cluster configs (with a top-level `api_url`) continue to work unchanged — they're treated as a single instance named `default`, and the `elasticsearch_instance` parameter is auto-selected.
```multi-instance
toolset: elasticsearch/data
name: Elasticsearch
config: |
api_url: "https://your-cluster.es.cloud.io:443"
api_key: "your-api-key"
```

## Authentication

Expand Down Expand Up @@ -367,11 +263,9 @@ If Elasticsearch uses a private CA, use the global [`certificate`](../../referen

| Toolset | Tool Name | Description |
|---------|-----------|-------------|
| `elasticsearch/data` | elasticsearch_data_list_instances | List configured Elasticsearch instances on the data toolset (multi-instance discovery) |
| `elasticsearch/data` | elasticsearch_search | Search documents using Elasticsearch Query DSL |
| `elasticsearch/data` | elasticsearch_mappings | Get field mappings for an index |
| `elasticsearch/data` | elasticsearch_list_indices | List indices matching a pattern |
| `elasticsearch/cluster` | elasticsearch_cluster_list_instances | List configured Elasticsearch instances on the cluster toolset (multi-instance discovery) |
| `elasticsearch/cluster` | elasticsearch_cat | Query _cat APIs (indices, shards, nodes, etc.) |
| `elasticsearch/cluster` | elasticsearch_cluster_health | Get cluster health status |
| `elasticsearch/cluster` | elasticsearch_allocation_explain | Explain shard allocation decisions |
Expand Down
Loading
Loading