Skip to main content

Infrastructure Observability custom scripts

This page provides ready-to-run scripts that fix two common Infrastructure Observability (IO) collection-policy issues in Global View (GV): entity topology that doesn't form correctly, and custom property values that aren't available for filtering. Each script updates your IO collection policies through the Virtana Platform API. Use this page to find the script for your issue, prepare the required credentials, run the script, and confirm the result.

Prerequisites

Both scripts share the same setup: OAuth client credentials, the jq command-line tool, and three input values. Complete the steps in this section once before you run either script.

Generate OAuth client credentials

The scripts authenticate to the Virtana Platform API with an OAuth client ID and client secret. To generate these credentials, do the following:

  1. Log in to the Virtana Platform portal.

  2. Open the Settings and navigate to Integrations > Virtana Platform API.

  3. Click Generate OAuth Client Credentials.

  4. Assign the Administrator user group.

  5. Click Save.

  6. Copy the generated Client ID and Client Secret, and store them securely.

You can't retrieve the client secret again after you leave the page, so store it before you continue.

Install jq

Both scripts use jq, a command-line JSON processor, to read and modify policy data. Confirm that jq is installed on the system where you run the script. If jq isn't installed, install it with your operating system's package manager before you continue.

Provide the input parameters

Each script requires three input values that identify your GV host and authenticate the API requests. You pass these values to the script when you run it. The following table describes each input parameter:

Input parameter

Description

BASE_URL

The base URL of your Global View host — for example, https://vp-qa2.k8s.vi.local. The script appends API paths to this value.

CLIENT_ID

The OAuth client ID was generated in the Virtana Platform portal. The script uses it to request an access token.

CLIENT_SECRET

The OAuth client secret is paired with the client ID. Store it securely and don't share it.

Authenticate the scripts

Before updating any policy, each script requests an OAuth access token from the /authorization/oauth/token endpoint, then sends that token with every subsequent request. The following table describes the authentication parameters in the scripts:

Authentication parameter

Description

client_id

The OAuth client ID you provide as input. Identifies the API client to the token endpoint.

client_secret

The OAuth client secret you provide as input. Authenticates the API client.

grant_type

Set to client_credentials. Requests a token for machine-to-machine access, without an interactive login.

override_token

A query parameter on the token request is set to true. Tells the token endpoint to issue a new token in place of any existing one.

access_token

The bearer token returned by the token endpoint. The script reads it with jq and sends it in the Authorization: Bearer header of all later requests.

Make the script executable

Before you run a script for the first time, give it execute permission. Run the following command, replacing the filename with the script you want to run:

chmod +x io-collection-policies-update.bsh

Fix: custom property values aren't available for filtering in Global View

Use this fix when you can't filter, search, or report on IO custom properties in Global View. The script in this section adds all custom properties to every IO collection policy so that Global View can collect and use them.

Problem

Custom properties, both property names and their values, from IO entities aren't collected and synchronized to Global View. As a result, you can't use these custom properties to filter, search, or report in Global View.

Verify whether custom properties are collected

To confirm whether this issue applies to your environment, check the IO collection policy configuration. Send the following request, replacing {GV_URL} with your Global View host URL:

GET {GV_URL}/api/ipm/io_collection_policy

Review the policy for the affected entity type. Custom properties appear in the entityProperties array in the format custom.<custom_property_name>. If the entityProperties array doesn't include any custom. entries, then IO isn't collecting those custom properties, and you can't filter on their values in Global View.

Solution

To resolve the issue, run the io-colpolicy-for-customProps.bsh script. The script reads every IO collection policy and adds the custom.* wildcard to each entity's entityProperties list, which makes all available custom properties for that entity type eligible for collection.

#!/bin/bash

set -e

if [ $# -ne 3 ]; then
    echo "Usage: $0 <BASE_URL> <CLIENT_ID> <CLIENT_SECRET>"
    exit 1
fi

BASE_URL="$1"
CLIENT_ID="$2"
CLIENT_SECRET="$3"

echo "Obtaining OAuth token..."

TOKEN_RESPONSE=$(curl --silent --insecure \
    --location "${BASE_URL}/authorization/oauth/token?override_token=true" \
    --header "Accept: application/json" \
    --header "Content-Type: application/x-www-form-urlencoded" \
    --data-urlencode "client_id=${CLIENT_ID}" \
    --data-urlencode "client_secret=${CLIENT_SECRET}" \
    --data-urlencode "grant_type=client_credentials")

TOKEN=$(echo "$TOKEN_RESPONSE" | jq -r '.access_token')

if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
    echo "Failed to obtain token"
    echo "$TOKEN_RESPONSE"
    exit 1
fi

echo "Token acquired"

API_URL="${BASE_URL}/api/ipm/io_collection_policy/aa1"

echo "Fetching policies..."

curl --silent --insecure \
     --location "${API_URL}" \
     --header "Authorization: Bearer ${TOKEN}" \
     > policies.json

COUNT=$(jq 'length' policies.json)

echo "Found ${COUNT} policies"

for ((i=0; i<COUNT; i++))
do
    POLICY=$(jq ".[$i]" policies.json)

    POLICY_ID=$(echo "$POLICY" | jq -r '.id')
    POLICY_NAME=$(echo "$POLICY" | jq -r '.collectionPolicyName')

    echo ""
    echo "Processing Policy: ${POLICY_NAME}"

    UPDATED_POLICY=$(echo "$POLICY" | jq '
      .context |= map(
        if .collectionType == "ENTITY" then
           .entityProperties |= (
        if index("custom.*")
        then .
        else . + ["custom.*"]
        end
      )
    else
      .
    end
      )
    ')

    TMP_FILE="/tmp/${POLICY_ID}.json"
    echo "$UPDATED_POLICY" > "$TMP_FILE"

    curl --silent --show-error --insecure \
         --request PUT \
         --location "${API_URL}/${POLICY_ID}" \
         --header "Authorization: Bearer ${TOKEN}" \
         --header "Content-Type: application/json" \
         --data @"${TMP_FILE}" >/dev/null

    echo "Updated ${POLICY_NAME}"
done

echo ""
echo "Completed updating all policies"

The script changes the following fields in each collection policy. The table describes what each field controls:

Policy field

Description

context

The array of collection settings inside each policy. The script iterates over its members to find entity settings.

collectionType

The type of each context entry. The script updates only entries where this value is ENTITY.

entityProperties

The list of entity properties the policy collects. The script adds custom.* to this list if it isn't already present.

custom.*

A wildcard that matches all custom properties defined on an entity type. Adding it makes every custom property available for filtering, searching, and reporting in GV.

Run the script

After you complete the steps in Prerequisities, run the script from the directory that contains it. Provide the base URL, client ID, and client secret as arguments:

./io-colpolicy-for-customProps.bsh <BASE_URL> <CLIENT_ID> <CLIENT_SECRET>

The script prints the name of each policy as it processes it, and prints a confirmation message when all policies are updated.

Expected behavior after update

Updated collection policies take effect during the next scheduled collection cycle. By default, collection runs every 24 hours, unless you've configured a different schedule.

Collect custom properties immediately (optional)

To collect the custom property data without waiting for the next collection cycle, restart the IO Cloud Sync service from IO Service Management. When IO Cloud Sync starts again, it runs all collection policies and synchronizes entity data, including the newly added custom properties. Later collections continue on the configured schedule.

Note

Restarting IO Cloud Sync briefly interrupts the integration while the service restarts. Use this option only when a short interruption is acceptable.

Result

After the updated policies run, IO collects and synchronizes all configured custom properties from IO entities to GV. You can then use these custom properties to filter, search, and report in GV.