Send test alerts to Alertmanager in OpenShift 4
Environment
- Red Hat OpenShift Container Platform 4
Issue
- A receiver has to be tested, for instance, with a
criticalalert. A real critical alert cannot be forced in production. - Verify that your receiver is configured correctly by creating a test alert.
Resolution
- Get a list of the configured routes:
$ oc exec alertmanager-main-0 -n openshift-monitoring -- amtool config routes show --alertmanager.url http://localhost:9093
Example output
Routing tree: . └── default-route receiver: default ├── {alertname="Watchdog"} receiver: Watchdog └── {service="example-app"} receiver: default └── {severity="critical"} receiver: team-frontend-page
- Print the route to your chosen receiver. The following example shows the receiver used for alerts with
service=example-appandseverity=criticalmatchers.
$ oc exec alertmanager-main-0 -n openshift-monitoring -- amtool config routes test service=example-app severity=critical --alertmanager.url http://localhost:9093
Example output
team-frontend-page
- Create a test alert and add it to the Alertmanager. The following example creates an alert with
service=example-appandseverity=criticalto test theteam-frontend-pagereceiver:
$ oc exec alertmanager-main-0 -n openshift-monitoring -- amtool alert add --alertmanager.url http://localhost:9093 alertname=myalarm --start="2025-03-31T00:00:00-00:00" service=example-app severity=critical --annotation="summary=\"This is a test alert with a custom summary\""
- Verify that the alert was generated:
$ oc exec alertmanager-main-0 -n openshift-monitoring -- amtool alert --alertmanager.url http://localhost:9093
Example output
Alertname Starts At Summary State myalarm 2025-03-31 00:00:00 UTC This is a test alert with a custom summary active Watchdog 2025-04-07 10:07:16 UTC An alert that should always be firing to certify that Alertmanager is working properly. active
- Verify that the receiver was notified with the
myalarmalert.
IMPORTANT NOTE: The test alert does not appear in the console nor queries to Prometheus alerts API Content from prometheus-k8s.openshift-monitoring.svc is not included.Content from prometheus-k8s.openshift-monitoring.svc is not included.https://prometheus-k8s.openshift-monitoring.svc:9091/api/v1/alerts. The test alerts are not generated in Prometheus at all.
Root Cause
- Need to test receivers without generating real alerts.
SBR
Product(s)
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.