# How do I determine which master node won an election?

**URL:** <https://discuss.elastic.co/t/how-do-i-determine-which-master-node-won-an-election/61173>\
**Category:** Elasticsearch\
**Created:** [September 21, 2016, 7:01pm UTC](https://discuss.elastic.co/t/how-do-i-determine-which-master-node-won-an-election/61173 "2016-09-21T19:01:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgibson](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rgibson](https://discuss.elastic.co/u/rgibson)\
**Post date:** [September 21, 2016, 7:01pm UTC](https://discuss.elastic.co/t/how-do-i-determine-which-master-node-won-an-election/61173/1 "2016-09-21T19:01:33Z")

</div>

I am trying to configure an alert in monit to alarm when my cluster state falls out of green. I have a short script that returns the text of the cluster state and issues a numeric return code that I can use to trigger an alert.

#!/bin/bash  
CLUSTERSTATUS=$(curl -s -XGET http://\<\>.example.com:9200/\_cluster/health?pretty=true | grep status | cut -d":" -f 2 | cut -d'"' -f 2)

case "$CLUSTERSTATUS" in  
red)  
echo "Cluster Status: RED"  
exit 2  
;;  
yellow)  
echo "Cluster Status: YELLOW"  
exit 1  
;;  
green)  
echo "Cluster Status: GREEN"  
exit 0  
;;  
esac

I would like to only have the elected master node running the script to avoid having duplicate alerts, one from each master node, as a copy of monit will be running locally on each system.

Is there an API to where I can determine the elected master in the way that curator can determine?

Thanks,  
Rob

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 21, 2016, 8:52pm UTC](https://discuss.elastic.co/t/how-do-i-determine-which-master-node-won-an-election/61173/2 "2016-09-21T20:52:03Z")

</div>

Yep - [https://www.elastic.co/guide/en/elasticsearch/reference/2.4/cat-master.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/cat-master.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:18pm UTC](https://discuss.elastic.co/t/how-do-i-determine-which-master-node-won-an-election/61173/3 "2017-07-05T22:18:22Z")

</div>


