From edd755c492b310259b136c849f6b7031cae17c25 Mon Sep 17 00:00:00 2001 From: ic-builder Date: Sun, 6 Sep 2026 09:25:04 -0500 Subject: [PATCH] [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 --- scripts/glpi-agent-coverage.sh | 36 ++++++++++++++++++++++ scripts/populate-netequip-from-librenms.sh | 4 ++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 scripts/glpi-agent-coverage.sh diff --git a/scripts/glpi-agent-coverage.sh b/scripts/glpi-agent-coverage.sh new file mode 100755 index 0000000..f891dee --- /dev/null +++ b/scripts/glpi-agent-coverage.sh @@ -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" diff --git a/scripts/populate-netequip-from-librenms.sh b/scripts/populate-netequip-from-librenms.sh index 80bbf78..e8236a9 100755 --- a/scripts/populate-netequip-from-librenms.sh +++ b/scripts/populate-netequip-from-librenms.sh @@ -81,7 +81,9 @@ while IFS=$'\t' read -r fa pa fb pb; do [ -n "$fa" ] || continue pa=${pa:-unknown}; pb=${pb:-unknown} 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 )) 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