#!/usr/bin/env bash # lldp-topology.sh — pull LLDP neighbor links from LibreNMS [#808 phase 2] # # Reads the LibreNMS links table (LLDP/CDP discovery) and emits # hostnameA, portA, hostnameB, portB rows. Run ON tsys-librenms as root # (MariaDB local auth) or via: lldp-topology.sh --fetch # # Output feeds GLPI NetworkEquipment + port-connection creation # (phase 2 of the GLPI x LibreNMS cross-feed). See librenms-glpi-drift.sh # for the device-level report (phase 1). set -uo pipefail LNMS_HOST="${LNMS_HOST:-100.86.204.77}" QUERY="SELECT d1.hostname, p1.ifName, d2.hostname, p2.ifName FROM links l JOIN devices d1 ON l.local_device_id=d1.device_id JOIN devices d2 ON l.remote_device_id=d2.device_id LEFT JOIN ports p1 ON l.local_port_id=p1.port_id LEFT JOIN ports p2 ON l.remote_port_id=p2.port_id;" if [ "${1:-}" = "--fetch" ]; then ssh -o BatchMode=yes "root@${LNMS_HOST}" "mysql -N librenms -e \"$QUERY\"" 2>/dev/null else # local mode: run on tsys-librenms itself mysql -N librenms -e "$QUERY" 2>/dev/null fi