From 5f137a957e88edd926ba920e7c5c28af409426af Mon Sep 17 00:00:00 2001 From: SupraJames Date: Thu, 4 Sep 2025 17:10:56 +0100 Subject: [PATCH] Add host refresh --- rsc_host_refresh.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++ rsc_ops.sh | 30 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100755 rsc_host_refresh.sh diff --git a/rsc_host_refresh.sh b/rsc_host_refresh.sh new file mode 100755 index 0000000..cc6750a --- /dev/null +++ b/rsc_host_refresh.sh @@ -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 +# +# Options: +# : Host to perform refresh job + +usage() { echo "Usage: $0 " 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 \ No newline at end of file diff --git a/rsc_ops.sh b/rsc_ops.sh index 4dcad03..fae77da 100755 --- a/rsc_ops.sh +++ b/rsc_ops.sh @@ -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 () { # if cluster_uuid is not set, get it