用于Nagios中监控elasticsearch健康状态脚本

在Nagios社区中上找了下相关用于监控elasticsearch索引的脚本,再经过修改下,可以在平时用于传入elasticsearch的监听ip用于在Nagios中使用监控elasticsearch健康状态的脚本。

#!/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

CentOS 7下安装配置Nagios监控图文详解 

Nagios邮件报警配置简述 

Nagios本机及其他主机监控安装部署详解 

Nagios 系统监控基本安装配置过程详解 

Linux下Nagios+PNP4Nagios的安装与配置 

CentOS7安装Nagios并配置出图详解 

Linux下Nagios安装配置详解 

Nagios 的详细介绍请点这里
Nagios 的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/1872f84763bf5844a5e20e0bbb9067ce.html