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

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

change authentication

See merge request !148
parents 1adc24ec 0c2289d8
No related branches found
No related tags found
1 merge request!148change authentication
......@@ -10,16 +10,24 @@
# - curl
#
# SYNTAX:
# - check_couchdb [-h] [-t FILE] -m MODE
# - check_couchdb [-h] [-c CFGFILE] -m MODE
#
# ----------------------------------------------------------------------
# 2023-08-28 v0.1 <axel.hahn@unibe.ch>
# 2023-08-28 v0.1 <axel.hahn@unibe.ch> first lines
# 2023-08-28 v0.2 <axel.hahn@unibe.ch> first check "up"
# ======================================================================
. $(dirname $0)/inc_pluginfunctions
export self_APPVERSION=0.1
export self_APPVERSION=0.2
cfgfile=/etc/icingaclient/.couchdb
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help
function showHelp(){
local _self; _self=$(basename $0)
cat <<EOF
......@@ -32,9 +40,9 @@ $_self [-h] [-t FILE] -m MODE
OPTIONS:
-h or --help show this help.
-c CFGFILE set a custom config file
default: ${cfgfile}
-m MODE test a value; for debugging purposes
-t FILE take couchdb auth from Telegraph config
add file like /etc/telegraf/telegraf.conf
EXAMPLE:
$_self -m up
......@@ -43,6 +51,10 @@ $_self -m up
EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
# --- check param -h
case "$1" in
"--help"|"-h")
......@@ -52,26 +64,24 @@ case "$1" in
*)
esac
sTelegraph=$(ph.getValueWithParam "" "t" "$@")
sMode=$(ph.getValueWithParam '' "m" "$@")
cfgfile=$(ph.getValueWithParam "${cfgfile}" "c" "$@")
if [ -n "$sTelegraph" ]; then
if [ ! -r "${sTelegraph}" ]; then
echo "ERROR: Telegraph config file [${sTelegraph}] cannot be read."
showHelp
if [ ! -f "$cfgfile" ]; then
echo "ERROR: Config file [${cfgfile}] does not exist."
ph.abort
fi
_user=$( grep "basic_username = " "${sTelegraph}" | cut -f 2 -d '"' )
_pw=$( grep "basic_password = " "${sTelegraph}" | cut -f 2 -d '"' )
export COUCH_URL=http://${_user}:${_pw}@localhost:5984
fi
. "$cfgfile" || exit 1
if [ -z "$COUCH_URL" ]; then
echo "ERROR: I have no couchdb url + autentication yet."
echo "ERROR: I have no couchdb url + authentication yet."
echo "Maybe you need to add -t /etc/telegraf/telegraf.conf."
ph.abort
fi
# ----------------------------------------------------------------------
case "${sMode}" in
"up")
response=$( curl -s "${COUCH_URL}/_up" )
......@@ -81,7 +91,6 @@ case "${sMode}" in
fi
ph.status "Couchdb status (value in /_up is '$_status')"
echo "Reponse: "; echo "${response}" | jq
_status=$( jq '.status' <<< "${response}" | tr -d '"')
;;
*)
echo "ERRROR: [${sMode}] is an INVALID mode"
......@@ -91,3 +100,5 @@ case "${sMode}" in
esac
ph.exit
# ----------------------------------------------------------------------
......@@ -14,6 +14,7 @@ There is one include script used by all checks:
* [check_ceph_osd](check_ceph_osd.md)
* [check_ceph_status](check_ceph_status.md)
* [check_clientbackup](check_clientbackup.md)
* [check_couchdb](check_couchdb.md)
* check_couchdb-lb
* [check_cpu](check_cpu.md)
* [check_cronstatus](check_cronstatus.md)
......
# check_couchdb
## Introduction
Check couchdb status.
### Requirements
* a running couchdb service
* authentication (see section Installation below)
## Syntax
```text
> check_couchdb -h
______________________________________________________________________
CHECK_COUCHDB
v0.2
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_couchdb.html
______________________________________________________________________
Show couchdb status.
SYNTAX:
check_couchdb [-h] [-t FILE] -m MODE
OPTIONS:
-h or --help show this help.
-c CFGFILE set a custom config file
default: /etc/icingaclient/.couchdb
-m MODE test a value; for debugging purposes
EXAMPLE:
check_couchdb -m up
Check if couchdb is up and running
```
## Installation
The check script by default sources a file ``/etc/icingaclient/.couchdb``.
It is a shell script with read permissions for the icinga user.
It contains a line with the url to couchdb
```shell
# ls -l /etc/icingaclient/.couchdb
-r--------. 1 icingaclient icingaclient 110 Aug 29 09:53 /etc/icingaclient/.couchdb
# cat /etc/icingaclient/.couchdb
export COUCH_URL=http://USERNAME:PASSWORD@localhost:5984
```
The variable COUCH_URL will be used to request status information.
With parameter ``-c CFGFILE`` can define another location where to find the variable COUCH_URL.
## Checks
With the parameter ``-m METHOD`` you define what kind of check to perform.
### up
Simple check if couchdb is up and running.
`check_couchdb -m up` returns
```txt
OK: Couchdb status (value in /_up is 'ok')
Reponse:
{
"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": {}
}
}
```
......@@ -98,7 +98,7 @@ The check is build to be customizable. You can add
The related files are in 2 subdirectories with check_eol prefix:
```
```txt
> ls -1 check_eol-data/ check_eol-versiondetect/
check_eol-data/:
databases.cfg
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment