Skip navigation
12877 Views 14 Replies Latest reply: May 21, 2013 6:39 AM by Eric Brinkley RSS
W Schroed Level 1 6 posts since
Jan 20, 2011
Currently Being Moderated

Jan 22, 2011 9:00 AM

Asset Management- Add to Asset Group via API

Is there a way to automatically place an IP based asset into an Asset Group when the asset is created? I am using the addassetip.pl script with a wrapper script that creates the asset.csv and addassetip.conf files. I would really like to find a way to asset group these IP assets as I add them.

 

Wrapper is below-

#!/usr/bin/perl

# Script to call addassetip.pl iterively to add more than one ip asset at a time

 

 

open(IF, '< test');

#open(IF, '< All_CIDR_Block27.csv');

#ADC, ,ADC-6500-PROD-D01, ,Pub_Clearing_66.54.251.192_27, ,66.54.251.192, ,66.54.251.223, ,27, ,VLAN12,

 

 

while (<IF>) {

chomp $_;

($datacenter, $switch, $name, $baseip, $endip, $cidr, $vlan) = split(",", $_);

 

 

open (CONF, ">addassetip.conf");

open (IP, ">asset.csv");

 

print "Working on $name\n";

 

#Write out asset.csv for each iterative call to the API

print IP "$baseip/$cidr\n";

close IP;

#Write out addassetip.conf for each iterative call to the API

 

print CONF "username THEUSERNAME\n";

 

print CONF "password THEPASSWORD\n";

 

print CONF "targetipfile  /THEPATH/asset.csv\n";

 

print CONF "tracking_method ip\n";

print CONF "location $datacenter\n";

print CONF "comment \"$switch, Name: $name, VlanNum: $vlan, DataCenter $datacenter\"\n";

print "comment $switch, Name: $name, VlanNum: $vlan, DataCenter $datacenter\n";

print CONF "function $name";

close CONF;

sleep 1;

`/THEPATH/addassetip.pl /THEPATH/addassetip.conf`;

 

sleep 2;

}

 

I have also added some code to the default API scritp to accept assets with a cidr mask as well as a range or single IP. The whole block plus my add is below.

for ($i=0;$i<scalar @input;$i++){

        my $j=$i+1;

        if ( $input[$i] =~ /((\d+\.\d+\.\d+\.\d+)\-(\d+\.\d+\.\d+\.\d+))/)

        {

                ($variable) = ( $input[$i] =~ /((\d+\.\d+\.\d+\.\d+)\-(\d+\.\d+\.\d+\.\d+))/);

                print "Found IP $variable\n";

                push(@newarray,$variable);

        }

        #matches cidr mask at end

          elsif ( $input[$i] =~ /(\d+\.\d+\.\d+\.\d+\/\d+)/) {

                ($variable) = ( $input[$i] =~ /(\d+\.\d+\.\d+\.\d+\/\d+)/);

                print "Found IP $variable\n";

                push(@newarray,$variable);

        }

        elsif ( $input[$i] =~ /(\d+\.\d+\.\d+\.\d+)/)

        {

                ($variable) = ( $input[$i] =~ /(\d+\.\d+\.\d+\.\d+)/);

                print "Found IP $variable\n";

                push(@newarray,$variable);

        }

        else

        {

                print "IP pattern not found in the line $j of the input file\n";

        }

More Like This

  • Retrieving data ...

Bookmarked By (1)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 6 points