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.
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
echo "Cluster Status: RED"
echo "Cluster Status: YELLOW"
echo "Cluster Status: GREEN"
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?