Skip to content

update_healthrule_bulk.sh recipe fixes #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions recipes/update_healthrule_bulk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ 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')
HRLIST=$(../act.sh -E ${ENVIRONMENT} healthrule list -a ${APPID} | jq -r --arg PATTERN "${HRSTRING}" '.[] | select(.name | contains($PATTERN)) | "\(.id), \(.name)"')
fi
echo "${HRLIST}"
echo "----------------------------------------------------------------------------"
Expand All @@ -141,25 +141,29 @@ 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}"
# GET our HR json
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
Expand All @@ -168,6 +172,8 @@ updateHRData() {
fi
done

IFS=$OLDIFS

echo "----------------------------------------------------------------------------"
echo "Completed HR updates"
echo "----------------------------------------------------------------------------"
Expand Down