Alertmanager
Fetches alerts from the Prometheus Alertmanager /api/v2/alerts endpoint and stores the alerts in results.alerts.
The following example transforms results.alerts so that each alert becomes a single check result. To fail when Alertmanager returns alerts, add a test expression in an imported fixture, such as results.alerts.size() == 0.
alert-manager-check.yamlapiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: alertmanager
spec:
schedule: "@every 5m"
alertmanager:
- url: http://kube-prometheus-stack-alertmanager.monitoring:9093
name: alertmanager-check
alerts:
- .*
ignore:
- KubeScheduler.*
exclude_filters:
namespace: elastic-system
transform:
expr: |
results.alerts.map(r, {
'name': r.name + r.fingerprint,
'namespace': 'namespace' in r.labels ? r.labels.namespace : '',
'labels': r.labels,
'icon': 'alert',
'message': r.message,
'description': r.message,
}).toJSON()
relationships:
components:
- name:
label: pod
namespace:
label: namespace
type:
value: KubernetesPod
configs:
- name:
label: pod
namespace:
label: namespace
type:
value: Kubernetes::Pod
| Field | Description | Scheme |
|---|---|---|
name* | Name of the check, must be unique within the canary |
|
alerts | Alert name regular expressions to include |
|
connection | Connection reference or URL to use. Inline username and password can supply credentials when the check supports them | |
exclude_filters | Label values to exclude |
|
filters | Label regular expressions to include |
|
ignore | Alert name regular expressions to exclude |
|
password | ||
url | Prometheus Alertmanager URL. Required unless connection supplies the URL |
|
username | ||
dependsOn | Checks that must complete before this check runs |
|
description | Description for the check |
|
display | Expression to change the formatting of the display | |
icon | Icon for overwriting default icon on the dashboard | |
labels | Labels for check |
|
markFailOnEmpty | If a transformation or datasource returns empty results, the check should fail |
|
metrics | Metrics to export from | |
namespace | Namespace to insert the check result into when it differs from the canary namespace |
|
relationships | Relationships that link check results to components or configs | Relationship |
test | Evaluate whether a check is healthy | |
transform | Transform data from a check into multiple individual checks | |
transformDeleteStrategy | Status to apply to transformed checks when the source check no longer returns them |
|
Relationships
| Field | Description | Scheme |
|---|---|---|
components | Select components to link to this check | |
configs | Select configs to link to this check |
Lookup
| Field | Description | Scheme |
|---|---|---|
name | Name selector for the related resource | |
namespace | Namespace selector for the related resource | |
type | Type selector for the related resource |
Lookup selector
Lookup specifies the type of lookup to perform.
| Field | Description | Scheme |
|---|---|---|
expr | Expr is a cel-expression |
|
label | Label specifies the key to lookup on the label |
|
value | Value is the static value to use |
|
Inserting checks into different namespaces
You can specify different namespaces for checks using the namespace field. This is helpful when checks are dynamically generated via transformation
and need to be assigned their respective namespace.
alert-manager-check.yamlapiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: alertmanager
spec:
schedule: "@every 5m"
alertmanager:
- url: http://kube-prometheus-stack-alertmanager.monitoring:9093
name: alertmanager-check
alerts:
- .*
ignore:
- KubeScheduler.*
exclude_filters:
namespace: elastic-system
transform:
expr: |
results.alerts.map(r, {
'name': r.name + r.fingerprint,
'namespace': 'namespace' in r.labels ? r.labels.namespace : '',
'labels': r.labels,
'icon': 'alert',
'message': r.message,
'description': r.message,
}).toJSON()
relationships:
components:
- name:
label: pod
namespace:
label: namespace
type:
value: KubernetesPod
configs:
- name:
label: pod
namespace:
label: namespace
type:
value: Kubernetes::Pod
The Alertmanager canary can reside in any namespace. The transformed checks use the namespace derived from the alerts.