[rt-users] bulk load into Asset Tracker possible?

Matthew Keller kellermg at potsdam.edu
Wed Jun 24 13:02:31 EDT 2009


On Wed, 2009-06-24 at 12:00 -0400, charlie derr wrote:
> Greetings,
>      Before we dive into the RT-APIs at a low level to try to figure out how to load our several hundred rows of excel data semi 
> automatically into our RT Asset Tracker instance, I just thought it worth asking if anyone else has solved this problem (or 
> started to?) and might be willing to share code or ideas on how best to proceed.  We've got a bunch of custom fields (and 
> obviously some basic fields) that we'll want to populate.  And it may be that we have a small enough data set that doing it 
> manually through the web interface ends up being a more efficient use of time and resources, but it sure seems worth asking.

Below is a script I wrote that bulk adds data from tab-separated data
into AT, using custom fields we have designed. 

#!/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>) {
		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