Skip to content
Snippets Groups Projects
Commit 42d5fc59 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

couchdb: add pending updates

parent 6adcf000
No related branches found
No related tags found
1 merge request!1506588 add couchdb check - add pending updates
......@@ -16,13 +16,15 @@
# 2023-08-28 v0.1 <axel.hahn@unibe.ch> first lines
# 2023-08-28 v0.2 <axel.hahn@unibe.ch> first check "up"
# 2023-08-28 v0.3 <axel.hahn@unibe.ch> add check "replication"
# 2023-08-28 v0.4 <axel.hahn@unibe.ch> add check "pending"
# ======================================================================
. $(dirname $0)/inc_pluginfunctions
export self_APPVERSION=0.3
export self_APPVERSION=0.4
cfgfile=/etc/icingaclient/.couchdb
export RESPONSE
# ----------------------------------------------------------------------
# FUNCTIONS
......@@ -49,6 +51,7 @@ OPTIONS:
MODE is one of
up show general couchdb status
replication show last replication status
pending show count of pending updates for nodes, dbs and users
EXAMPLE:
$_self -m up
......@@ -59,21 +62,18 @@ EOF
# get couchdb status by given url and a filter
# The check aborts here if no data were found.
# Response is written into global var RESPONSE
#
# param string url to request; the part behind couchdb base url
# param string string to search for in the content
function get(){
_path="$1"
curl -s "${COUCH_URL}${_path}"
}
function abortOnWrongResponse(){
_response="$1"
_path="$2"
_filter="$3"
_path="$1"
_filter="$2"
if ! grep "$_filter" <<< "$_response" >/dev/null ; then
RESPONSE=$( curl -s "${COUCH_URL}${_path}" )
if ! grep "$_filter" <<< "$RESPONSE" >/dev/null ; then
echo "ERROR: Wrong response from $_path - it does not contain $_filter"
curl -si "${COUCH_URL}${2}"
curl -si "${COUCH_URL}${_path}"
ph.abort
fi
}
......@@ -105,29 +105,31 @@ fi
if [ -z "$COUCH_URL" ]; then
echo "ERROR: I have no couchdb url + authentication yet."
echo "Maybe you need to add -t /etc/telegraf/telegraf.conf."
echo "set 'export COUCH_URL=http://USER:PW@localhost:5984' in $cfgfile"
ph.abort
fi
# ----------------------------------------------------------------------
case "${sMode}" in
# ............................................................
"up")
response=$( get "/_up" )
abortOnWrongResponse "$response" "/_up" '"status":"'
REQ=/_up
abortOnWrongResponse "${REQ}" '"status":"'
_status=$( jq '.status' <<< "${response}" | tr -d '"')
_status=$( jq '.status' <<< "${RESPONSE}" | tr -d '"')
if ! echo "$_status" | grep "ok" >/dev/null; then
ph.setStatus critical
fi
ph.status "Couchdb status (value 'status' in /_up is '$_status')"
echo "Reponse: "; echo "${response}" | jq
ph.status "Couchdb :: health status (value 'status' in ${REQ} is '$_status')"
echo "Reponse of ${REQ}: "; echo "${RESPONSE}" | jq
;;
# ............................................................
"replication")
response=$( get "/_up" )
abortOnWrongResponse "$response" "/_up" '"status":"'
REQ=/_up
abortOnWrongResponse "${REQ}" '"status":"'
_status=$( jq '.seeds[] | .last_replication_status' <<< "${response}" | grep -v "null" | tr -d '"')
_status=$( jq '.seeds[] | .last_replication_status' <<< "${RESPONSE}" | grep -v "null" | tr -d '"')
# there can be multiple sections "seeds" and multiple line responses.
# remove all lines with "ok" and check if there is any "bad content" left
......@@ -135,12 +137,37 @@ case "${sMode}" in
if [ -n "$_nonok" ]; then
ph.setStatus critical
fi
if ! echo "$_status" | grep "ok" >/dev/null; then
ph.setStatus critical
fi
ph.status "Couchdb replication"
echo "Reponse: "; echo "${response}" | jq
ph.status "Couchdb :: replication (values 'last_replication_status' in ${REQ} are '$_status')"
echo "Reponse: of ${REQ}"; echo "${RESPONSE}" | jq
;;
# ............................................................
"pending")
REQ=/_up
abortOnWrongResponse "${REQ}" '"status":"'
_status=$( jq '.seeds[] | .pending_updates' <<< "${RESPONSE}" | grep -v "null" | tr -d '"')
typeset -i _iSumme
typeset -i _iTotal
_iTotal=0
for myvar in _nodes _dbs _users
do
_iSumme=0
for myvalue in $( grep "$myvar" <<< "$_status" | cut -f 2 -d ':' | tr -d ',')
do
_iSumme+=$myvalue
test "$myvalue" -gt 0 && ph.setStatus warning
done
ph.perfadd "$myvar" "$_iSumme" "" ""
_iTotal+=$_iSumme
done
ph.status "Couchdb :: pending updates: $_iTotal (values below 'pending_updates' in ${REQ})"
echo "Reponse: of ${REQ}"; echo "${RESPONSE}" | jq
;;
# ............................................................
*)
echo "ERRROR: [${sMode}] is an INVALID mode"
showHelp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment