Monitor Elasticsearch Servers with Shell Script – E-Mail Notification

           The following shell script can be used to monitor Elasticsearch servers. The basic idea is that the server (IP:9200) will respond with a color code(Green, Red and Yellow). We use the color code to know the status of the server and notify the users through configured E-Mail addresses. An E-Mail will be sent to configured E-Mail addresses when the Elasticsearch server goes down i.e. when the status goes red.

Steps to Configure the Shell Script:

  1. Copy the shell script content to a file and name it with extension .sh
  2. Add the required IP addresses of the Elasticsearch servers
  3. Add the hostnames(used for display purpose only) of the Elasticsearch servers
  4. Add the required E-Mail addresses
  5. Configure the sleep interval which is used by the script to check the status of the servers for each n minutes. Default value is 10m which represents 10minutes
  6. Start the script using the command sh or ./ (in Linux/Unix OS)

Shell Script:


#Configure the IP addresses
IP=("IP1" "IP2" "IP3")

#Configure the hostnames

while true
   for (( i=0; i < ${#IP[@]}; i++ ))
      echo $i
      response=$(curl ${IP[$i]}:9200/_cluster/health)
      if [[ ! "$response" =~ "green" ]]; then
         if [[ "$response" =~ "red" ]]; 
            message+="Elasticsearch Server ${hostname[$i]}(${IP[$i]}) is down\n"
         elif [[ "$response" =~ "yellow" ]]; then
            message+="Elasticsearch  server ${hostname[$i]}(${IP[$i]}) shards are allocating\n"
         elif [[ "$response" == "" ]]; then
            message+="Elasticsearch process is not running in ${hostname[$i]}(${IP[$i]})\n"

   if [ $flag == 1 ]; then
      echo "Sending Mail"

      #Configure the E-Mail addresses
      echo $message | mail -s "Pulse - Elasticssearch Server Down" EMailID1 EMailID2
      echo $message

   #Time duration between the monitoring. 10m represents 10 minutes
   sleep 10m

           The above shell script was tested and works fine in Red Hat Linux and it should also work in Unix based systems. Make sure to enable the mail settings in the system.

Related Links :

Web Application for Elasticsearch :
  1. ElasticTab – Elasticsearch to Excel Report (Web Application)
Elasticsearch Plugin:
  1. Elasticsearch Plugin To Generate (Save and E-Mail) Excel Reports
  1. Execute Multiple Search Query in Elasticsearch
  2. Monitor Elasticsearch Servers with Shell Script - E-Mail Notification
  3. Execute Multiple Search Query in Elasticsearch
  4. Enable CORS to Send Cross Domain Request to Elasticsearch using AJAX
  5. Elasticsearch – Use Script Filter/Conditon in Aggregation/Sub-Aggreagtion
  6. Elasticsearch - Date/Time(String)  Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds
  7. Elasticsearch Geo-Shape Slow Indexing Performance - Solved
  8. Chrome Elasticsearch Sense Not Working – Solved
  1. Logstash – Process Log File Once and Exit/Stop Logstash After Reading Log File Once
  2. Measure Logstash Performance using Metrics Filter – Issue/Error in Syntax (Unknown setting ‘message’ for stdout)
  3. Logstash – Process Same Log File (File Input) from Beginning/Start
  4. Create Custom Filter/Plugin to Emit New Events Manually in Logstash
Logstash and Elasticsearch:
  1. Query Elasticsearch Cluster in Filter Section when using Logstash
  2. Custom Elasticsearch Index Name/Type Name based on Events in Logstash
MongoDB and Elasticsearch:
  1. Import Data from Mongo DB to Elasticsearch using Elasticsearch River

3 thoughts on “Monitor Elasticsearch Servers with Shell Script – E-Mail Notification

Leave a Reply