Skip to content
Snippets Groups Projects

change authentication

Merged Hahn Axel (hahn) requested to merge 6588-add-couchdb-check into master
1 file
+ 28
16
Compare changes
  • Side-by-side
  • Inline
+ 28
16
@@ -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
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
if [ ! -f "$cfgfile" ]; then
echo "ERROR: Config file [${cfgfile}] does not exist."
ph.abort
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" )
@@ -90,3 +100,5 @@ case "${sMode}" in
esac
ph.exit
# ----------------------------------------------------------------------
Loading