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

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

6588 add couchdb check

See merge request !149
parents 199686c0 6adcf000
No related branches found
No related tags found
1 merge request!1496588 add couchdb check
...@@ -15,11 +15,12 @@ ...@@ -15,11 +15,12 @@
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# 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"
# ====================================================================== # ======================================================================
. $(dirname $0)/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
export self_APPVERSION=0.2 export self_APPVERSION=0.3
cfgfile=/etc/icingaclient/.couchdb cfgfile=/etc/icingaclient/.couchdb
...@@ -42,7 +43,12 @@ OPTIONS: ...@@ -42,7 +43,12 @@ OPTIONS:
-h or --help show this help. -h or --help show this help.
-c CFGFILE set a custom config file -c CFGFILE set a custom config file
default: ${cfgfile} default: ${cfgfile}
-m MODE test a value; for debugging purposes -m MODE test a value; for debugging purposes the full json
response will be shown
MODE is one of
up show general couchdb status
replication show last replication status
EXAMPLE: EXAMPLE:
$_self -m up $_self -m up
...@@ -51,6 +57,27 @@ $_self -m up ...@@ -51,6 +57,27 @@ $_self -m up
EOF EOF
} }
# get couchdb status by given url and a filter
# The check aborts here if no data were found.
# 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"
if ! grep "$_filter" <<< "$_response" >/dev/null ; then
echo "ERROR: Wrong response from $_path - it does not contain $_filter"
curl -si "${COUCH_URL}${2}"
ph.abort
fi
}
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# MAIN # MAIN
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -64,6 +91,8 @@ case "$1" in ...@@ -64,6 +91,8 @@ case "$1" in
*) *)
esac esac
ph.require jq
sMode=$(ph.getValueWithParam '' "m" "$@") sMode=$(ph.getValueWithParam '' "m" "$@")
cfgfile=$(ph.getValueWithParam "${cfgfile}" "c" "$@") cfgfile=$(ph.getValueWithParam "${cfgfile}" "c" "$@")
...@@ -84,12 +113,32 @@ fi ...@@ -84,12 +113,32 @@ fi
case "${sMode}" in case "${sMode}" in
"up") "up")
response=$( curl -s "${COUCH_URL}/_up" ) response=$( get "/_up" )
abortOnWrongResponse "$response" "/_up" '"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 in /_up is '$_status')" ph.status "Couchdb status (value 'status' in /_up is '$_status')"
echo "Reponse: "; echo "${response}" | jq
;;
"replication")
response=$( get "/_up" )
abortOnWrongResponse "$response" "/_up" '"status":"'
_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
_nonok=$( echo "$_status" | grep -v "ok" )
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 echo "Reponse: "; echo "${response}" | jq
;; ;;
*) *)
......
...@@ -6,6 +6,8 @@ Check couchdb status. ...@@ -6,6 +6,8 @@ Check couchdb status.
### Requirements ### Requirements
* curl
* jq
* a running couchdb service * a running couchdb service
* authentication (see section Installation below) * authentication (see section Installation below)
...@@ -16,7 +18,7 @@ Check couchdb status. ...@@ -16,7 +18,7 @@ Check couchdb status.
______________________________________________________________________ ______________________________________________________________________
CHECK_COUCHDB CHECK_COUCHDB
v0.2 v0.3
(c) Institute for Medical Education - University of Bern (c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3 Licence: GNU GPL 3
...@@ -33,7 +35,12 @@ OPTIONS: ...@@ -33,7 +35,12 @@ OPTIONS:
-h or --help show this help. -h or --help show this help.
-c CFGFILE set a custom config file -c CFGFILE set a custom config file
default: /etc/icingaclient/.couchdb default: /etc/icingaclient/.couchdb
-m MODE test a value; for debugging purposes -m MODE test a value; for debugging purposes the full json
response will be shown
MODE is one of
up show general couchdb status
replication show last replication status
EXAMPLE: EXAMPLE:
check_couchdb -m up check_couchdb -m up
...@@ -66,13 +73,17 @@ With the parameter ``-m METHOD`` you define what kind of check to perform. ...@@ -66,13 +73,17 @@ With the parameter ``-m METHOD`` you define what kind of check to perform.
### up ### up
Simple check if couchdb is up and running. Simple check if couchdb is up and running.
From url ``/up`` it fetches the value status.
It switches to critical if one of the seeds is not "ok".
`check_couchdb -m up` returns `check_couchdb -m up` returns
```txt ```txt
OK: Couchdb status (value in /_up is 'ok') OK: Couchdb status (value in /_up is 'ok')
Reponse: Reponse:
{ {
"status": "ok", "status": "ok", <<< checked value
"seeds": { "seeds": {
"couchdb@192.168.25.172": { "couchdb@192.168.25.172": {
"timestamp": "2023-08-28T07:27:54.938619Z", "timestamp": "2023-08-28T07:27:54.938619Z",
...@@ -87,3 +98,30 @@ Reponse: ...@@ -87,3 +98,30 @@ Reponse:
} }
} }
``` ```
### replication
From url ``/up`` it fetches seeds -> [node] -> last_replication_status.
It switches to critical if one of the seeds is not "ok".
``check_couchdb -m replication`` returns
```txt
OK: Couchdb replication
Reponse:
{
"status": "ok",
"seeds": {
"couchdb@192.168.25.172": {
"timestamp": "2023-08-28T07:27:54.938619Z",
"last_replication_status": "ok", <<< checked value
"pending_updates": {
"_nodes": 0,
"_dbs": 0,
"_users": 0
}
},
"couchdb@192.168.25.61": {}
}
}
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment