From 6dd26a138216eab984d2a79cc13a6b792a257080 Mon Sep 17 00:00:00 2001 From: Mark Kelly-Smith Date: Thu, 25 May 2023 17:07:04 +0100 Subject: [PATCH 1/3] Fixed typo --- recipes/update_healthrule_bulk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/update_healthrule_bulk.sh b/recipes/update_healthrule_bulk.sh index 4e5fd24..56b2e71 100755 --- a/recipes/update_healthrule_bulk.sh +++ b/recipes/update_healthrule_bulk.sh @@ -126,7 +126,7 @@ getHRLIST() { echo " No -H param, getting ALL HR" HRLIST=$(../act.sh -E ${ENVIRONMENT} healthrule list -a ${APPID} | jq -r '.[] | .id') else - echo " -H '${HRSTRING}', getting mathcing HRs" + echo " -H '${HRSTRING}', getting matching HRs" # Get list if HR IDs matching HRSTRING HRLIST=$(../act.sh -E ${ENVIRONMENT} healthrule list -a ${APPID} | jq -r --arg PATTERN "${HRSTRING}" '.[] | select(.name | contains($PATTERN)) | .id') fi From 7c1a70fc45c90bfb9bb25ae00e51aea98f295cd0 Mon Sep 17 00:00:00 2001 From: Mark Kelly-Smith Date: Thu, 25 May 2023 17:08:24 +0100 Subject: [PATCH 2/3] Improved HR list ouptut and operation --- recipes/update_healthrule_bulk.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/recipes/update_healthrule_bulk.sh b/recipes/update_healthrule_bulk.sh index 56b2e71..70e11a8 100755 --- a/recipes/update_healthrule_bulk.sh +++ b/recipes/update_healthrule_bulk.sh @@ -128,7 +128,7 @@ getHRLIST() { else echo " -H '${HRSTRING}', getting matching HRs" # Get list if HR IDs matching HRSTRING - HRLIST=$(../act.sh -E ${ENVIRONMENT} healthrule list -a ${APPID} | jq -r --arg PATTERN "${HRSTRING}" '.[] | select(.name | contains($PATTERN)) | .id') + HRLIST=$(../act.sh -E ${ENVIRONMENT} healthrule list -a ${APPID} | jq -r --arg PATTERN "${HRSTRING}" '.[] | select(.name | contains($PATTERN)) | "\(.id), \(.name)"') fi echo "${HRLIST}" echo "----------------------------------------------------------------------------" @@ -141,8 +141,12 @@ updateHRData() { # Reset our vars and carry on resetVars + OLDIFS=$IFS + IFS=$'\r\n' + # Iterate through HR list - for HRID in $HRLIST; do + for HRITEM in $HRLIST; do + HRID=$(echo ${HRITEM} | cut -d "," -f1) echo "Updating ${HRID}..." # Set our URI for getting/updating current HR HEATHRULEURI="/controller/alerting/rest/v1/applications/${APPID}/health-rules/${HRID}" @@ -168,6 +172,8 @@ updateHRData() { fi done + IFS=$OLDIFS + echo "----------------------------------------------------------------------------" echo "Completed HR updates" echo "----------------------------------------------------------------------------" From 92942763668da346e6f16f62c0b0106fd7434c97 Mon Sep 17 00:00:00 2001 From: Mark Kelly-Smith Date: Thu, 25 May 2023 17:09:26 +0100 Subject: [PATCH 3/3] added regex flags for grep and sed --- recipes/update_healthrule_bulk.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipes/update_healthrule_bulk.sh b/recipes/update_healthrule_bulk.sh index 70e11a8..9beec27 100755 --- a/recipes/update_healthrule_bulk.sh +++ b/recipes/update_healthrule_bulk.sh @@ -154,16 +154,16 @@ updateHRData() { HROUTPUT=$(../act.sh -E ${ENVIRONMENT} controller call -X GET ${HEATHRULEURI}) # Do we see the PATTERNIN in our HR? - HROUTPUTCHECK=$(echo ${HROUTPUT} | grep "${PATTERNIN}") + HROUTPUTCHECK=$(echo ${HROUTPUT} | grep -E "${PATTERNIN}") if [[ -z ${HROUTPUTCHECK} ]]; then echo " No pattern match found in health rule, skipping any changes..." continue else # Update the HR json - HROUTPUTUPDATED=$(echo "${HROUTPUT}" | sed "s|${PATTERNIN}|${PATTERNOUT}|g") + HROUTPUTUPDATED=$(echo "${HROUTPUT}" | sed -r "s|${PATTERNIN}|${PATTERNOUT}|g") # PUT our HR json back HRPUTRESPONSE=$(../act.sh -E ${ENVIRONMENT} controller call -X PUT -d "${HROUTPUTUPDATED}" ${HEATHRULEURI}) - HRPUTRESPONSECHECK=$(echo ${HRPUTRESPONSE} | grep "\"id\":${HRID},") + HRPUTRESPONSECHECK=$(echo ${HRPUTRESPONSE} | grep -E "\"id\":${HRID},") if [[ ${HRPUTRESPONSECHECK} ]]; then echo " Updated" else