Retrieve Count of Devices

This guide is intended for network administrators or users responsible for inventory management on the CNC server. It explains how to retrieve the total count of devices registered on the CNC server, which is a foundational step in assessing the current inventory for network management or reporting.

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 the Count of Devices on the CNC Server

To retrieve the total count of devices registered on the CNC server, run the device_count.sh script from the example directory. Ensure the script's dependencies are properly set up before execution.

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

Script Details

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

device_count() {
    # Assuming the CNC JWT has already been obtained by executing the get-cnc-jwt.sh script
    # Read from JWT file and export it as AUTH_TOKEN_HDR
     export_jwt

    # STEP 1 : Retrieve the device count from the CNC server and store the output in the CNC_API_OUTPUT file.
    CNC_API_URL=$CNC_INVENTORY_API_CTX/count
    CNC_API_OUTPUT="$PRJ/output/device_count.json"
    http_get $CNC_API_URL $CNC_API_OUTPUT
}
device_count