Files
KNELInventory/scripts/glpi-agent-coverage.sh
ic-builder edd755c492
ci / audit (pull_request) Successful in 18s
[inventory] fix SC2015 for CI shellcheck 0.9
Unambiguous if-form for the two-condition guard. CI (node:20-bookworm,
Debian shellcheck 0.9) flags the A && B || C pattern where the koalaman
stable docker path passed. No behavior change.

CI evidence: https://git.knownelement.com/KNEL/inventory/actions/runs/118227
Ticket: https://projects.knownelement.com/issues/784
2026-09-06 09:25:04 -05:00

37 lines
1.7 KiB
Bash
Executable File

#!/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"