Files
claudetools/.claude/scripts/check-ksteen-smartbadge.sh
Mike Swanson 324c3b94a4 feat(birth-biologic): KSTEEN SmartBadge daily watch + remediation scripts
Corrected the 2026-05-28 SmartBadge fix on KSTEENBB2025: the older Datto
Workplace Desktop v8 had been left in place (diverged from the fleet, which
runs Datto Workplace v10.53.4 / Workplace2). Removed v8, installed v10,
aligned the SmartBadge _CC add-in + CLSID to the EVO-X1 reference, and cleared
Kristin's stuck per-user LoadBehavior=2.

- ksteen-smartbadge-verify.ps1: PASS/FAIL verdict vs fleet reference
- ksteen-smartbadge-fix.ps1: machine + per-user remediation
- check-ksteen-smartbadge.sh: daily runner (RMM -> verdict -> #bot-alerts,
  coord message to Mike on drift); driven by a 7-day scheduled task on GURU-5070
- wiki: agents table, dual-Workplace SmartBadge known issue + fleet standard,
  2026-05-28/29 history

Syncro #32339. Coord todo 4a5b09b3 (watch expires 2026-06-05).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-29 08:40:54 -07:00

63 lines
3.5 KiB
Bash

#!/usr/bin/env bash
# Daily verification that KSTEENBB2025 (Birth Biologic) Datto SmartBadge config
# still matches the EVO-X1 fleet reference. Posts a #bot-alerts heartbeat each run;
# on drift also sends a coord message to Mike. Intended to run once/day for ~1 week
# via the "ClaudeTools - KSTEEN SmartBadge Daily" scheduled task on GURU-5070.
set -uo pipefail
REPO_ROOT="${CLAUDETOOLS_ROOT:-/d/claudetools}"
[ -d "$REPO_ROOT" ] || REPO_ROOT="$(git -C "$(dirname "$0")" rev-parse --show-toplevel 2>/dev/null)"
VAULT="$REPO_ROOT/.claude/scripts/vault.sh"
RMM="http://172.16.3.30:3001"
COORD="http://172.16.3.30:8001/api/coord"
KSTEEN="ee3c6aea-e9cc-4d2f-9e79-a38dd0eb129e"
VERIFY_PS="$REPO_ROOT/.claude/scripts/ksteen-smartbadge-verify.ps1"
LOG="$REPO_ROOT/.claude/logs/ksteen-smartbadge.log"
mkdir -p "$(dirname "$LOG")"
ts() { date '+%Y-%m-%d %H:%M:%S %Z'; }
alert() { bash "$REPO_ROOT/.claude/scripts/post-bot-alert.sh" "$1" >/dev/null 2>&1; }
fail_exit() { echo "$(ts) [ERROR] $1" >> "$LOG"; alert "[SMARTBADGE-WATCH] ERROR on KSTEENBB2025 check: $1"; exit 1; }
EMAIL=$(bash "$VAULT" get-field infrastructure/gururmm-server.sops.yaml credentials.gururmm-api.admin-email 2>/dev/null)
PASS=$(bash "$VAULT" get-field infrastructure/gururmm-server.sops.yaml credentials.gururmm-api.admin-password 2>/dev/null)
[ -z "$EMAIL" ] && fail_exit "could not read RMM creds from vault"
TOKEN=$(curl -s -X POST "$RMM/api/auth/login" -H "Content-Type: application/json" \
--data-binary "{\"email\":\"$EMAIL\",\"password\":\"$PASS\"}" | jq -r '.token // empty')
[ -z "$TOKEN" ] && fail_exit "RMM login failed"
# Is the agent connected? If offline, note and exit cleanly (will catch it tomorrow).
ONLINE=$(curl -s "$RMM/api/agents" -H "Authorization: Bearer $TOKEN" | jq -r --arg id "$KSTEEN" '.[] | select(.id==$id) | .status')
if [ "$ONLINE" != "online" ]; then
echo "$(ts) [SKIP] agent offline ($ONLINE)" >> "$LOG"
alert "[SMARTBADGE-WATCH] KSTEENBB2025 offline - SmartBadge check skipped, will retry next run"
exit 0
fi
PAYLOAD=$(jq -n --rawfile cmd "$VERIFY_PS" '{command_type:"powershell", command:$cmd, timeout_seconds:60}')
CID=$(curl -s -X POST "$RMM/api/agents/$KSTEEN/command" -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d "$PAYLOAD" | jq -r '.command_id // empty')
[ -z "$CID" ] && fail_exit "command dispatch failed"
for i in $(seq 1 20); do
ST=$(curl -s "$RMM/api/commands/$CID" -H "Authorization: Bearer $TOKEN" | jq -r '.status')
case "$ST" in completed|failed|cancelled|interrupted) break;; esac
sleep 4
done
OUT=$(curl -s "$RMM/api/commands/$CID" -H "Authorization: Bearer $TOKEN" | jq -r '.stdout')
RESULT=$(printf '%s' "$OUT" | grep -m1 'RESULT:')
if printf '%s' "$RESULT" | grep -q 'RESULT: PASS'; then
echo "$(ts) PASS" >> "$LOG"
alert "[SMARTBADGE-WATCH] KSTEENBB2025 PASS - Datto Workplace v10 + SmartBadge _CC add-in aligned"
else
REASON=$(printf '%s' "$RESULT" | sed 's/^RESULT: //')
[ -z "$REASON" ] && REASON="no RESULT line returned: ${OUT:0:200}"
echo "$(ts) FAIL | $REASON" >> "$LOG"
alert "[SMARTBADGE-WATCH] *** DRIFT *** KSTEENBB2025 FAIL | $REASON"
curl -s -X POST "$COORD/messages" -H "Content-Type: application/json" --data-binary @- <<JSON >/dev/null 2>&1
{"from_session":"GURU-5070/smartbadge-watch","to_user":"mike","subject":"KSTEENBB2025 SmartBadge drift detected","body":"Daily watch found drift on Kristin Steen's machine: $REASON. Re-run the SmartBadge remediation (.claude/scripts ksteen-smartbadge-verify.ps1 + datto-fix.ps1).","priority":"high"}
JSON
fi