How do I determine which master node won an election?


(Rob Gibson) #1

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


(Mark Walkom) #2

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


(system) #3