Enable Granular Inventory (GI) for a Specific Device
Scenario Overview
This guide demonstrates how to enable Granular Inventory (GI) for a specific device on the CNC server. Enabling GI allows for detailed inventory collection and monitoring of device configurations, making it useful for troubleshooting or managing device-specific operations. 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, the required jq utility is installed for JSON processing, and the necessary input/output directories exist.
Enable Granular Inventory (GI) for a Given Device
Update the input_device_address
array in the enable_granular_inventory.sh
script with the IP address(es) of the devices for which you want to enable Granular Inventory (GI). Then, run the script from the example directory as shown below.
cd cnc-inventory-api-examples;./enable_granular_inventory.sh
Script Details
#!/bin/bash
. ./cnc-api-common.sh
enable_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 : ENABLE 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 enable 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/enable_granular_inventory_input.json"
echo "{\"nodeuuids\": [$node_uuids], \"enable\": \"true\"}" > $CNC_API_INPUT
CNC_API_OUTPUT="$PRJ/output/enable_granular_inventory_output.json"
http_put $CNC_API_URL @$CNC_API_INPUT $CNC_API_OUTPUT
}
enable_granular_inventory