14 Replies Latest reply on May 21, 2013 6:39 AM by Eric Brinkley

    Asset Management- Add to Asset Group via API

    W Schroed Level 1

      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-


      # 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, ,, ,, ,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";



              #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";



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


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

                      print "Found IP $variable\n";





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