Monitor Elasticsearch Servers with Shell Script – E-Mail Notification

Monitor Elasticsearch Servers with Shell Script - E-Mail Notification

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 filename.sh or ./filename.sh (in Linux/Unix OS)

Shell Script:

#!/bin/sh

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

#Configure the hostnames
hostname=("HOSTNAME1" "HOSTNAME2" "HOSTNAME3")

while true
do
   message=""
   flag=0
   for (( i=0; i < ${#IP[@]}; i++ ))
   do
      echo $i
      response=$(curl ${IP[$i]}:9200/_cluster/health)
      if [[ ! "$response" =~ "green" ]]; then
      flag=1
         if [[ "$response" =~ "red" ]]; 
         then
            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"
         fi
      fi
   done

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

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

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

           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
Elasticsearch:
  1. Execute Multiple Search Query in Elasticsearch
  2. Monitor Elasticsearch Servers with Shell Script - E-Mail Notification
  3. Execute Raw Elasticsearch Query using Transport Client – Java API
  4. Elasticsearch – Apply Nested Filter on Nested (Inner) Aggregation
  5. Execute Multiple Search Query in Elasticsearch
  6. Enable CORS to Send Cross Domain Request to Elasticsearch using AJAX
  7. Elasticsearch Java API – Get Index List
  8. Elasticsearch Java API – Get Alias List
  9. Elasticsearch Java API - Get Type List from given Index
  10. Elasticsearch Java API – Get Field List for a given Index and Type
  11. Elasticsearch Java API – Get Index Type List Mapping
  12. Elasticsearch – Use Script Filter/Conditon in Aggregation/Sub-Aggreagtion
  13. Elasticsearch – Compare/ScriptFilter/Condition on Two Fields using Script Filter – REST Query + Java API
  14. Elasticsearch - Date/Time(String)  Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds
Logstash:
  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
 Read More...

[ YOU MAY ALSO LIKE ]

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

Leave a Reply