Gary Wu | 9d32165 | 2019-06-18 09:41:02 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | if [ "$#" -ne 2 ]; then |
| 4 | echo This script updates the controll loop name for vFWCL in consul |
| 5 | echo "$0 <k8s_host_ip> <new_control_loop_name>" |
| 6 | echo |
| 7 | exit 1 |
| 8 | fi |
| 9 | |
| 10 | |
| 11 | set -v |
| 12 | set -x |
| 13 | set -e |
| 14 | |
| 15 | K8S_IP=$1 |
| 16 | CL_NAME=$2 |
| 17 | |
| 18 | CONSUL_ENDPOINT=http://$K8S_IP:30270/v1/kv |
| 19 | TMP_DIR=$(mktemp -d) |
| 20 | pushd $TMP_DIR |
| 21 | |
| 22 | curl -s $CONSUL_ENDPOINT/dcae-tca-analytics | jq -r '.[0].Value' | base64 --decode | jq '.' > dcae-tca-analytics.json |
| 23 | jq -r '.app_preferences.tca_policy' < dcae-tca-analytics.json | jq '.' > tca_policy.json |
| 24 | jq '.metricsPerEventName |= map( select(.eventName == "vFirewallBroadcastPackets").thresholds[].closedLoopControlName="'$CL_NAME'" )' < tca_policy.json > tca_policy_new.json |
| 25 | diff tca_policy.json tca_policy_new.json || true |
| 26 | |
| 27 | jq --argfile tca_policy_new tca_policy_new.json '.app_preferences.tca_policy |= ($tca_policy_new | tostring)' < dcae-tca-analytics.json > dcae-tca-analytics-new.json |
| 28 | |
| 29 | jq -c '.' < dcae-tca-analytics-new.json | curl -X PUT -d @- $CONSUL_ENDPOINT/dcae-tca-analytics |
| 30 | |
| 31 | popd |