blob: 45b11cdecc130fba65d9be75cbd326cb5ba8e9a5 [file] [log] [blame]
Gary Wu9d321652019-06-18 09:41:02 -07001#!/bin/bash
2
3if [ "$#" -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
8fi
9
10
11set -v
12set -x
13set -e
14
15K8S_IP=$1
16CL_NAME=$2
17
18CONSUL_ENDPOINT=http://$K8S_IP:30270/v1/kv
19TMP_DIR=$(mktemp -d)
20pushd $TMP_DIR
21
22curl -s $CONSUL_ENDPOINT/dcae-tca-analytics | jq -r '.[0].Value' | base64 --decode | jq '.' > dcae-tca-analytics.json
23jq -r '.app_preferences.tca_policy' < dcae-tca-analytics.json | jq '.' > tca_policy.json
24jq '.metricsPerEventName |= map( select(.eventName == "vFirewallBroadcastPackets").thresholds[].closedLoopControlName="'$CL_NAME'" )' < tca_policy.json > tca_policy_new.json
25diff tca_policy.json tca_policy_new.json || true
26
27jq --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
29jq -c '.' < dcae-tca-analytics-new.json | curl -X PUT -d @- $CONSUL_ENDPOINT/dcae-tca-analytics
30
31popd