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 @@ ...@@ -16,13 +16,15 @@
# 2023-08-28 v0.1 <axel.hahn@unibe.ch> first lines # 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.2 <axel.hahn@unibe.ch> first check "up"
# 2023-08-28 v0.3 <axel.hahn@unibe.ch> add check "replication" # 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 . $(dirname $0)/inc_pluginfunctions
export self_APPVERSION=0.3 export self_APPVERSION=0.4
cfgfile=/etc/icingaclient/.couchdb cfgfile=/etc/icingaclient/.couchdb
export RESPONSE
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
...@@ -49,6 +51,7 @@ OPTIONS: ...@@ -49,6 +51,7 @@ OPTIONS:
MODE is one of MODE is one of
up show general couchdb status up show general couchdb status
replication show last replication status replication show last replication status
pending show count of pending updates for nodes, dbs and users
EXAMPLE: EXAMPLE:
$_self -m up $_self -m up
...@@ -59,21 +62,18 @@ EOF ...@@ -59,21 +62,18 @@ EOF
# get couchdb status by given url and a filter # get couchdb status by given url and a filter
# The check aborts here if no data were found. # 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 url to request; the part behind couchdb base url
# param string string to search for in the content # param string string to search for in the content
function get(){
_path="$1"
curl -s "${COUCH_URL}${_path}"
}
function abortOnWrongResponse(){ function abortOnWrongResponse(){
_response="$1" _path="$1"
_path="$2" _filter="$2"
_filter="$3"
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" echo "ERROR: Wrong response from $_path - it does not contain $_filter"
curl -si "${COUCH_URL}${2}" curl -si "${COUCH_URL}${_path}"
ph.abort ph.abort
fi fi
} }
...@@ -105,29 +105,31 @@ fi ...@@ -105,29 +105,31 @@ fi
if [ -z "$COUCH_URL" ]; then if [ -z "$COUCH_URL" ]; then
echo "ERROR: I have no couchdb url + authentication yet." 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 ph.abort
fi fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
case "${sMode}" in case "${sMode}" in
# ............................................................
"up") "up")
response=$( get "/_up" ) REQ=/_up
abortOnWrongResponse "$response" "/_up" '"status":"' abortOnWrongResponse "${REQ}" '"status":"'
_status=$( jq '.status' <<< "${response}" | tr -d '"') _status=$( jq '.status' <<< "${RESPONSE}" | tr -d '"')
if ! echo "$_status" | grep "ok" >/dev/null; then if ! echo "$_status" | grep "ok" >/dev/null; then
ph.setStatus critical ph.setStatus critical
fi fi
ph.status "Couchdb status (value 'status' in /_up is '$_status')" ph.status "Couchdb :: health status (value 'status' in ${REQ} is '$_status')"
echo "Reponse: "; echo "${response}" | jq echo "Reponse of ${REQ}: "; echo "${RESPONSE}" | jq
;; ;;
# ............................................................
"replication") "replication")
response=$( get "/_up" ) REQ=/_up
abortOnWrongResponse "$response" "/_up" '"status":"' 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. # there can be multiple sections "seeds" and multiple line responses.
# remove all lines with "ok" and check if there is any "bad content" left # remove all lines with "ok" and check if there is any "bad content" left
...@@ -135,12 +137,37 @@ case "${sMode}" in ...@@ -135,12 +137,37 @@ case "${sMode}" in
if [ -n "$_nonok" ]; then if [ -n "$_nonok" ]; then
ph.setStatus critical ph.setStatus critical
fi fi
if ! echo "$_status" | grep "ok" >/dev/null; then
ph.setStatus critical ph.status "Couchdb :: replication (values 'last_replication_status' in ${REQ} are '$_status')"
fi echo "Reponse: of ${REQ}"; echo "${RESPONSE}" | jq
ph.status "Couchdb replication" ;;
echo "Reponse: "; 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" echo "ERRROR: [${sMode}] is an INVALID mode"
showHelp showHelp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment