Add a Device to an Addigy Policy Using a Custom Script

Introduction: In this blog post, we’ll demonstrate how to create a script that automates the process of adding a device to an Addigy policy. The script will check if the logged-in computer has an Addigy AgentID and, if so, add that AgentID to a predefined policy.

Here’s the updated and improved script:

#!/bin/bash

# Replace XXXX with your actual policy ID
policy_id="XXXX"

# Function to extract the agent ID from the Addigy configuration file
get_agent_id() {
awk '$1 == "agentid" {print $2}' /Library/Addigy/config/.adg_agent_config
}

# Function to add the device to a predefined Addigy policy using Addigy API
add_device_to_policy() {
local agent_id=$1
local policy_id=$2

curl --request "POST" "https://prod.addigy.com/api/policies/devices" \
--header 'client-id: YOUR_CLIENT_ID' \
--header 'client-secret: YOUR_CLIENT_SECRET' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode "policy_id=$policy_id" \
--data-urlencode "agent_id=$agent_id"
}

# Main script execution
agent_id=$(get_agent_id)
if [ -n "$agent_id" ]; then
add_device_to_policy "$agent_id" "$policy_id"
else
echo "Agent ID not found. Please ensure Addigy Agent is installed and configured properly."
fi

Be sure to replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your actual Addigy API credentials. This script is compatible with macOS systems running the Addigy agent.

With this improved script, you can easily automate adding devices to Addigy policies, saving time and effort in managing your device fleet.

Leave a Reply

Your email address will not be published. Required fields are marked *