Check the health status of elasticsearch instance, sends an email if the response status is not 200.
You can run this with cronjob, creates a file to do not send the email multiple times if the server is down.
Note : Change the ‘host-elastic-server’ to your elasticsearch instance IP.
#!/bin/bash
mailSentFileFlag="mail_sent"
status_code=$(curl --write-out %{http_code} --silent --output /dev/null http://host-elastic-server:9200/_cluster/health)
if [[ ( "$status_code" -ne 200 ) && ( ! -f ${mailSentFileFlag} ) ]] ; then
echo "Elasticsearch is down. Status code $status_code" | mail -s "Elasticsearch monior" "mail1@gmail.com,mail2@gmail.com" -r "ElasticSearch Monitor"
echo "yeah"
touch ${mailSentFileFlag}
else
exit 0
fi