johnnyjava
Kilo Guru

I've written a quick bash script to create a csv file from the output of DiG:

#!/bin/bash

echo "hostname,TTL,record_class,record_type,ip_address" > dns.dump.raw;

dig mydomain.com axfr >> dns.dump.raw;

sed -i '/unused/d' dns.dump.raw;

sed -i 's/\t/,/g' dns.dump.raw;

sed -i 's/\ /,/g' dns.dump.raw;

sed -i 's/com\./com/g' dns.dump.raw;

sed -i 's/com\,$/com/g' dns.dump.raw;

sed -i '/SOA/d' dns.dump.raw;

sed -i '/NS/d' dns.dump.raw;

sed -i '/DiG/d' dns.dump.raw;

sed -i '/printcmd/d' dns.dump.raw;

sed -i '/^$/d' dns.dump.raw;

sed -i '/^;;/d' dns.dump.raw;

sed -i 's/,,/,/g' dns.dump.raw;

mv dns.dump.raw dns.dump.csv

exit 0

Surely the sed commands can be condensed down and ran together, but I wrote this as if chiseling a statue: whittling away at the dump output until I had valid csv.

Next I get this file into a location on a midserver, and then leverage the MID Server CSV Importer located here.

A transform map then loads this into the target table. I use cmdb_ci_dns_name and the previously unused ip_address field located there. My own scripts can then access this data. I am reading the other Sensors and Discovery Script Includes to determine when / if I want to also update cmdb_ip_address_dns_name, which references cmdb_ci_dns_name and cmdb_ci_ip_address. For now I'm leaving it alone.

Version history
Last update:
‎03-27-2015 11:34 AM
Updated by: