[rt-users] RTAT Import?

Jean-Sebastien Morisset jsmoriss at mvlan.net
Tue Apr 29 17:01:56 EDT 2008


On Tue, Apr 29, 2008 at 04:32:43PM -0400, Matthew Keller wrote:
> Ah yes... The way I usually do things like that is by grabbing the asset
> CF info, ala: 
> 
> my $AssCFs=$AssObj->CustomFields();
> 
> and then setting the appropriate values ala:
> 
> while(my $AssCF = $AssCFs->Next()) {
> 	$AssCF->Value = whatever
> }
> 
> The above is pseudocode from memory, but is +/- 96% correct. :)

Hmmm... Here's what I get:

# /opt/rt3/bin/import-assets.sh /tmp/js.csv
gessolx1:
        Loaded gessolx1 as asset #85.
        Setting Client to STI
[Tue Apr 29 21:00:16 2008] [crit]: Can't modify non-lvalue subroutine
call at /opt/rt3/bin/import-assets.sh line 56, <CSV> line 2.
(/opt/rt3/lib/RT.pm:361)
Can't modify non-lvalue subroutine call at /opt/rt3/bin/import-assets.sh
line 56, <CSV> line 2.

And here's the code I'm using...

#!/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;

# customfield columns in csv file
my %cf_map = (
        'Client' => 4,
        'Location' => 5,
        'Manufacturer' => 6,
        'Model' => 7,
        'Serial Number' => 8,
        'OS Name' => 9,
);

while (<CSV>) {
        chomp; $line++;
        next if ($line == 1);   # Skip CSV Header
        s/^"//; s/"$//;
        my @csv = split(/"?,"?/);

        print $csv[0], ":\n";
        if (my $id = $at->Load($csv[0])) {
                print "\tLoaded $csv[0] as asset #$id.\n";
        } else {
                my ($id, $t, $msg) = $at->Create (
                        Name => $csv[0],
                        Status => $csv[1],
                        Type => $csv[2],
                        Description => $csv[3],
                );
                print "\t$msg\n";
        }

        my $atcf = $at->CustomFields();
        while (my $cf = $atcf->Next()) {
                # check to see if we have a column number for this customfield
                if (my $col = $cf_map{$cf->Name}) {
                        print "\tSetting ".$cf->Name." to ".$csv[$col]."\n";
                        $cf->Value = $csv[$col];
                }
        }
}

-- 
Jean-Sebastien Morisset, Sr. UNIX Administrator <jsmoriss at mvlan.net>



More information about the rt-users mailing list