[rt-users] RTAT Import?

Matthew Keller kellermg at potsdam.edu
Tue Apr 29 16:15:03 EDT 2008


The '$at->_Set' calls you're making scare me. Is there a reason you're
setting them iteratively instead of within the Create call?

On Tue, 2008-04-29 at 20:08 +0000, Jean-Sebastien Morisset wrote:
> Matthew,
> 
> Thanks for your code. This was an exellent starting point. Since I
> already have a bunch of assets, I tried to incorporate some code to
> update assets. I'm not sure what I'm doing wrong though... Here's the
> result:
> 
> # /opt/rt3/bin/import-assets.sh /tmp/js.csv
> gessolx1:
>         Loaded gessolx1 as asset #85.
>         CustomField-10 could not be set to STI.
>         CustomField-11 could not be set to Montreal QC CA.
>         CustomField-12 could not be set to SUN.
>         CustomField-14 could not be set to X4200.
>         That is already the current value
>         CustomField-16 could not be set to SUN Solaris 10.
> uasolx1:
>         Loaded uasolx1 as asset #86.
>         CustomField-10 could not be set to STI.
>         CustomField-11 could not be set to Montreal QC CA.
>         CustomField-12 could not be set to SUN.
>         CustomField-14 could not be set to 0.
>         CustomField-15 could not be set to 0.
>         CustomField-16 could not be set to 0.
> 
> And the code:
> 
> #!/usr/bin/perl
> 
> use lib qw(/opt/rt3/local/lib /opt/rt3/lib);
> 
> use RT;
> use RTx::AssetTracker::Asset;
> RT::LoadConfig();
> RT::Init();
> 
> use strict;
> 
> if (! $ARGV[0] || $ARGV[0] =~ /^--?h/) {
>     print "Syntax: $0 {csvfile}\n";
>     exit 0;
> }
> 
> open(CSV, "< $ARGV[0]") or die "$!\n";
> 
> my $at = RTx::AssetTracker::Asset->new(RT->SystemUser);
> my $line;
> 
> while (<CSV>) {
>         my ($el, $id, $t, $msg);
>         chomp; $line++; next if ($line == 1);
>         s/^"//; s/"$//;
>         my @csv = split(/"?,"?/);
>         my @fn = (
>                 'Name',
>                 'Status',
>                 'Type',
>                 'Description',
>                 'CustomField-10',       # Client
>                 'CustomField-11',       # Location
>                 'CustomField-12',       # Manufacturer
>                 'CustomField-14',       # Model
>                 'CustomField-15',       # Serial Number
>                 'CustomField-16',       # OS Name
>         );
> 
>         print $csv[0], ":\n";
>         if ($id = $at->Load($csv[0])) {
>                 print "\tLoaded $csv[0] as asset #$id.\n";
>         } else {
>                 ($id, $t, $msg) = $at->Create (
>                         Name => $csv[0],
>                         Status => $csv[1],
>                         Type => $csv[2],
>                         Description => $csv[3],
>                 );
>                 print "\t$msg\n";
>         }
> 
>         for my $k (@fn) {
>                 if ($k =~ /^CustomField/) {
>                         ($id, $msg) = $at->_Set (
>                                 Field => $k,
>                                 Value => $csv[$el],
>                                 UpdateAsset => 1,
>                                 TransactionData => undef,
>                         );
>                         print "\t$msg\n";
>                 }
>                 $el++;
>         }
> 
> }
> 
> Any ideas on what I could be doing wrong?
> 
> js.
> 
> On Tue, Apr 29, 2008 at 11:26:41AM -0400, Matthew Keller wrote:
> > The script below takes a tab-delimited file of format:
> > 
> > AssetTag Make Model Serial Building Room MACAddress
> > 
> > And populated a bunch of CFs. Salt to taste.
> > 
> > 
> > 
> > On Tue, 2008-04-29 at 14:01 +0000, Jean-Sebastien Morisset wrote:
> >> Has anyone developed a script or something to import an inventory into
> >> AT (from a csv file, for example)?
> >> 
> >> js.
> > 
> > 
> > #!/usr/bin/perl
> > 
> > 
> > use lib qw(/opt/rt3/local/lib /opt/rt3/lib);
> > 
> > use RT;
> > use RTx::AssetTracker::Asset;
> > RT::LoadConfig();
> > RT::Init();
> > 
> > use strict;
> > 
> > 
> > #### MAIN ########################
> > 
> > 
> >         my $BFILE="/opt/rt3/wslist";
> > 
> > 
> >         open(BF,"<$BFILE") or die "$!\n";
> > 
> >         my $ass = RTx::AssetTracker::Asset->new(RT->SystemUser);
> > 
> >         while(<BF>) {
> >                 # 12478 Gateway E4100   0032459740      KEL-HL  219
> > 00:0C:F1:D5:49:2E
> >                 chomp;
> >                 my @lineparts=split(/\t/);
> >                 my $sysname=$lineparts[4];
> >                 $sysname =~ s/\W.*$//; # Strip from non-word to eol
> >                 $sysname .= $lineparts[5] . "-" . $lineparts[0];
> > 
> >                 my ($id, undef, undef) = $ass->Create(Type =>
> > 'Workstations', 
> >                                                         Name =>
> > "$sysname",
> >                                                         Status =>
> > 'production',
> >                                                         'CustomField-7'
> > => "$lineparts[0]", # Decal
> >                                                         'CustomField-3'
> > => "$lineparts[1]", # Make
> >                                                         'CustomField-4'
> > => "$lineparts[2]", # Model
> >                                                         'CustomField-8'
> > => "$lineparts[3]", # Serial
> >                                                         'CustomField-59'
> > => "$lineparts[4]", # Building
> >                                                         'CustomField-60'
> > => "$lineparts[5]", # Room
> >                                                         'CustomField-62'
> > => "$lineparts[6]", # MAC address
> >                                                         );
> >                 print "$sysname created with id $id\n";
> >         }
> > 
> > 
> 




More information about the rt-users mailing list