- Add hooks declarations to 9 plugins missing them in marketplace.json - Change .mcp.json to use relative paths (portable across users) - Fix pr-review hook schema to use standard nested hooks structure - Fix token exposure in cmdb-assistant startup-check.sh (use curl -K) - Update version to 5.4.1 in marketplace.json, README.md - Fix CANONICAL-PATHS.md version (was incorrectly showing 5.5.0) All 12 plugins now have hooks properly registered. All validations pass. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
84 lines
2.4 KiB
Bash
Executable File
84 lines
2.4 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
|
|
|
|
# Helper function to make authenticated API calls
|
|
# Token passed via curl config to avoid exposure in process listings
|
|
netbox_curl() {
|
|
local url="$1"
|
|
curl -s -K - <<EOF 2>/dev/null
|
|
-H "Authorization: Token ${NETBOX_API_TOKEN}"
|
|
-H "Accept: application/json"
|
|
url = "${url}"
|
|
EOF
|
|
}
|
|
|
|
# Quick API connectivity test (5s timeout)
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -m 5 -K - <<EOF 2>/dev/null || echo "000"
|
|
-H "Authorization: Token ${NETBOX_API_TOKEN}"
|
|
-H "Accept: application/json"
|
|
url = "${NETBOX_API_URL}/"
|
|
EOF
|
|
)
|
|
|
|
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 -K - <<EOF 2>/dev/null || echo '{"count":0}'
|
|
-H "Authorization: Token ${NETBOX_API_TOKEN}"
|
|
-H "Accept: application/json"
|
|
url = "${NETBOX_API_URL}/virtualization/virtual-machines/?site__isnull=true&limit=1"
|
|
EOF
|
|
)
|
|
|
|
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 -K - <<EOF 2>/dev/null || echo '{"count":0}'
|
|
-H "Authorization: Token ${NETBOX_API_TOKEN}"
|
|
-H "Accept: application/json"
|
|
url = "${NETBOX_API_URL}/dcim/devices/?platform__isnull=true&limit=1"
|
|
EOF
|
|
)
|
|
|
|
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
|