Add host refresh

This commit is contained in:
2025-09-04 17:10:56 +01:00
parent b5d849d029
commit 5f137a957e
2 changed files with 87 additions and 0 deletions

57
rsc_host_refresh.sh Executable file
View File

@@ -0,0 +1,57 @@
#!/bin/bash
#
# Example RSC API call script
# v0.1 - James Pattinson - September 2025
#
# Perfoms a host refresh in RSC
#
# usage: rsc_host_refresh.sh <targethost>
#
# Options:
# <targethost> : Host to perform refresh job
usage() { echo "Usage: $0 <host>" 1>&2; exit 1; }
if [[ -z "$1" ]]; then
usage
fi
MYDIR="$(dirname "$(realpath "$0")")"
source $MYDIR/oracle_funcs.sh
source $MYDIR/rsc_ops.sh
RBK_HOST=$1
rsc_get_host_id
echo "Host ID: $targetHostId"
gql_refreshHost='mutation RefreshHost($input: RefreshHostInput!) {
refreshHost(input: $input) {
output {
hostSummary {
name
operatingSystemType
status
}
agentId
}
}
}'
variables="{
\"input\": {
\"id\": \"$targetHostId\"
}
}"
gqlQuery="$(echo $gql_refreshHost)"
gqlVars="$(echo $variables)"
echo "Refreshing host $RBK_HOST (ID: $targetHostId)"
rsc_gql_query
echo "Response:"
cat /tmp/rbkresponse.$$ | jq

View File

@@ -112,6 +112,36 @@ EOF
} }
rsc_get_host_id() {
gql_list_targets='query PhysicalHosts($hostRoot: HostRoot!, $filter: [Filter!]) {
physicalHosts(hostRoot: $hostRoot, filter: $filter) {
nodes {
id
name
}
}
}'
variables="{\"hostRoot\":\"LINUX_HOST_ROOT\",\"first\":50,\"filter\":[{\"field\":\"NAME_EXACT_MATCH\",\"texts\":[\"$RBK_HOST\"]},{\"field\":\"IS_RELIC\",\"texts\":[\"false\"]},{\"field\":\"IS_REPLICATED\",\"texts\":[\"false\"]},{\"field\":\"IS_KUPR_HOST\",\"texts\":[\"false\"]}],\"sortBy\":\"NAME\",\"sortOrder\":\"ASC\",\"childFilter\":[{\"field\":\"IS_GHOST\",\"texts\":[\"false\"]},{\"field\":\"IS_RELIC\",\"texts\":[\"false\"]}]}"
gqlQuery="$(echo $gql_list_targets)"
gqlVars="$(echo $variables)"
rsc_gql_query
# Get all matching host IDs (portable, no mapfile)
host_ids=$(cat /tmp/rbkresponse.$$ | jq -r '.data.physicalHosts.nodes[] | .id')
host_count=$(echo "$host_ids" | grep -c .)
if [[ $host_count -ne 1 ]]; then
echo "ERROR: Multiple hosts found for '$1':"
cat /tmp/rbkresponse.$$ | jq -r '.data.physicalHosts.nodes[] | "\(.name) \(.id)"'
exit_with_error
fi
# Set the first match (or empty if none)
targetHostId=$(echo "$host_ids" | head -n 1)
#cat /tmp/rbkresponse.$$ | jq -r
}
rsc_find_database () { rsc_find_database () {
# if cluster_uuid is not set, get it # if cluster_uuid is not set, get it