Retrieve Devices with a Specific Collection Status
Scenario Overview
This guide shows network administrators how to use the Collection Status Query API to monitor devices and check their collection status, such as completed
, failed
, or in progress
.
Prerequisites
Before running this example:
- Ensure that you have obtained a valid JWT token. Refer to the 'Getting Started' section.
- Confirm that the
cnc-api-common.sh
script is correctly configured and that the required input and output directories exist. - The input file (collection_status.json) contains a valid collection status (completed, failed, or in progress).
Retrieve Devices with a Specific Collection Status
Update the collection_status.json
file with the desired collection status (completed, failed, or in progress) and run the retrieve_devices_with_collection_status.sh
script from the example directory.
cd cnc-inventory-api-examples;./retrieve_devices_with_collection_status.sh
Script Details
#!/bin/bash
. ./cnc-api-common.sh
retrieve_devices_with_collection_status() {
# Assuming the CNC JWT has already been obtained prior to invoking this method by executing the get-cnc-jwt.sh script
# Read from JWT file and export it as AUTH_TOKEN_HDR
export_jwt
# STEP 1 : Create a collection-status payload with specifying the desired status (`completed`, `failed`, or `inprogress`)in the input json file: (CNC_API_INPUT)
# STEP 2 : Retrieve devices with collection status provided in the payload
# STEP 2.1 : Copy the output device list in CNC_API_OUTPUT file
CNC_API_URL=$CNC_INVENTORY_API_CTX/query
CNC_API_INPUT="@$PRJ/input/collection_status.json"
CNC_API_OUTPUT="$PRJ/output/devices_with_collection_status.json"
http_post $CNC_API_URL $CNC_API_INPUT $CNC_API_OUTPUT
}
retrieve_devices_with_collection_status