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

Merge branch '6072-fix-shell-warnings' into 'master'

fix _bStopOnError; some shellfixes

See merge request !22
parents 32ad2086 7ca32cea
No related branches found
No related tags found
1 merge request!22fix _bStopOnError; some shellfixes
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
# ah = axel.hahn@iml.unibe.ch # ah = axel.hahn@iml.unibe.ch
# 2022-02-16 v0.2 ah add --cfg param # 2022-02-16 v0.2 ah add --cfg param
# 2022-03-04 v0.3 ah abort on http 5xx error # 2022-03-04 v0.3 ah abort on http 5xx error
# 2023-01-22 v0.4 ah fix _bStopOnError; some shellfixes
# ====================================================================== # ======================================================================
tmpfile=/tmp/outcurl.tmp tmpfile=/tmp/outcurl.tmp
...@@ -57,8 +58,8 @@ typeset cfg_dryrun=false ...@@ -57,8 +58,8 @@ typeset cfg_dryrun=false
function _initVars(){ function _initVars(){
if [ -z "$loadfile" ]; then if [ -z "$loadfile" ]; then
MY_NAME=`hostname -f` MY_NAME=$(hostname -f)
MY_IP=`_getIpFrontend | head -1` MY_IP=$(_getIpFrontend | head -1)
MY_ZONE= MY_ZONE=
fi fi
IDC_host__cachefile="${dir_data}/${MY_NAME}__host_at-director.txt" IDC_host__cachefile="${dir_data}/${MY_NAME}__host_at-director.txt"
...@@ -69,7 +70,7 @@ typeset cfg_dryrun=false ...@@ -69,7 +70,7 @@ typeset cfg_dryrun=false
} }
function flushDatadir(){ function flushDatadir(){
if [ ! -z "${dir_data}" -a -d "${dir_data}" ]; then if [ -n "${dir_data}" -a -d "${dir_data}" ]; then
_wd "deleting ${dir_data} ..." _wd "deleting ${dir_data} ..."
rm -f ${dir_data}/*.txt rm -f ${dir_data}/*.txt
fi fi
...@@ -87,10 +88,10 @@ typeset cfg_dryrun=false ...@@ -87,10 +88,10 @@ typeset cfg_dryrun=false
if [ -z "$loadfile" ]; then if [ -z "$loadfile" ]; then
# --- host infos # --- host infos
local MY_Platform=`uname -a | cut -f 1 -d ' '` local MY_Platform=$(uname -a | cut -f 1 -d ' ')
. `dirname $0`/plugins/inc_pluginfunctions || exit 1 . $(dirname $0)/plugins/inc_pluginfunctions || exit 1
local MY_OSName=`ph.getOS` local MY_OSName=$(ph.getOS)
local MY_OSMajorVersion=`ph.getOSMajor` local MY_OSMajorVersion=$(ph.getOSMajor)
fi fi
export CFGSTORAGE="directorhost" export CFGSTORAGE="directorhost"
...@@ -121,16 +122,16 @@ typeset cfg_dryrun=false ...@@ -121,16 +122,16 @@ typeset cfg_dryrun=false
# ----- set host type # ----- set host type
# host in the UNIBE network: # host in the UNIBE network:
echo $MY_IP | grep -E "^(10\.|172\.1[6-9]\.|172.2[0-9]\.|172\.3[01]\.|192.168\.)" >/dev/null if echo "$MY_IP" | grep -E "^(10\.|172\.1[6-9]\.|172.2[0-9]\.|172\.3[01]\.|192.168\.)" >/dev/null
if [ $? -eq 0 ]; then then
$ch --set imports '["host passive only"]' $ch --set imports '["host passive only"]'
else else
$ch --set imports '["host in network"]' $ch --set imports '["host in network"]'
# port checks initiated by icinga server to monitor client # port checks initiated by icinga server to monitor client
if [ ! -z "${host_vars_tcpport}" -a "${host_vars_tcpport}" != "[]" ]; then if [ -n "${host_vars_tcpport}" -a "${host_vars_tcpport}" != "[]" ]; then
host_vars_tcpport=`echo ${host_vars_tcpport} | sed "s# ##g"` host_vars_tcpport=$(echo ${host_vars_tcpport} | sed "s# ##g")
$ch --set vars.tcp_port ${host_vars_tcpport} $ch --set vars.tcp_port "${host_vars_tcpport}"
fi fi
fi fi
...@@ -361,7 +362,7 @@ typeset cfg_dryrun=false ...@@ -361,7 +362,7 @@ typeset cfg_dryrun=false
# --- get json data of object # --- get json data of object
if [ $_bSendData = true ]; then if [ $_bSendData = true ]; then
_jsondata=`$ch --json 2>/dev/null` _jsondata=$($ch --json 2>/dev/null)
fi fi
$ch --flush 2>/dev/null $ch --flush 2>/dev/null
...@@ -369,7 +370,7 @@ typeset cfg_dryrun=false ...@@ -369,7 +370,7 @@ typeset cfg_dryrun=false
if [ ${_paramDryrun} = false ]; then if [ ${_paramDryrun} = false ]; then
_wd ">>>>> $_paramAction $_paramObj [${_object_name}] >> $_sMethod $_sUrl $_jsondata" _wd ">>>>> $_paramAction $_paramObj [${_object_name}] >> $_sMethod $_sUrl $_jsondata"
http.makeRequest "$_sMethod" "$_sUrl" "$_jsondata" http.makeRequest "$_sMethod" "$_sUrl" "$_jsondata"
if _bStopOnError && http.isServerError >/dev/null; then if $_bStopOnError && http.isServerError >/dev/null; then
echo "CRITICAL ERROR: Director API request failed with a server error $_sMethod $_sUrl" echo "CRITICAL ERROR: Director API request failed with a server error $_sMethod $_sUrl"
exit 1 exit 1
fi fi
...@@ -446,7 +447,7 @@ typeset cfg_dryrun=false ...@@ -446,7 +447,7 @@ typeset cfg_dryrun=false
_h2 "create host" _h2 "create host"
ObjAction create host ObjAction create host
if [ -z "`http.isOk`" ]; then if [ -z "$(http.isOk)" ]; then
echo "ERROR, host was NOT created." echo "ERROR, host was NOT created."
else else
echo "OK, host was created successfully." echo "OK, host was created successfully."
...@@ -460,7 +461,7 @@ typeset cfg_dryrun=false ...@@ -460,7 +461,7 @@ typeset cfg_dryrun=false
function hostRead(){ function hostRead(){
_h2 "read host" _h2 "read host"
ObjAction read host ObjAction read host
if [ -z "`http.isOk`" ]; then if [ -z "$(http.isOk)" ]; then
echo "ERROR, host was NOT found." echo "ERROR, host was NOT found."
fi fi
} }
...@@ -473,8 +474,8 @@ typeset cfg_dryrun=false ...@@ -473,8 +474,8 @@ typeset cfg_dryrun=false
_h2 "update host - set $1 $2" _h2 "update host - set $1 $2"
ObjAction update host ObjAction update host
if [ -z "`http.isOk`" ]; then if [ -z "$(http.isOk)" ]; then
case `http.getStatuscode` in case $(http.getStatuscode) in
"304") "304")
echo "OK, no update" echo "OK, no update"
;; ;;
...@@ -503,7 +504,7 @@ typeset cfg_dryrun=false ...@@ -503,7 +504,7 @@ typeset cfg_dryrun=false
function hostDelete(){ function hostDelete(){
_h2 "delete host" _h2 "delete host"
ObjAction delete host ObjAction delete host
case `http.getStatuscode` in case $(http.getStatuscode) in
"200") "200")
echo "OK, host was deleted" echo "OK, host was deleted"
;; ;;
...@@ -535,7 +536,7 @@ typeset cfg_dryrun=false ...@@ -535,7 +536,7 @@ typeset cfg_dryrun=false
IDC_command__obj_name="${checkName}" IDC_command__obj_name="${checkName}"
IDC_service__obj_name="service-template_for_command_${checkName}" IDC_service__obj_name="service-template_for_command_${checkName}"
IDC_svcathost__obj_name="`_getName4Svcathost ${checkName}`" IDC_svcathost__obj_name="$(_getName4Svcathost ${checkName})"
# IDC_service__obj_name="${checkName}" # IDC_service__obj_name="${checkName}"
# IDC_svcathost__obj_name="${checkName}" # IDC_svcathost__obj_name="${checkName}"
...@@ -603,7 +604,7 @@ typeset cfg_dryrun=false ...@@ -603,7 +604,7 @@ typeset cfg_dryrun=false
_h2 "${FUNCNAME[0]}() - create all services" _h2 "${FUNCNAME[0]}() - create all services"
# loop over all services and create # loop over all services and create
for mycheckfile in `getChecks` for mycheckfile in $(getChecks)
do do
serviceCreateByCfgFile "${mycheckfile}" serviceCreateByCfgFile "${mycheckfile}"
echo echo
...@@ -624,7 +625,7 @@ typeset cfg_dryrun=false ...@@ -624,7 +625,7 @@ typeset cfg_dryrun=false
# --- perpare II: create file with local configs and object names for its link # --- perpare II: create file with local configs and object names for its link
rm -f $tmpLocal 2>/dev/null rm -f $tmpLocal 2>/dev/null
for mycheckfile in `getChecks` for mycheckfile in $(getChecks)
do do
_parseCheckConfig "${mycheckfile}" _parseCheckConfig "${mycheckfile}"
_generateVarsByCheckname "${checkName}" _generateVarsByCheckname "${checkName}"
...@@ -640,12 +641,12 @@ typeset cfg_dryrun=false ...@@ -640,12 +641,12 @@ typeset cfg_dryrun=false
# _h3 "Compare" # _h3 "Compare"
cat $tmpRemote | while read remoteLink cat $tmpRemote | while read remoteLink
do do
grep $remoteLink $tmpLocal >/dev/null if grep "$remoteLink" $tmpLocal >/dev/null
if [ $? -eq 0 ]; then then
echo "OK: $remoteLink" echo "OK: $remoteLink"
else else
echo "DELETE: link [$remoteLink] is not used by any local check anymore." echo "DELETE: link [$remoteLink] is not used by any local check anymore."
checkName=`_getName4Svcathost $remoteLink reverse` checkName=$(_getName4Svcathost $remoteLink reverse)
_generateVarsByCheckname "${checkName}" _generateVarsByCheckname "${checkName}"
ObjAction delete svclink ObjAction delete svclink
fi fi
...@@ -667,7 +668,7 @@ typeset cfg_dryrun=false ...@@ -667,7 +668,7 @@ typeset cfg_dryrun=false
_wd POST director/config/deploy _wd POST director/config/deploy
_APIcall POST director/config/deploy _APIcall POST director/config/deploy
if [ -z "`http.isOk`" ]; then if [ -z "$(http.isOk)" ]; then
echo "ERROR deploy config was not queued." echo "ERROR deploy config was not queued."
else else
echo "OK, deploy was triggered" echo "OK, deploy was triggered"
...@@ -678,7 +679,7 @@ typeset cfg_dryrun=false ...@@ -678,7 +679,7 @@ typeset cfg_dryrun=false
# #
# show a help # show a help
function showHelp(){ function showHelp(){
script=`basename $0` script=$(basename $0)
cat <<ENDOFHELP cat <<ENDOFHELP
HELP: HELP:
...@@ -779,8 +780,8 @@ if [ "$1" = "--cfg" ] && [ -n "$2" ]; then ...@@ -779,8 +780,8 @@ if [ "$1" = "--cfg" ] && [ -n "$2" ]; then
else else
. "$( dirname $0 )/inc_getconfig.sh" . "$( dirname $0 )/inc_getconfig.sh"
fi fi
. `dirname $0`/inc_functions.sh . $(dirname $0)/inc_functions.sh
. `dirname $0`/inc/rest-api-client.sh . $(dirname $0)/inc/rest-api-client.sh
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
...@@ -788,8 +789,8 @@ if [ $# -eq 0 ]; then ...@@ -788,8 +789,8 @@ if [ $# -eq 0 ]; then
exit 0 exit 0
fi fi
cd `dirname $0` cd $(dirname $0) || exit
ls ./`basename $0` >/dev/null || exit 1 ls ./$(basename $0) >/dev/null || exit 1
_initVars _initVars
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment