Skip to main content
warning

This script will modify user settings for all agents found in ACD queues across all domains on your PBX. Ensure you have proper backups and test in a non-production environment first. The script processes agents sequentially and may take several minutes for large deployments.

Vodia PBX Agent Configuration Script - (V68 to V69 upgrade)

Prerequisites

  • Root or sudo access - Script should be run with appropriate permissions
  • jq installed - Required for JSON parsing (script will check and prompt if missing)
  • PBX API access - Admin username and password with system-level permissions and API enabled
  • Network connectivity - HTTPS access to your PBX server

Installation Requirements

Install jq (if not already installed)

# Ubuntu/Debian
sudo apt-get update && sudo apt-get install jq

# CentOS/RHEL
sudo yum install jq

# or using dnf
sudo dnf install jq

Basic Usage

./pbx-agent-config.sh <pbx_url> <username> <password>

Examples

./pbx-agent-config.sh my-pbx.company.com admin mySecurePassword123

What the Script Does

  1. Domain Discovery: Retrieves all domains from your PBX server via /rest/system/usage
  2. Agent Collection: For each domain, gets all ACDs and collects unique agents from all_agents arrays
  3. Deduplication: Automatically removes duplicate agents across domains
  4. Bulk Configuration: Sets euse: "agent" i.e. changes extensiosn type to call queue agent for each unique agent via /rest/domain/{domain}/user_settings/{agent}

Here is the script

#!/bin/bash

# PBX Agent Configuration Script
# This script:
# 1. Gets all domains from PBX server
# 2. Gets all ACDs for each domain and collects unique agents
# 3. Sets euse="agent" for each unique agent

# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is required but not installed. Please install jq first."
echo "Ubuntu/Debian: sudo apt-get install jq"
echo "CentOS/RHEL: sudo yum install jq"
exit 1
fi

# Check if required parameters are provided
if [ $# -lt 3 ]; then
echo "Usage: $0 <pbx_url> <username> <password>"
echo "Example: $0 pbx69.vodia-teams.com admin 75EfS65NXcySQZ23"
exit 1
fi

PBX_URL="$1"
USERNAME="$2"
PASSWORD="$3"

# Base URL
BASE_URL="https://${PBX_URL}"

# Associative array to store unique domain:agent combinations
declare -A unique_agents

echo "=== PBX Agent Configuration Script ==="
echo "PBX URL: $BASE_URL"
echo "Username: $USERNAME"
echo ""

# Function to make API calls with error handling
make_api_call() {
local url="$1"
local method="${2:-GET}"
local data="$3"

if [ "$method" = "POST" ] && [ -n "$data" ]; then
curl --silent --location -g -u "${USERNAME}:${PASSWORD}" -k "$url" \
-H "Content-Type: application/json" \
-d "$data"
else
curl --silent --location -g -u "${USERNAME}:${PASSWORD}" -k "$url"
fi
}

echo "Step 1: Getting domains from PBX server..."

# Get all domains
domains_response=$(make_api_call "${BASE_URL}/rest/system/usage")

if [ $? -ne 0 ] || [ -z "$domains_response" ]; then
echo "Error: Failed to get domains from PBX server"
exit 1
fi

# Extract domain names using jq
domains=$(echo "$domains_response" | jq -r '.[].name' 2>/dev/null)

if [ $? -ne 0 ] || [ -z "$domains" ]; then
echo "Error: Failed to parse domains response"
echo "Response: $domains_response"
exit 1
fi

echo "Found domains:"
echo "$domains" | sed 's/^/ - /'
echo ""

echo "Step 2: Getting ACDs and collecting agents for each domain..."

# For each domain, get ACDs and collect agents
total_agents_found=0
for domain in $domains; do
echo "Processing domain: $domain"

acds_response=$(make_api_call "${BASE_URL}/rest/domain/${domain}/acds")

if [ $? -ne 0 ] || [ -z "$acds_response" ]; then
echo " Warning: Failed to get ACDs for domain $domain"
continue
fi

# Check if response is valid JSON and has data
if ! echo "$acds_response" | jq . >/dev/null 2>&1; then
echo " Warning: Invalid JSON response for domain $domain ACDs"
continue
fi

# Extract all_agents from each ACD
agents=$(echo "$acds_response" | jq -r '.[].all_agents[]?' 2>/dev/null | sort -u)

if [ -n "$agents" ]; then
echo " Found agents:"
agent_count=0
for agent in $agents; do
echo " - $agent"
# Store unique domain:agent combination
unique_agents["${domain}:${agent}"]="$domain"
((agent_count++))
((total_agents_found++))
done
echo " Total agents in $domain: $agent_count"
else
echo " No agents found in domain $domain"
fi
echo ""
done

echo "Total unique agents found across all domains: ${#unique_agents[@]}"

if [ ${#unique_agents[@]} -eq 0 ]; then
echo "No agents found to configure. Exiting."
exit 0
fi

echo ""
echo "Step 3: Setting euse='agent' for all unique agents..."
echo ""

# Process each unique agent
success_count=0
failure_count=0

for domain_agent in "${!unique_agents[@]}"; do
domain="${unique_agents[$domain_agent]}"
agent="${domain_agent#*:}" # Remove domain prefix to get just the agent number

echo "Configuring agent $agent in domain $domain..."

response=$(make_api_call "${BASE_URL}/rest/domain/${domain}/user_settings/${agent}" "POST" '{"euse": "agent"}')

if [ $? -eq 0 ]; then
echo " ✓ Successfully updated agent $agent in domain $domain"
((success_count++))
else
echo " ✗ Failed to update agent $agent in domain $domain"
((failure_count++))
fi
done

echo ""
echo "=== Summary ==="
echo "Total agents processed: ${#unique_agents[@]}"
echo "Successfully configured: $success_count"
echo "Failed to configure: $failure_count"

if [ $failure_count -eq 0 ]; then
echo "✓ All agents configured successfully!"
else
echo "⚠ Some agents failed to configure. Please check the output above."
exit 1
fi

Output Example

=== PBX Agent Configuration Script ===
PBX URL: https://pbx69.vodia-teams.com
Username: admin

Step 1: Getting domains from PBX server...
Found domains:
- lhgrxp.vodia-pbx.com
- sbc.vodia-teams.com
- cts.vodia.com

Step 2: Getting ACDs and collecting agents for each domain...
Processing domain: lhgrxp.vodia-pbx.com
Found agents:
- 504
- 508
Total agents in lhgrxp.vodia-pbx.com: 2

Processing domain: sbc.vodia-teams.com
Found agents:
- 504
- 508
Total agents in sbc.vodia-teams.com: 2

Total unique agents found across all domains: 4

Step 3: Setting euse='agent' for all unique agents...

Configuring agent 504 in domain lhgrxp.vodia-pbx.com...
✓ Successfully updated agent 504 in domain lhgrxp.vodia-pbx.com
Configuring agent 508 in domain lhgrxp.vodia-pbx.com...
✓ Successfully updated agent 508 in domain lhgrxp.vodia-pbx.com

=== Summary ===
Total agents processed: 4
Successfully configured: 4
Failed to configure: 0
✓ All agents configured successfully!