prometheus / alertmanager

Prometheus Alertmanager
https://prometheus.io
Apache License 2.0
6.59k stars 2.14k forks source link

Incomplete AlertManager API Documentation #2228

Open stevebail opened 4 years ago

stevebail commented 4 years ago

@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:

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

mxinden commented 4 years ago

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.

simonpasquier commented 4 years ago

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

stevebail commented 4 years ago

@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 :)

mxinden commented 4 years ago

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.

SadeghKrmi commented 3 years ago

if in bash, use | jq to handle output

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

ajaikumarsadasivam commented 3 years ago

@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

oalimerko commented 2 years ago

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

serrrios commented 2 years ago

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"}