Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b894ab870b | ||
|
|
edd755c492 |
Executable
+36
@@ -0,0 +1,36 @@
|
|||||||
|
#!/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"
|
||||||
@@ -81,7 +81,9 @@ while IFS=$'\t' read -r fa pa fb pb; do
|
|||||||
[ -n "$fa" ] || continue
|
[ -n "$fa" ] || continue
|
||||||
pa=${pa:-unknown}; pb=${pb:-unknown}
|
pa=${pa:-unknown}; pb=${pb:-unknown}
|
||||||
ida=$(ensure_port "$fa" "$pa"); idb=$(ensure_port "$fb" "$pb")
|
ida=$(ensure_port "$fa" "$pa"); idb=$(ensure_port "$fb" "$pb")
|
||||||
[ -n "$ida" ] && [ -n "$idb" ] || { echo "SKIP link $fa/$pa <-> $fb/$pb (missing CI/port)" >&2; continue; }
|
if [ -z "$ida" ] || [ -z "$idb" ]; then
|
||||||
|
echo "SKIP link $fa/$pa <-> $fb/$pb (missing CI/port)" >&2; continue
|
||||||
|
fi
|
||||||
lo=$(( ida < idb ? ida : idb )); hi=$(( ida < idb ? idb : ida ))
|
lo=$(( ida < idb ? ida : idb )); hi=$(( ida < idb ? idb : ida ))
|
||||||
if api GET "search/NetworkPort_NetworkPort?criteria%5B0%5D%5Bfield%5D=13&criteria%5B0%5D%5Bsearchtype%5D=equals&criteria%5B0%5D%5Bvalue%5D=$lo" \
|
if api GET "search/NetworkPort_NetworkPort?criteria%5B0%5D%5Bfield%5D=13&criteria%5B0%5D%5Bsearchtype%5D=equals&criteria%5B0%5D%5Bvalue%5D=$lo" \
|
||||||
| grep -q "\"$hi\""; then conn_dup=$((conn_dup+1)); continue; fi
|
| grep -q "\"$hi\""; then conn_dup=$((conn_dup+1)); continue; fi
|
||||||
|
|||||||
Reference in New Issue
Block a user