Add validation hooks, best practices skill, and new commands to enforce NetBox data quality standards: Hooks: - SessionStart: Test NetBox connectivity, report data quality issues - PreToolUse: Validate VM/device parameters before create/update New Commands: - /cmdb-audit: Data quality analysis (vms, devices, naming, roles) - /cmdb-register: Register current machine with running applications - /cmdb-sync: Sync machine state with NetBox, detect drift Best Practices Skill: - Dependency order (regions -> sites -> devices -> VMs) - Site/tenant/platform assignment requirements - Naming conventions enforcement - Role consolidation guidance Updated agent with validation requirements, dependency order checks, naming convention warnings, and duplicate prevention. Marketplace: 5.0.0 -> 5.1.0 Plugin: 1.0.0 -> 1.1.0 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
67 lines
2.1 KiB
Bash
Executable File
67 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# cmdb-assistant SessionStart hook
|
|
# Tests NetBox API connectivity and checks for data quality issues
|
|
# All output MUST have [cmdb-assistant] prefix
|
|
# Non-blocking: always exits 0
|
|
|
|
set -euo pipefail
|
|
|
|
PREFIX="[cmdb-assistant]"
|
|
|
|
# Load NetBox configuration
|
|
NETBOX_CONFIG="$HOME/.config/claude/netbox.env"
|
|
|
|
if [[ ! -f "$NETBOX_CONFIG" ]]; then
|
|
echo "$PREFIX NetBox not configured - run /cmdb-assistant:initial-setup"
|
|
exit 0
|
|
fi
|
|
|
|
# Source config
|
|
source "$NETBOX_CONFIG"
|
|
|
|
# Validate required variables
|
|
if [[ -z "${NETBOX_API_URL:-}" ]] || [[ -z "${NETBOX_API_TOKEN:-}" ]]; then
|
|
echo "$PREFIX Missing NETBOX_API_URL or NETBOX_API_TOKEN in config"
|
|
exit 0
|
|
fi
|
|
|
|
# Quick API connectivity test (5s timeout)
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -m 5 \
|
|
-H "Authorization: Token $NETBOX_API_TOKEN" \
|
|
-H "Accept: application/json" \
|
|
"${NETBOX_API_URL}/" 2>/dev/null || echo "000")
|
|
|
|
if [[ "$HTTP_CODE" == "000" ]]; then
|
|
echo "$PREFIX NetBox API unreachable (timeout/connection error)"
|
|
exit 0
|
|
elif [[ "$HTTP_CODE" != "200" ]]; then
|
|
echo "$PREFIX NetBox API returned HTTP $HTTP_CODE - check credentials"
|
|
exit 0
|
|
fi
|
|
|
|
# Check for VMs without site assignment (data quality)
|
|
VMS_RESPONSE=$(curl -s -m 5 \
|
|
-H "Authorization: Token $NETBOX_API_TOKEN" \
|
|
-H "Accept: application/json" \
|
|
"${NETBOX_API_URL}/virtualization/virtual-machines/?site__isnull=true&limit=1" 2>/dev/null || echo '{"count":0}')
|
|
|
|
VMS_NO_SITE=$(echo "$VMS_RESPONSE" | grep -o '"count":[0-9]*' | cut -d: -f2 || echo "0")
|
|
|
|
if [[ "$VMS_NO_SITE" -gt 0 ]]; then
|
|
echo "$PREFIX $VMS_NO_SITE VMs without site assignment - run /cmdb-audit for details"
|
|
fi
|
|
|
|
# Check for devices without platform
|
|
DEVICES_RESPONSE=$(curl -s -m 5 \
|
|
-H "Authorization: Token $NETBOX_API_TOKEN" \
|
|
-H "Accept: application/json" \
|
|
"${NETBOX_API_URL}/dcim/devices/?platform__isnull=true&limit=1" 2>/dev/null || echo '{"count":0}')
|
|
|
|
DEVICES_NO_PLATFORM=$(echo "$DEVICES_RESPONSE" | grep -o '"count":[0-9]*' | cut -d: -f2 || echo "0")
|
|
|
|
if [[ "$DEVICES_NO_PLATFORM" -gt 0 ]]; then
|
|
echo "$PREFIX $DEVICES_NO_PLATFORM devices without platform - consider updating"
|
|
fi
|
|
|
|
exit 0
|