#!/usr/bin/env bash # glpi-agent-coverage.sh — agent coverage audit [#705/#801, fundamentals directive] # # Lists every Computer CI in GLPI with its agent-fed status: # agent_fed = is_dynamic 1 (glpi-agent inventory has landed) # last_inventory = freshness from GLPI # Cross-reference list: pass a newline-separated list of known fleet hosts # (defaults to seed CSV names) to spot fleet machines with NO GLPI CI at all. # # Env: mglpi.env. Exit 0 always (report). set -uo pipefail [ -f "$HOME/.creds/mglpi.env" ] && . "$HOME/.creds/mglpi.env" : "${MGLPI_URL:?}"; : "${MGLPI_APP_TOKEN:?}"; : "${MGLPI_USER_TOKEN:?}" S=$(curl -sk --max-time 20 -H "Content-Type: application/json" \ -H "App-Token: ${MGLPI_APP_TOKEN}" -H "Authorization: user_token ${MGLPI_USER_TOKEN}" \ "${MGLPI_URL}/initSession" | jq -r '.session_token // empty') [ -n "$S" ] || { echo "FAIL: GLPI session init" >&2; exit 1; } curl -sk --max-time 60 -G -H "App-Token: ${MGLPI_APP_TOKEN}" -H "Session-Token: $S" \ "${MGLPI_URL}/search/Computer" \ --data-urlencode 'is_deleted=0' \ --data-urlencode 'forcedisplay[]=2' \ --data-urlencode 'forcedisplay[]=16' \ --data-urlencode 'forcedisplay[]=47' \ -o /tmp/glpi_cov.json curl -sk --max-time 15 -X DELETE -H "App-Token: ${MGLPI_APP_TOKEN}" \ -H "Session-Token: $S" "${MGLPI_URL}/killSession" -o /dev/null jq -r '.data[] | [.["2"], (.["16"] // "-"), (.["47"] // "-")] | @tsv' /tmp/glpi_cov.json \ | awk -F'\t' '{ fed = ($3 ~ /^[0-9]{4}-/) ? "agent-fed" : "NO-AGENT-DATA"; printf "%s\t%s\t%s\n", $1, fed, $3; }' | sort echo "---" echo "note: field 16 = last inventory update; anything not YYYY-MM-DD has no agent feed"