Skip to content
Browse files

Add script to import hosts with DNS and DHCP reservations from CSV file

  • Loading branch information
cvicente committed Feb 21, 2018
1 parent 3b43dae commit 592bd87c56d059fc191ed3a89c91fb4d3fbe474f
Showing with 31 additions and 0 deletions.
  1. +31 −0 import/
@@ -0,0 +1,31 @@
# Import hosts from a CSV file
# Each host is a 4-tuple: (name, zone, IP, MAC)
# which will create DNS records and DHCP reservations in Netdot.
# Note: The subnet(s) to which the IPs belong must be DHCP enabled
use lib "/usr/local/netdot/lib";
use Netdot::Model;
use strict;

my $file = $ARGV[0] or die "Need input file\n";
open(FILE, $file) or die "Cannot open $file: $!\n";

while (<FILE>){
next if /^#|^\s/;
my($name, $zone, $ip, $mac) = split(',', $_);

my $rr;
eval {
$rr = RR->add_host(name=>$name, zone=>$zone,
address=>$ip, ethernet=>$mac);
if (my $e = $@){
printf("Problem importing %s, %s, %s, %s: $e\n",
$name, $zone, $ip, $mac);
printf("Added %s with MAC %s\n", $rr->get_label, $mac);

0 comments on commit 592bd87

Please sign in to comment.
You can’t perform that action at this time.