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

Merge branch '6588-add-couchdb-check' into 'master'

6588 add couchdb check - add pending updates

See merge request !150
parents 8fbcafbe 2770f91c
Branches
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
......
......@@ -18,7 +18,7 @@ Check couchdb status.
______________________________________________________________________
CHECK_COUCHDB
v0.3
v0.4
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
......@@ -41,6 +41,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:
check_couchdb -m up
......@@ -80,10 +81,47 @@ It switches to critical if one of the seeds is not "ok".
`check_couchdb -m up` returns
```txt
OK: Couchdb status (value in /_up is 'ok')
Reponse:
OK: Couchdb :: health status (value 'status' in /_up is 'ok')
Reponse of /_up:
{
"status": "ok", <<< checked value
"status": "ok",
"seeds": {
"couchdb@192.168.25.172": {
"timestamp": "2023-08-28T07:27:54.938619Z",
"last_replication_status": "ok",
"pending_updates": {
"_nodes": 0,
"_dbs": 0,
"_users": 0
}
},
"couchdb@192.168.25.61": {}
}
}
```
### pending
From url ``/up`` it fetches from seeds -> [node] -> pending_updates the values for
* _nodes
* _dbs
* _users
and summarizes its values.
It switches to warning if one of the values is > 0.
This check sends performance data.
``check_couchdb -m pending`` returns
```txt
OK: Couchdb :: pending updates: 0 (values below 'pending_updates' in /_up)
Reponse: of /_up
{
"status": "ok",
"seeds": {
"couchdb@192.168.25.172": {
"timestamp": "2023-08-28T07:27:54.938619Z",
......@@ -97,6 +135,7 @@ Reponse:
"couchdb@192.168.25.61": {}
}
}
|nodes=0;; dbs=0;; users=0;;
```
### replication
......@@ -107,14 +146,14 @@ It switches to critical if one of the seeds is not "ok".
``check_couchdb -m replication`` returns
```txt
OK: Couchdb replication
Reponse:
OK: Couchdb :: replication (values 'last_replication_status' in /_up are 'ok')
Reponse: of /_up
{
"status": "ok",
"seeds": {
"couchdb@192.168.25.172": {
"timestamp": "2023-08-28T07:27:54.938619Z",
"last_replication_status": "ok", <<< checked value
"last_replication_status": "ok",
"pending_updates": {
"_nodes": 0,
"_dbs": 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment