Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update check_es_system.sh #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions check_es_system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@
# 20201110: Fix thresholds in jthreads check #
# 20201125: Show names of read_only indexes with jq, set jq as default parser #
# 20210616: Fix authentication bug (#38) and non ES URL responding (#39) #
# 20210714: add --noproxy to curl, define "curlcmd" and "curlcmdauth" #
################################################################################
#Variables and defaults
STATE_OK=0 # define the exit code if status is OK
STATE_WARNING=1 # define the exit code if status is Warning
STATE_CRITICAL=2 # define the exit code if status is Critical
STATE_UNKNOWN=3 # define the exit code if status is Unknown
export PATH=$PATH:/usr/local/bin:/usr/bin:/bin # Set path
version=1.11.1
version=1.12.0
port=9200
httpscheme=http
unit=G
Expand Down Expand Up @@ -235,11 +236,14 @@ fi
################################################################################
# Retrieve information from Elasticsearch
getstatus() {
# define curl-commands for all calls (with and without authentication):
curlcmd="curl -k -s --max-time ${max_time} --noproxy ${host}"
curlcmdauth="curl -k -s --max-time ${max_time} --noproxy ${host} --basic -u ${user}:${pass}"
esurl="${httpscheme}://${host}:${port}/_cluster/stats"
eshealthurl="${httpscheme}://${host}:${port}/_cluster/health"
if [[ -z $user ]]; then
# Without authentication
esstatus=$(curl -k -s --max-time ${max_time} $esurl)
esstatus=$($curlcmd $esurl)
esstatusrc=$?
if [[ $esstatusrc -eq 7 ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
Expand All @@ -259,7 +263,7 @@ if [[ -z $user ]]; then
fi
# Additionally get cluster health infos
if [ $checktype = status ]; then
eshealth=$(curl -k -s --max-time ${max_time} $eshealthurl)
eshealth=$($curlcmd $eshealthurl)
if [[ -z $eshealth ]]; then
echo "ES SYSTEM CRITICAL - unable to get cluster health information"
exit $STATE_CRITICAL
Expand All @@ -270,7 +274,7 @@ fi
if [[ -n $user ]] || [[ -n $(echo $esstatus | grep -i authentication) ]] ; then
# Authentication required
authlogic
esstatus=$(curl -k -s --max-time ${max_time} --basic -u ${user}:${pass} $esurl)
esstatus=$($curlcmdauth $esurl)
esstatusrc=$?
if [[ $esstatusrc -eq 7 ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
Expand All @@ -296,7 +300,7 @@ if [[ -n $user ]] || [[ -n $(echo $esstatus | grep -i authentication) ]] ; then
fi
# Additionally get cluster health infos
if [[ $checktype = status ]]; then
eshealth=$(curl -k -s --max-time ${max_time} --basic -u ${user}:${pass} $eshealthurl)
eshealth=$($curlcmdauth $eshealthurl)
if [[ -z $eshealth ]]; then
echo "ES SYSTEM CRITICAL - unable to get cluster health information"
exit $STATE_CRITICAL
Expand Down Expand Up @@ -394,7 +398,7 @@ readonly) # Check Readonly status on given indexes
for index in $include; do
if [[ -z $user ]]; then
# Without authentication
settings=$(curl -k -s --max-time ${max_time} ${httpscheme}://${host}:${port}/$index/_settings)
settings=$($curlcmd ${httpscheme}://${host}:${port}/$index/_settings)
if [[ $? -eq 7 ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
exit $STATE_CRITICAL
Expand All @@ -417,7 +421,7 @@ readonly) # Check Readonly status on given indexes
if [[ -n $user ]] || [[ -n $(echo $esstatus | grep -i authentication) ]] ; then
# Authentication required
authlogic
settings=$(curl -k -s --max-time ${max_time} --basic -u ${user}:${pass} ${httpscheme}://${host}:${port}/$index/_settings)
settings=$($curlcmdauth ${httpscheme}://${host}:${port}/$index/_settings)
settingsrc=$?
if [[ $settingsrc -eq 7 ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
Expand Down Expand Up @@ -494,7 +498,7 @@ tps) # Check Thread Pool Statistics
getstatus
if [[ -z $user ]]; then
# Without authentication
threadpools=$(curl -k -s --max-time ${max_time} ${httpscheme}://${host}:${port}/_cat/thread_pool)
threadpools=$($curlcmd ${httpscheme}://${host}:${port}/_cat/thread_pool)
threadpoolrc=$?
if [[ $threadpoolrc -eq 7 ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
Expand All @@ -508,7 +512,7 @@ tps) # Check Thread Pool Statistics
if [[ -n $user ]] || [[ -n $(echo $esstatus | grep -i authentication) ]] ; then
# Authentication required
authlogic
threadpools=$(curl -k -s --max-time ${max_time} --basic -u ${user}:${pass} ${httpscheme}://${host}:${port}/_cat/thread_pool)
threadpools=$($curlcmdauth ${httpscheme}://${host}:${port}/_cat/thread_pool)
threadpoolrc=$?
if [[ $threadpoolrc -eq 7 ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
Expand Down Expand Up @@ -607,7 +611,7 @@ master) # Check Cluster Master
getstatus
if [[ -z $user ]]; then
# Without authentication
master=$(curl -k -s --max-time ${max_time} ${httpscheme}://${host}:${port}/_cat/master)
master=$($curlcmd ${httpscheme}://${host}:${port}/_cat/master)
masterrc=$?
if [[ $masterrc -eq 7 ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
Expand All @@ -621,7 +625,7 @@ master) # Check Cluster Master
if [[ -n $user ]] || [[ -n $(echo $esstatus | grep -i authentication) ]] ; then
# Authentication required
authlogic
master=$(curl -k -s --max-time ${max_time} --basic -u ${user}:${pass} ${httpscheme}://${host}:${port}/_cat/master)
master=$($curlcmdauth ${httpscheme}://${host}:${port}/_cat/master)
masterrc=$?
if [[ $threadpoolrc -eq 7 ]]; then
echo "ES SYSTEM CRITICAL - Failed to connect to ${host} port ${port}: Connection refused"
Expand Down