alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Incomplete AlertManager API Documentation

Open stevebail opened this issue 4 years ago • 8 comments

@mxinden Either I don't know what I am doing or the Alert Manager API is not working as expected. Your assistance is greatly appreciated.

I am trying to get a list of active alerts using a filter and it does not work as expected. In all cases, I receive the complete list of active alarms. Example 1: curl -X GET http://10.44.0.3:9093/api/v2/alerts Here I get the full list of active alerts. So far so good!

Example 2: curl -X GET http://10.44.0.3:9093/api/v2/alerts?name=my_receiver Here I still get the full list of active alerts.

Example 2: curl -X GET http://10.44.0.3:9093/api/v2/alerts?alertname=my_alert.* Here I still get the full list of active alerts.

Unfortunately the AlertManager API documentation is poor vs Prometheus Server API documentation. See link below: https://prometheus.io/docs/alerting/management_api/

Below is the Alert Manager OPEN API spec but I don't know how to use it: https://github.com/prometheus/alertmanager/blob/master/api/v2/openapi.yaml

/alerts: get: tags: - alert operationId: getAlerts description: Get a list of alerts parameters: - in: query name: active type: boolean description: Show active alerts default: true - in: query name: silenced type: boolean description: Show silenced alerts default: true - in: query name: inhibited type: boolean description: Show inhibited alerts default: true - in: query name: unprocessed type: boolean description: Show unprocessed alerts default: true - name: filter in: query description: A list of matchers to filter alerts by required: false type: array collectionFormat: multi items: type: string - name: receiver in: query description: A regex matching receivers to filter alerts by required: false type: string

Can you provide examples showing how to construct alert queries with filters?

stevebail avatar Apr 07 '20 00:04 stevebail

Unfortunately the AlertManager API documentation is poor vs Prometheus Server API documentation. See link below: https://prometheus.io/docs/alerting/management_api/

This only documents the API documentation. Given that you stumbled over it, it might make sense to add a note in there. (PRs are welcome.)

Can you provide examples showing how to construct alert queries with filters?

On the projects readme there is an API section which should give some more insights.

The easiest way to construct your curl commands is probably the interactive swagger ui.

Let me know if this helps. Again, as this is an open source project it heavily depends on contributions, especially in the form of documentation. Thus if you find anything that would have helped you, please file a pull request.

mxinden avatar Apr 09 '20 12:04 mxinden

I agree with @mxinden: it would be good to mention the API specification in the official documentation.

simonpasquier avatar Apr 10 '20 15:04 simonpasquier

@mxinden Thank you very much for the tip. Both swagger and amtool work for me. The only question left is to know the syntax for querying alerts based on the receiver name using amtool. It works with swagger but it does not work with amtool.

This is what I am using so far: amtool alert query receiver="receiver-name" --alertmanager.url "url"

The response is an empty list. Help please :)

stevebail avatar Apr 16 '20 16:04 stevebail

I don't have much experience with amtool. In addition as this would be a usage question the mailing list is the best place to ask https://groups.google.com/forum/#!forum/prometheus-users.

mxinden avatar Apr 17 '20 14:04 mxinden

if in bash, use | jq to handle output

curl -X GET http://localhost:9093/api/v2/alerts/ | jq '{ alertname: .[].labels.alertname, instance: .[].labels.instance }'

SadeghKrmi avatar Jan 04 '21 11:01 SadeghKrmi

@mxinden, I see this ticket is still open, hence commenting the API calls I have used for reference:

To GET Active Alerts: curl -X GET http://localhost:9093/api/v1/alerts/?active=true

To GET Inactive Alerts: curl -X GET http://localhost:9093/api/v1/alerts/?active=false

To GET filtered Alerts based on a matcher: curl -X GET http://localhost:9093/api/v1/alerts/?filter=["alertname=my_alert.*"]

To GET all Silences: curl -X GET http://localhost:9093/api/v1/silences

To GET filtered Silence based on a matcher: curl -X GET http://localhost:9093/api/v1/silences/?filter=["alertname=my_alert.*"]

To DELETE a Silence: curl -X DELETE http://localhost:9093/api/v1/silence/e89f243c-bb21-47c6-9f1d-0f602830fcs9

ajaikumarcs avatar Jul 05 '21 15:07 ajaikumarcs

does AM support silences filtering only based on match label?What if i want to get only the active silences? I ran this call ,same as browser does in backend when AM UI is used for filtering the active silences:

curl -X GET http://127.0.0.1:9093/api/v2/silences?active=true

Unfortunately i get all silences,active and expired

oalimerko avatar May 23 '22 08:05 oalimerko

Don't work for me: curl -X GET http://localhost:9093/api/v1/alerts/?filter=["alertname=my_alert.*"] In browser: http://example.com:9093/api/v1/alerts?filter=[%22project=vm%22] {"status":"error","errorType":"bad_data","error":"bad matcher format: ["project=vm"]"}

what am I doing wrong?

UPD true url http://example.com:9093/api/v1/alerts?filter=project="vm" it now working UPD2 It now question.. how to use two filter? /alerts?filter=project="vm"&filter=env="test" - get the full list of all env UPD3 work link /api/v1/alerts?filter={project="vm",env="prod"}

serrrios avatar Jun 02 '22 08:06 serrrios