Send Netdot-users mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://osl.uoregon.edu/mailman/listinfo/netdot-users
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Netdot-users digest..."
Today's Topics:
1. Import ipblock information with comments ("info" field on
ipblock table) (Nico)
2. Re: Import ipblock information with comments ("info" field on
ipblock table) (Patrick Landry)
----------------------------------------------------------------------
Message: 1
Date: Mon, 4 Aug 2014 14:07:16 +0200
From: Nico <[email protected]>
Subject: [Netdot-users] Import ipblock information with comments
("info" field on ipblock table)
To: "[email protected]" <[email protected]>
Message-ID:
<CAKXQfmtUASZoZ32aAG7ET5LRVPKe0giza74QpqfEMkC=fwk...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hello,
I wish to import into Netdot a lot of IP information, but not only
with description but also the info field (shown as "comment" on the
web interface).
So far, i've modified the import/import_ip_bulk.pl file adding another
field wich will contain the info field, and it works.
But i don't know if there is an easy way to enter newline and ,
(comma) characters into this field, i've tried with \n and \, with no
luck :-/.
Modified import_ip_bulk.pl...
#!/usr/bin/perl
#
# Import a list of IP blocks and addresses from a CSV file
# (See sample input file ip_list.txt)
#
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($block, $status, $owner, $used_by, $description, $info) = split(',', $_);
my($address, $prefix) = split(/\//, $block);
die "Syntax error: Block must be in CIDR notation: $block\n"
unless ($address && $prefix);
die "Unrecognized status: $status\n"
unless ( $status =~ /^Dynamic|Static|Container|Reserved|Subnet$/ );
my ($ent1, $ent2);
if ($owner){
$ent1 = Entity->find_or_create({name=>$owner});
}
if ($used_by){
$ent2 = Entity->find_or_create({name=>$used_by});
}
if ( my $ip = Ipblock->search(address=>$address, prefix=>$prefix)->first ){
print "IP " . $ip->get_label . " exists. Updating.\n";
print $info
$ip->update({status => $status,
owner => $ent1,
used_by => $ent2,
description => $description,
info => $info,
});
}else{
my $newip;
eval {
print $info
$newip = Ipblock->insert({address => $address,
prefix => $prefix,
status => $status,
owner => $ent1,
used_by => $ent2,
description => $description,
info => $info,
no_update_tree => 1,
});
};
if ( my $e = $@ ){
die "ERROR: $e\n";
}else{
print "Inserted " . $newip->get_label. "\n";
}
}
}
Ipblock->build_tree(4);
Ipblock->build_tree(6);
And sample file with ip info (to import from):
192.168.1.1/32,Static,Network Services,Network Services,PC81278,PC de
Nico cuidado con este\nEs un poco ga??n, ya se sabe
192.158.1.2/32,Static,Network Services,Network Services,PC12983,otro
PC de Nico \nSigue siendo un ga??n\, ya sabe?s
Greetings, thanks
--
Nico
------------------------------
Message: 2
Date: Mon, 4 Aug 2014 07:35:57 -0500 (CDT)
From: Patrick Landry <[email protected]>
Subject: Re: [Netdot-users] Import ipblock information with comments
("info" field on ipblock table)
To: Nico <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
----- Original Message -----
> Hello,
> I wish to import into Netdot a lot of IP information, but not only
> with description but also the info field (shown as "comment" on the
> web interface).
> So far, i've modified the import/import_ip_bulk.pl file adding
> another
> field wich will contain the info field, and it works.
> But i don't know if there is an easy way to enter newline and ,
> (comma) characters into this field, i've tried with \n and \, with no
> luck :-/.
When I wrote my perl importer I was able to get line breaks in the info field
by embedding a carriage return character (ASCII 13, HEX 0D) in the literal
string.
$rrdata->{'info'} = $rrdata->{'info'} . '^MDEPT: '
The '^M' you see there should be a single character. Unfortunately that is not
returned to you when you subsequently fetch that field.
--
patrick
Patrick Landry
University of Louisiana at Lafayette
Director, University Computer Support Services
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://osl.uoregon.edu/pipermail/netdot-users/attachments/20140804/fb6fc60a/attachment-0001.html
------------------------------
_______________________________________________
Netdot-users mailing list
[email protected]
https://osl.uoregon.edu/mailman/listinfo/netdot-users
End of Netdot-users Digest, Vol 69, Issue 1
*******************************************