useful_scripts/check_vip_issue_db.sh
Arif Ali a90392cc89
Update + add scripts
* Added a simple check juju script
* fix cloud script for focal, similar to the bionic one
* initialise vault scipt
* Update get_password script to add innodb
* Added a new script for check_vip_issue_db.sh
2022-01-27 10:08:00 +00:00

61 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
juju_status=$(mktemp)
juju_db=$(mktemp)
juju status --format json > ${juju_status}
JUJU_DEV_FEATURE_FLAGS=developer-mode juju dump-db --format json > ${juju_db}
#juju_status=/tmp/tmp.IG9jLOKBET
#juju_db=/tmp/tmp.1kg5IV5I3k
hacluster_apps=$(cat ${juju_status} | jq ".applications | to_entries[] | select(.value[\"charm-name\"] == \"hacluster\") | .key" | sed s/\"//g)
for app in ${hacluster_apps}
do
super_app=$(cat ${juju_status} | jq .applications.\"${app}\".relations.ha[] | sed s/\"//g)
units=$(cat ${juju_status} | jq ".applications.\"${super_app}\".units | keys[]" | sed s/\"//g)
#vips=$(juju config ${super_app} vip)
vips=$(cat ${juju_db} | jq ".settings[] | select(._id | contains(\"a#${super_app}#cs\")) | .settings.vip")
bindings=$(cat ${juju_status} | jq ".applications.\"${super_app}\".\"endpoint-bindings\" | keys[]" | sed s/\"//g)
for r in ${bindings}
do
[[ ${r} != "cluster" ]] && [[ ${r} != "ha" ]] && continue
for unit in ${units}
do
#relation_ids=$(juju run --unit ${unit} "relation-ids ${r}" | awk -F\: '{print $2}' | sort)
relation_ids=$(cat ${juju_db} | jq ".relations[] | select(.endpoints[].relation.name == \"${r}\") | select(.endpoints[].applicationname == \"${super_app}\")| .id")
for i in ${relation_ids}
do
#relation_output=$(juju run --unit ${unit} "relation-get -r ${r}:${i} - ${unit}" | grep $vip)
if [[ ${r} == "cluster" ]] ; then
relation_output=$(cat ${juju_db} | jq ".settings[] | select(._id | contains(\"r#${i}#peer#${unit}\"))")
else
relation_output=$(cat ${juju_db} | jq ".settings[] | select(._id | contains(\"r#${i}#${unit}#req\"))")
fi
for vip in ${vips} ; do
#include_vip=$(echo $relation_output | grep ${vip})
include_vip=$(echo $relation_output | jq -rc ".settings | [.\"egress-subnets\", .\"private-address\", .\"ingress-address\"]" | grep ${vip})
if [[ -n "$relation_output" ]] && [[ -n "${include_vip}" ]] ; then
#echo $relation_output | jq -rc "._id"
echo ${unit}: {vip: ${vip}, binding: ${r}:${i}}
echo
echo $relation_output | jq -rc ".settings | [.\"egress-subnets\", .\"private-address\", .\"ingress-address\"]"
echo
fi
done
done
done
done
done