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

abort on http 5xx error

parent 6770ec69
No related branches found
No related tags found
1 merge request!4abort on http 5xx error
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,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
# ====================================================================== # ======================================================================
tmpfile=/tmp/outcurl.tmp tmpfile=/tmp/outcurl.tmp
...@@ -365,6 +366,10 @@ typeset cfg_dryrun=false ...@@ -365,6 +366,10 @@ 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 http.isServerError >/dev/null; then
echo "CRITICAL ERROR: Director API request failed with a server error $_sMethod $_sUrl"
exit 1
fi
if [ $_bShowResponse = true ]; then if [ $_bShowResponse = true ]; then
http.getResponseHeader http.getResponseHeader
http.getResponse http.getResponse
......
...@@ -13,11 +13,12 @@ ...@@ -13,11 +13,12 @@
# 2021-03-.. init # 2021-03-.. init
# 2022-01-11 v0.7 ah shellcheck # 2022-01-11 v0.7 ah shellcheck
# 2022-02-16 v0.8 ah add --cfg param # 2022-02-16 v0.8 ah add --cfg param
# 2022-03-04 v0.9 ah abort on http 5xx error
# ====================================================================== # ======================================================================
_product="ICINGA PASSIVE CLIENT" _product="ICINGA PASSIVE CLIENT"
_version="0.8" _version="0.9"
_license="GNU GPL 3.0" _license="GNU GPL 3.0"
_copyright='(c) 2020 Institute for Medical Education * University of Bern' _copyright='(c) 2020 Institute for Medical Education * University of Bern'
...@@ -248,6 +249,10 @@ function icingaHost(){ ...@@ -248,6 +249,10 @@ function icingaHost(){
http.setCacheTtl $_iRefreshCache http.setCacheTtl $_iRefreshCache
http.setCacheFile $_localCache http.setCacheFile $_localCache
http.makeRequest GET $_apiRequest http.makeRequest GET $_apiRequest
if http.isServerError >/dev/null; then
echo "CRITICAL ERROR: Icinga2 API request failed with a server error GET $_apiRequest"
exit 1
fi
# set return code of GET action # set return code of GET action
http.isOk >/dev/null http.isOk >/dev/null
......
...@@ -232,6 +232,10 @@ function _getIpPrivate(){ ...@@ -232,6 +232,10 @@ function _getIpPrivate(){
function _APIcall(){ function _APIcall(){
http.makeRequest "$1" "$2" "$3" http.makeRequest "$1" "$2" "$3"
if http.isServerError >/dev/null; then
echo "CRITICAL ERROR: API request failed with a server error $1 $2"
exit 1
fi
http.getResponseHeader http.getResponseHeader
http.getResponse http.getResponse
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment