How to specify Organisation when pausing all alerts

Hi guys

Grafana is structured into organisation and I have use that to make one for our azuredev teams at job Those azure VM shutdown a 17h so i wanted to pause only azuredev oraganisation but not the others that target corporated 24/7 VM.

What I found to pause/unpause alerts for all alerts all organisations

I did try the API key authentication but it keep saying no permission. Which is sad because API key authentication is focused on organisation.

So I did make an admin user for my azureedev organisation, but the previous curl commands don t work with that user as i do not know how to specify the organisation ?

Can someone help me find the right syntaxe to specify the target organisation in the above curl commands ?

Ty

This might be a bug that you have uncovered. The user has to be a Grafana Admin to execute the pause all alerts command but it does not seem to work when authenticating with an API key. Will take a deeper look at it tomorrow morning (european time).

After some investigation:

  • pause-all-alerts pauses all alerts for all organizations
  • It is registered as a Grafana Admin function which means API keys won’t work. This is apparently a feature and not a bug :slight_smile:

So unfortunately, to do what you want you will have to pause each alert individually:

Hi Daniellee

Ty for checking. this is what i have done.
So to share with others here is my script to pause all alert for a “organization” as you describe it, hope it will be usefull for someone.

Required:

  • a API KEY admin to your organisation
  • Something to format the onliner json output in a human readable format in order to grep in. As i am on Ubuntu i use “python -mjson.tool”. People will have to use anything that can format json output to multiple line. On Ubuntu do apt -y install python-minimal and you wil be able to pipe json output into python -mjson.tool

scripts to pause: (to unpause use “paused”: false)

#!/bin/bash
cd dirname $0
APIKEY=“YourAPIKEYGenerated with grafana for the target organization”
SERVER=“NameOrIP”
PORT=“3000”

AlertsList=`curl -H “Authorization: Bearer $APIKEY” -X GET http://$SERVER:$PORT/api/alerts 2>/dev/null | python -mjson.tool | grep “"id"” | sed s/,//g | awk ‘{print $2}’ | sort -n`
for i in $AlertsList
do
curl -X POST http://$SERVER:$PORT/api/alerts/$i/pause -H “Content-type: application/json” -d ‘{“alertId”: ‘$i’, “paused”: true }’ -H “Authorization: Bearer $APIKEY”
echo “”
done

Ty

EDIT: because some character where like " ` "not seen in forum post

Eric

1 Like

Thank you for sharing your script!