Mass-creation of RT user accounts

Hi,

Is there a quick way of creating, say, 100 user accounts in RT w/o entering them one by one via the web interface?

I guess I could flip the switch to allow each user to send an email to RT to auto-create the account. But I want to have a better control of the username, email address, password, rights, etc…

thanks

Pei

Is there a quick way of creating, say, 100 user accounts in RT w/o
entering them one by one via the web interface?

shell script around the command line client.
simple perl script around the API.

There may or may not be a bulk load wiki topic. I know I’ve sent a
pointer to a trivial bulk loader I wrote awhile ago.

seph

I’ve seen some people mentioned RT CLI and/or API, but I have not come across a documentation titled “RT CLI” or “RT API”. Could someone care to point the way?

thanks

Pei

I’ve seen some people mentioned RT CLI and/or API, but I have not
come across a documentation titled “RT CLI” or “RT API”. Could
someone care to point the way?

There’s at least some info on the wiki http://wiki.bestpractical.com/

seph

Hi,

Is there a quick way of creating, say, 100 user accounts in RT w/o entering them one by one via the web interface?

I didn’t test this at all. This is 10 minutes of cutting and
pasting with a few extra lines thrown in.

Keep passing stuff to CreateUser.

You can probably drop the $ErrorTo and $entity part (or populate them
accordingly as seen in <RT_BASE>/lib/RT/Interface/Email.pm for an
example) and just do:
CreateUser( “username”, “e-mail address”, “name” );

Or loop through a list appropriately.

     #!/usr/local/bin/perl -w
     use strict;
     use lib "/path/to/rt/libraries/";

     use RT::Interface::CLI  qw(CleanEnv
                              GetCurrentUser GetMessageContent loc);

     #Clean out all the nasties from the environment
     CleanEnv();

     #let's talk to RT'
     use RT;

     #Load RT's config file
     RT::LoadConfig();

     # Connect to the database. set up loggign
     RT::Init();

     #Load the systemuser
     my $NewUser = RT::User->new($RT::SystemUser);

     print loc('Hello!'); # Synonym of $CurrentUser->loc('Hello!');

{{{ Create User

sub CreateUser {
my ($Username, $Address, $Name, $ErrorsTo, $entity) = @_;
my $NewUser = RT::User->new($RT::SystemUser);

 my ($Val, $Message) = 
   $NewUser->Create(Name => ($Username || $Address),
                    EmailAddress => $Address,
                    RealName => $Name,
                    Password => undef,
                    Privileged => 0,
                    Comments => 'Autocreated on ticket submission'
                   );
 
 unless ($Val) {
     
     # Deal with the race condition of two account creations at once
     if ($Username) {
         $NewUser->LoadByName($Username);
     }
     
     unless ($NewUser->Id) {
         $NewUser->LoadByEmail($Address);
     }
     
     unless ($NewUser->Id) {  
         MailError( To => $ErrorsTo,
                    Subject => "User could not be created",
                    Explanation => "User creation failed in

mailgateway: $Message",
MIMEObj => $entity,
LogLevel => ‘crit’
);
}
}

 #Load the new user object
 my $CurrentUser = RT::CurrentUser->new();
 $CurrentUser->LoadByEmail($Address);

 unless ($CurrentUser->id) {
         $RT::Logger->warning("Couldn't load user '$Address'.". 

“giving up”);
MailError( To => $ErrorsTo,
Subject => “User could not be loaded”,
Explanation => “User ‘$Address’ could not
be loaded in the mail gateway”,
MIMEObj => $entity,
LogLevel => ‘crit’
);
} else {
my ($stat, $pass) = $CurrentUser->SetRandomPassword();
if ( $stat ) {
print "User: $CurrentUser->Name, " Password: ", $pass, “\n”;
} else {
print "Unable to set password for user ", $CurrentUser->Name, “\n”;
}

}

 return $CurrentUser;

}

}}}

Andy Harrison