Basically what I did is that I exported the 3 tables I had to use:
mysql librenms -u librenms -pXXXX -B -e “SELECT device_id,sysName FROM devices;” > devices_aug12
mysql librenms -u librenms -pXXXX -B -e “SELECT port_id,device_id,ifName FROM ports;” > ports_aug12
mysql librenms -u librenms -pXXXX -B -e “SELECT local_device_id,local_port_id,remote_hostname,remote_port FROM links;” > links_aug12
did some columns reordering and added some “,” between them all:
cat ports_aug12 | awk ‘{print $1","$2","$3","}’ > ports_aug12.csv
cat links_aug12 | awk ‘{print $1","$2","$3","$4","}’ > links_aug12.csv
cat ports_aug12.csv | awk ‘{print “,”$0}’ > ports_aug12.csv_
cat ports_aug12.csv | replace “,” " " | awk ‘{print “,”$2","$1","$3","}’ > ports_aug12.csv_
had some issues there…
and then did 2 bash scripts:
1: for replacing the device ID by the device hostname and outputting to a file:
#!/bin/sh
for HOSTID in cat devices_aug12.csv | cut -d"," -f2
do
HOSTNAME=cat devices_aug12.csv | grep ^\,$HOSTID\, | cut -d"," -f3
HOSTRST=cat links_aug12.csv | grep ^\,$HOSTID\, | replace ",$HOSTID," ",$HOSTNAME,"
echo “$HOSTRST” >> LINKS2
done
2:took the file outputted from script 1 and replace the portID by the port name and redirected the output to a final file including it all:
#!/bin/sh
for PORTID in cat LINKS2 | cut -d"," -f3
do
PORTNAME=cat ports_aug12.csv | grep \,$PORTID, | grep -v ^\,$PORTID, | cut -d"," -f4
HOSTRSTR=cat LINKS2 | grep \,$PORTID\, | grep -v ^\,$PORTID, | replace ",$PORTID," ",$PORTNAME,"
echo $HOSTRSTR >> LINKS_LAST &
done
####################
Not much of a programmer but had to do it with bash
Hope someone will find it helpfull one day