Retrieve collection details of a device

Scenario Overview

This guide demonstrates how to retrieve collection details for a specific device on the CNC server. It is intended for network administrators or operations teams who need to monitor a device's last collection time, GI Sync status, and overall collection status for troubleshooting or operational insights.

Prerequisites

Before running this example, ensure you have obtained an access token by following the instructions in the Getting Started section. Additionally, ensure that the cnc-api-common.sh script is correctly configured and that the necessary input and output directories exist

Retrieve collection details of given device

Update the input_device_address in the script with the IP address of the device you want to query. Then, run the retrieve_device_collection_details.sh script from the example directory.

cd cnc-inventory-api-examples;./retrieve_device_collection_details.sh

Script Details

#!/bin/bash
. ./cnc-api-common.sh

retrieve_device_collection_details() {
    # Assume 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 of devices registered on the server.
    # STEP 2 : retrieve nodeuuid for the device IP provided by the user below
    # STEP 3 : retrieve collection details for nodeuuid and store the output in CNC_API_OUTPUT file

    NODEUUID_OUTPUT="$PRJ/output/nodeuuid.json"
    get_nodeuuids $NODEUUID_OUTPUT

    # Replace this with the IP address of the device you want to query. Ensure this address matches the device registered on the CNC server.
    input_device_address="0.0.0.0"  

    # Use jq to find the corresponding nodeUUId
    node_uuid=$(jq -r --arg address "$input_device_address" '.[] | select(.deviceAddress == $address) | .nodeUUId' $NODEUUID_OUTPUT)

    # Check if the nodeUUId was found
    if [ -n "$node_uuid" ]; then
      echo "The nodeUUId for device address $input_device_address is $node_uuid."
    else
      echo "No nodeUUId found for device address $input_device_address."
    fi

    CNC_API_URL=$CNC_INVENTORY_API_CTX/collectiondetails/query
    CNC_API_INPUT="{\"nodeuuid\":\"$node_uuid\"}"
    CNC_API_OUTPUT="$PRJ/output/collection_details.json"
    http_post $CNC_API_URL $CNC_API_INPUT $CNC_API_OUTPUT
}
retrieve_device_collection_details