用於Nagios中監控elasticsearch健康狀態腳本

    在Nagios社區中上找了下相關用於監控elasticsearch索引的腳本,再通過修改下,能夠在平時用於傳入elasticsearch的監聽ip用於在Nagios中使用監控elasticsearch健康狀態的腳本ios

#!/bin/bash
#check_elasticsearch_health.sh
#Memo for Nagios outputs
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

#Position parameter judgment
if [ $# -lt 1 ];then
    echo "Please enter host address"
    echo "ex> $0 HOST_ADDRESS"
    exit $STATE_UNKNOWN
fi

if [ $# -gt 1 ]; then
        echo "The input host address are too much"
    echo "ex> $0 localhost"
    exit $STATE_UNKNOWN
fi

type curl >/dev/null 2>&1 || { echo >&2 "This plugin require curl but it's not installed."; exit $STATE_UNKNOWN; }
#檢查是否有安裝curl
HOST=$1

STATUS=$(curl -s $HOST:9200/_cluster/health?pretty | grep status | awk '{print $3}' | cut -d\" -f2)
#單節點的健康檢測,平時能夠根據須要監控內容來修改api獲取相應的值
if [[ $STATUS && "$STATUS" != "green" ]]; then
echo "CRITICAL - Status is $STATUS"
exit $STATE_CRITICAL
fi

if [[ "$STATUS" == "green" ]]; then
echo "OK - Status is $STATUS"
exit $STATE_OK
fi

echo "UNKNOW - No data were returned by elastisearch on host $HOST"
exit $STATE_UNKNOWN
相關文章
相關標籤/搜索