Disable Granular Inventory (GI) for a Specific Device
Scenario Overview
This guide demonstrates how to disable Granular Inventory (GI) for a specific device on the CNC server. Disabling GI may be necessary to optimize server performance, reduce unnecessary data collection, or troubleshoot device-specific issues. This guide is intended for network administrators managing device configurations on the CNC server."
Prerequisites
Before running this example, ensure you have obtained an access token by following the instructions in the 'Getting Started' section. Additionally, confirm that the cnc-api-common.sh script is properly configured and that the necessary input/output directories exist.
Disable Granular Inventory (GI) for a given device
Update the input_device_address
array in the disable_granular_inventory.sh
script with the IP address(es) of the devices for which you want to disable Granular Inventory (GI). Then, run the script from the example directory as shown below.
cd cnc-inventory-api-examples;./disable_granular_inventory.sh
Script Details
#!/bin/bash
. ./cnc-api-common.sh
disable_granular_inventory() {
# Assuming the CNC JWT has already been obtained by running the get-cnc-jwt.sh script.
# Read from JWT file and export it as AUTH_TOKEN_HDR
export_jwt
# STEP 1 : Retrieve all the nodeuuids on the server
# STEP 2 : Retrieve nodeuuid for the device IP provided by the user below
# STEP 3 : Disable granular inventory for the provided devices
NODEUUID_OUTPUT="$PRJ/output/nodeuuid.json"
get_nodeuuids $NODEUUID_OUTPUT
# Replace the input_device_address array with the IP address(es) of the devices for which you want to disable Granular Inventory (GI). For multiple devices, provide the IPs as an array, where each IP is enclosed in double quotes and separated by spaces.
input_device_address=("0.0.0.0" "255.255.255.255")
node_uuids=""
for ip in "${input_device_address[@]}"; do
# Use jq to find the corresponding nodeUUId
node_uuid=$(jq -r --arg address "$ip" '.[] | select(.deviceAddress == $address) | .nodeUUId' $NODEUUID_OUTPUT)
# Check if a nodeUUId was found
if [ -n "$node_uuid" ]; then
node_uuids+="\"$node_uuid\","
echo "The nodeUUId for device address $input_device_address is $node_uuid."
else
echo "No nodeUUId found for device address $input_device_address."
fi
done
node_uuids=${node_uuids%,}
CNC_API_URL=$CNC_INVENTORY_API_CTX/granularinventory
CNC_API_INPUT="$PRJ/input/disable_granular_inventory_input.json"
echo "{\"nodeuuids\": [$node_uuids], \"enable\": \"false\"}" > $CNC_API_INPUT
CNC_API_OUTPUT="$PRJ/output/disable_granular_inventory_output.json"
http_put $CNC_API_URL @$CNC_API_INPUT $CNC_API_OUTPUT
}
disable_granular_inventory