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

add check replication

parent 0c2289d8
No related branches found
No related tags found
1 merge request!1496588 add couchdb check
......@@ -15,11 +15,12 @@
# ----------------------------------------------------------------------
# 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"
# ======================================================================
. $(dirname $0)/inc_pluginfunctions
export self_APPVERSION=0.2
export self_APPVERSION=0.3
cfgfile=/etc/icingaclient/.couchdb
......@@ -42,7 +43,12 @@ OPTIONS:
-h or --help show this help.
-c CFGFILE set a custom config file
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:
$_self -m up
......@@ -51,6 +57,27 @@ $_self -m up
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
# ----------------------------------------------------------------------
......@@ -64,6 +91,8 @@ case "$1" in
*)
esac
ph.require jq
sMode=$(ph.getValueWithParam '' "m" "$@")
cfgfile=$(ph.getValueWithParam "${cfgfile}" "c" "$@")
......@@ -84,12 +113,32 @@ fi
case "${sMode}" in
"up")
response=$( curl -s "${COUCH_URL}/_up" )
response=$( get "/_up" )
abortOnWrongResponse "$response" "/_up" '"status":"'
_status=$( jq '.status' <<< "${response}" | tr -d '"')
if ! echo "$_status" | grep "ok" >/dev/null; then
ph.setStatus critical
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
;;
*)
......@@ -101,4 +150,4 @@ esac
ph.exit
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment