#!/bin/bash source /etc/noc.conf IPS=`sql "select ipaddr from ipInterface where ipaddr != '0.0.0.0' and ipaddr != iphostname;" | sort -u` echo "Checking `echo "$IPS" | wc -l` reverse DNS names that OpenNMS has stored in it's database." echo "" for ip in $IPS ; do DNSNAME=`nslookup $ip | grep 'name = ' | head -1 | sed -e 's/^.*name = //' -e 's/\.$//' | tr '[:upper:]' '[:lower:]'` DBNAME=`sql "select iphostname from ipInterface where ipaddr = '$ip' LIMIT 1;" | sed -e 's/ //g' | tr '[:upper:]' '[:lower:]'` if [ "$DNSNAME" != "$DBNAME" ]; then echo "Mismatch Found" echo " IP: $ip" echo " DB Name: $DBNAME" echo "DNS Name: $DNSNAME" if [ "$1" != "-n" ]; then echo -n "Remove name from DB so OpenNMS will refresh on next scan? [y/n] > " if [ "$1" = "-y" ]; then echo "y" INPUT="y" else read INPUT fi if [ "$INPUT" = y ]; then echo "Removing $DBNAME from Database where IP is $ip." sql "update ipInterface set iphostname=ipaddr where ipaddr = '$ip';" fi fi echo "" fi done echo "Done."