# How to specify Organisation when pausing all alerts

**URL:** <https://community.grafana.com/t/how-to-specify-organisation-when-pausing-all-alerts/762>\
**Category:** Developers & API\
**Tags:** scripts, api, alerting\
**Created:** [May 2, 2017, 2:44pm UTC](https://community.grafana.com/t/how-to-specify-organisation-when-pausing-all-alerts/762 "2017-05-02T14:44:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eridur142](https://avatars.discourse-cdn.com/v4/letter/e/c67d28/32.png) [@eridur142](https://community.grafana.com/u/eridur142)\
**Post date:** [May 2, 2017, 2:44pm UTC](https://community.grafana.com/t/how-to-specify-organisation-when-pausing-all-alerts/762/1 "2017-05-02T14:44:53Z")

</div>

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

- pause : curl --http1.1 -X POST [http://admin:password@yourserver:3000/api/admin/pause-all-alerts](http://admin:password@yourserver:3000/api/admin/pause-all-alerts) -H “Content-type: application/json” -d ‘{“paused”: true}’
- unpause: same but ‘{“paused”: false}’

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

---

<div class="post-metadata">

**Author:** ![daniellee](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/daniellee/32/41_2.png) [@daniellee](https://community.grafana.com/u/daniellee)\
**Post date:** [May 2, 2017, 3:41pm UTC](https://community.grafana.com/t/how-to-specify-organisation-when-pausing-all-alerts/762/2 "2017-05-02T15:41:10Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![daniellee](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/daniellee/32/41_2.png) [@daniellee](https://community.grafana.com/u/daniellee)\
**Post date:** [May 3, 2017, 4:00pm UTC](https://community.grafana.com/t/how-to-specify-organisation-when-pausing-all-alerts/762/3 "2017-05-03T16:00:34Z")

</div>

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 🙂

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

- First by [getting all the alerts](http://docs.grafana.org/http_api/alerting/#get-alerts) for your organization using your API key

- Then you will have to loop through each alert and [pause them one by one](http://docs.grafana.org/http_api/alerting/#pause-alert).

---

<div class="post-metadata">

**Author:** ![eridur142](https://avatars.discourse-cdn.com/v4/letter/e/c67d28/32.png) [@eridur142](https://community.grafana.com/u/eridur142)\
**Post date:** [May 3, 2017, 6:51pm UTC](https://community.grafana.com/t/how-to-specify-organisation-when-pausing-all-alerts/762/4 "2017-05-03T18:51:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daniellee](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/daniellee/32/41_2.png) [@daniellee](https://community.grafana.com/u/daniellee)\
**Post date:** [May 4, 2017, 7:11am UTC](https://community.grafana.com/t/how-to-specify-organisation-when-pausing-all-alerts/762/5 "2017-05-04T07:11:45Z")

</div>

Thank you for sharing your script!

---

<div class="post-metadata">

**Author:** ![anon80964540](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@anon80964540](https://community.grafana.com/u/anon80964540)\
**Post date:** [January 13, 2021, 4:02pm UTC](https://community.grafana.com/t/how-to-specify-organisation-when-pausing-all-alerts/762/6 "2021-01-13T16:02:25Z")

</div>


