> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chronosphere.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Add templated links to monitors

Use templated links on [monitors](/investigate/alerts/monitors) to send responders
from an [alert](/investigate/alerts/alert-details) to the right dashboard view, log
query, or external runbook. Each link interpolates template variables from the
alerting signal's labels when the alert triggers, so every alert opens a destination
scoped to its own cluster, namespace, pod, or other dimensions. Responders open
expanded links from **Additional information** on the
[alert details](/investigate/alerts/alert-details#view-an-alerts-related-information)
page.

## Links and annotations

In the monitor editor, **Annotations** hold text notes such as runbook summaries.
**Links** hold URL-valued annotations that Observability Platform renders as
clickable links on monitor and alert detail pages.

Link names become annotation keys. They must use only letters, numbers, and
underscores, and can't start with a number.

When the **Links** section is enabled in the monitor editor, Observability Platform
displays URL-valued annotations from existing monitors in **Links** rather than in
**Annotations**. Saving the monitor preserves those entries in `annotations`.

SLOs also support the **Links** section in the **SLO Definition** drawer when
this feature is enabled. SLO links use the same link types but don't interpolate
template variables during editing because SLOs have no live preview signal. See
[Labels and annotations](/investigate/alerts/manage-slos#labels-and-annotations) for the
separate SLO annotations workflow.

## Add links to a monitor

Add dashboard, log, or external links in the monitor editor **Links** section, or
set URL-valued entries on the monitor's `annotations` map when you define the
monitor in code. Select the tab for your workflow.

In the Chronoctl, Terraform, and API tabs, a `Pod restarts` monitor includes two
templated links in `annotations`: `dashboard` and `error_logs`. The sample values
in this section match those code examples. Replace *`TENANT`* with your tenant
subdomain. For *`DASHBOARD_SLUG`*, [open the dashboard](/observe/dashboards#view-dashboards),
click [**Copy URL**](/navigate#shareable-links) in the page header, and use the path
segment after `/dashboards/`. For template syntax and URL patterns, see
[Construct link URLs](#construct-link-urls).

Value for the `dashboard` annotation:

```text wrap /var-cluster/ /var-namespace/ theme={null}
https://TENANT.chronosphere.io/dashboards/DASHBOARD_SLUG?var-cluster={{ $labels.chronosphere_k8s_cluster }}&var-namespace={{ $labels.namespace }}
```

Logs query that the code examples encode into the `error_logs` annotation URL:

```text wrap /severity/ /kubernetes.namespace/ theme={null}
severity="ERROR" AND service="{{ $labels.service }}" AND kubernetes.namespace="{{ $labels.namespace }}"
```

<Tabs>
  <Tab title="Web" id="add-annotation-links-web">
    1. [Create or edit a monitor](/investigate/alerts/monitors#create-a-monitor).
    2. In the **Links** section, click **Add link**.
    3. Enter a **Link name**.
    4. Select a link type:
       * **URL**: Enter a full URL or a relative path to a page in Observability Platform.
         Use this type for external runbooks, status pages, and other links.
         See [Construct link URLs](#construct-link-urls) for URL patterns.
       * **Dashboard**: Select a dashboard from the autocomplete. Observability Platform
         maps dashboard variables to alert signal labels so the link opens a view scoped
         to the alerting dimensions. Add or remove variable mappings as needed.
       * **Logs**: Enter a [logging query](/investigate/querying/query-logs/query-syntax).
         Observability Platform builds a Logs Explorer URL from the query. Use template
         variables in the query to scope results to each alerting signal. See
         [Construct link URLs](#construct-link-urls) for query patterns.

         The **Logs** type is available only when your tenant has a logging data source.
         If logging isn't enabled, the drawer accepts **URL** and **Dashboard** links only.
    5. Review the **Link preview** as you type. The preview updates to show the link
       Observability Platform stores on the monitor.
    6. Click **Create** to add the link to the table, then click **Save** on the monitor
       form to persist your changes.
    7. To edit a link, click the **<Icon icon="pencil" />** edit icon. In the
       **Edit link** page, make any necessary changes and then click **Save**.

    To remove a link, click the **<Icon icon="trash" />** delete icon on the link's row
    in the **Links** table.
  </Tab>

  <Tab title="Chronoctl" id="add-annotation-links-chronoctl">
    Add URL-valued keys to the `annotations` section in your monitor YAML when you
    [create](/investigate/alerts/monitors#create-a-monitor) or
    [edit](/investigate/alerts/monitors#edit-a-monitor) a monitor. For more
    information, see [Chronoctl](/tooling/chronoctl).

    ```yaml wrap /var-cluster/ /var-namespace/ theme={null}
    annotations:
      dashboard: >-
        https://TENANT.chronosphere.io/dashboards/DASHBOARD_SLUG?var-cluster={{ $labels.chronosphere_k8s_cluster }}&var-namespace={{ $labels.namespace }}
      error_logs: >-
        https://TENANT.chronosphere.io/logs/explorer?query=severity%3D%22ERROR%22%0AAND%20kubernetes.namespace%3D%22{{ $labels.namespace }}%22
    ```
  </Tab>

  <Tab title="Terraform" id="add-annotation-links-terraform">
    In a `chronosphere_monitor` resource, set the `annotations` argument to a map of
    link names and URL values. For more information, see the
    [Terraform provider](/tooling/infrastructure/terraform) documentation.

    ```terraform wrap /var-cluster/ /var-namespace/ theme={null}
    resource "chronosphere_monitor" "pod_restarts" {
      name = "Pod restarts"

      collection_id = chronosphere_collection.infra.id

      annotations = {
        dashboard = "https://TENANT.chronosphere.io/dashboards/DASHBOARD_SLUG?var-cluster={{ $labels.chronosphere_k8s_cluster }}&var-namespace={{ $labels.namespace }}"
        error_logs  = "https://TENANT.chronosphere.io/logs/explorer?query=severity%3D%22ERROR%22%0AAND%20kubernetes.namespace%3D%22{{ $labels.namespace }}%22"
      }

      query {
        prometheus_expr = "increase(kube_pod_container_status_restarts_total[5m]) > 0"
      }
    }
    ```

    Run `terraform apply` to create or update the monitor resource.
  </Tab>

  <Tab title="API" id="add-annotation-links-api">
    Set the `annotations` field on the monitor body when calling
    [`CreateMonitor`](/tooling/api-info/definition/operations/CreateMonitor) or
    [`UpdateMonitor`](/tooling/api-info/definition/operations/UpdateMonitor). Replace
    *`COLLECTION_SLUG`* with the slug of the collection that owns the monitor.

    ```json wrap /var-cluster/ /var-namespace/ theme={null}
    {
      "monitor": {
        "name": "Pod restarts",
        "collection_slug": "COLLECTION_SLUG",
        "annotations": {
          "dashboard": "https://TENANT.chronosphere.io/dashboards/DASHBOARD_SLUG?var-cluster={{ $labels.chronosphere_k8s_cluster }}&var-namespace={{ $labels.namespace }}",
          "error_logs": "https://TENANT.chronosphere.io/logs/explorer?query=severity%3D%22ERROR%22%0AAND%20kubernetes.namespace%3D%22{{ $labels.namespace }}%22"
        },
        "query": {
          "prometheus_expr": "increase(kube_pod_container_status_restarts_total[5m]) > 0"
        }
      }
    }
    ```
  </Tab>
</Tabs>

## Construct link URLs

Reference labels from the alerting time series with Prometheus Alertmanager template
syntax. Observability Platform expands variables when an alert triggers and when
responders view links on alert detail pages.

Use either of these forms to read a label from the alerting series:

* `{{ $labels.LABEL }}`
* `{{ .Labels.LABEL }}`

Replace *`LABEL`* with the label name, such as `namespace` or
`chronosphere_k8s_cluster`.

Labels referenced in a template must be present on the alerting time series. Missing
labels display as the template string, such as `{{ $labels.missing_label }}`.

the variable renders as empty in the expanded link.

For a full list of alerting variables and templating functions, see the
[Alertmanager documentation](https://prometheus.io/docs/alerting/latest/notifications/).

### Dashboard links

Select **Dashboard** as the link type to scope a dashboard to the alerting signal.
Choose a dashboard from the **Dashboard name** dropdown. For native dashboards,
Observability Platform populates **Dashboard variables** with the dashboard's
configured variables and maps each to a signal label using `${LABEL}` tokens. For
classic (Grafana) dashboards, an info banner indicates that variables aren't
available from the dashboard configuration.

Click **+ Add variable** to add custom variable mappings. Click a variable's
**Values** field to select from available signal labels, or type a literal value.
Edit or delete existing variable mappings as needed. The **Link preview** updates as
you configure variables, showing the constructed URL with interpolated template
variables where signal labels are available.

Omit `start`, `end`, `from`, and `to` from dashboard and Logs Explorer URLs when
you want the alert page's time range to apply when a responder clicks the link.
If the URL already includes any of those parameters, Observability Platform leaves
them unchanged.

### Logs links

When you use the **Logs** link type in the monitor editor, enter the query in plain
logging query syntax and embed template variables where you want per-signal values.
The sample logs query in [Add links to a monitor](#add-links-to-a-monitor) is what
the `error_logs` annotation encodes in Chronoctl, Terraform, and API definitions.
Observability Platform encodes the query into a Logs Explorer URL and preserves
`{{ ... }}` expressions for expansion at alert time.

To construct a logs URL manually instead, see
[Create links to log data](/investigate/querying/create-links#create-links-to-log-data).
