zuerst mal kurz die Vorgeschichte:
Unsere "echten" Customer_User authentifiziere ich gegen MS Active Directory (Forest mit einigen Subdomains).
Dazu kommen "unechte" Customer User, die sich niemals am OTRS anmelden werden, aber als betroffene User ausgewählt werden sollen.
Der Server:
W2K3 Server in einer VMware
OTRS::ITSM 1.2.1
Ich habe auf http://www.cape-it.de/ ein Script zum Import von Customer Usern aus csv Dateien entdeckt, das aber mit seltsamen MainModul Fehlern abgeschmiert ist. Daraufhin stieß ich auf ein original OTRS Script namens syncuser_csv2otrs.pl zum Anlegen von Agents aus einer csv Datei, was tadellos funktioniert.
Nun habe ich den Versuch unternommen, das funktionierende Agent- Anlegescript mit dem Fehler verursachenden Script zum Import von Customer Usern zusammenzuführen. Customer User aus einer csv Datei Anlegen funktioniert nun auch prima. Nur das Update bestehender Customer User haut nicht hin... Der Aufruf und die Meldung:
Code: Select all
D:\OTRS\Perl\bin>perl d:\otrs\otrs\scripts\test.pl -s d:\utest.csv
Updating customer user '244' with password '244'
ERROR: test.pl-72 Perl: 5.8.8 OS: MSWin32 Time: Thu Sep 11 11:40:47 2008
Message: Need User or CustomerID!
Traceback (5756):
Module: Kernel::System::CustomerUser::DB::CustomerUserDataGet (v1.67) Line: 4
13
Module: Kernel::System::CustomerUser::DB::CustomerUserUpdate (v1.67) Line: 69
6
Module: Kernel::System::CustomerUser::CustomerUserUpdate (v1.44) Line: 349
Module: d:\otrs\otrs\scripts\test.pl (unknown version) Line: 99
Use of uninitialized value in concatenation (.) or string at d:/otrs/otrs/Kernel
/System/CustomerUser/DB.pm line 740, <IN> line 1.
Code: Select all
244;244@bla.de;244;244;XXX GmbH Kirchheim;1621234567;DoPi 1234 // SiPi 2345;Typ 1e39 // SiPu 3456
Anbei mal mein kläglicher Versuch:
Code: Select all
#!/usr/bin/perl -w
# --
# syncuser_csv2otrs.pl - sync csv user list or otrs
# Copyright (C) 2001-2008 xxx, http://otrs.org/
# --
# $Id: syncuser_csv2otrs.pl,v 1.10 2008/06/09 14:52:11 tr Exp $
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# --
# config options / csv file - column 0-...
my %Fields = ();
$Fields{login} = 0;
$Fields{email} = 1;
$Fields{customer_id} = 2;
$Fields{pw} = 3;
$Fields{salutation} = 4;
$Fields{firstname} = 5;
$Fields{lastname} = 6;
$Fields{comment} = 7;
# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin) . "/Kernel/cpan-lib";
use strict;
use warnings;
use Getopt::Std;
use Kernel::Config;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::Time;
use Kernel::System::DB;
#use Kernel::System::User;
use Kernel::System::CustomerUser;
# common objects
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new();
$CommonObject{LogObject} = Kernel::System::Log->new(
LogPrefix => 'test.pl',
%CommonObject
);
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
#$CommonObject{UserObject} = Kernel::System::User->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
$CommonObject{CustomerUserObject} = Kernel::System::CustomerUser->new(%CommonObject);
# get options
my %Opts = ();
getopt( 's', \%Opts );
my $End = "\n";
if ( !$Opts{s} ) {
die "Need -s <CSV_FILE>\n";
}
my $Lang = $CommonObject{ConfigObject}->Get('DefaultLanguage') || 'de';
# read csv file
open (IN, "< $Opts{'s'}") || die "Can't read $Opts{'s'}: $!";
while( <IN>) {
my $LineStrg = $_;
$LineStrg =~ s/\"//g;
my @Line = split(/;/, $LineStrg);
# check if user extsis
#my %UserData = $CommonObject{UserObject}->GetUserData( User => $Line[ $Fields{UserLogin} ] );
my %CustomerUserData = $CommonObject{CustomerUserObject}->CustomerUserDataGet(User => $Line[$Fields{login}]);
# if there is no pw in the csv list, gererate one
if( !$Line[$Fields{pw}]) {
$Line[$Fields{pw}] = $CommonObject{CustomerUserObject}->GenerateRandomPassword();
}
# update user
if( %CustomerUserData) {
print "Updating customer user '$Line[$Fields{login}]' with password '$Line[$Fields{pw}]'\n";
$CommonObject{CustomerUserObject}->CustomerUserUpdate(
UserSalutation => $Line[$Fields{salutation}] || '',
UserFirstname => $Line[$Fields{firstname}],
UserLastname => $Line[$Fields{lastname}],
UserLogin => $Line[$Fields{login}],
UserPassword => $Line[$Fields{pw}],
UserEmail => $Line[$Fields{email}],
CustomerID => $Line[$Fields{customer_id}] || '',
UserCustomerID => $Line[$Fields{customer_id}] || '',
UserComment => $Line[$Fields{comment}] || '',
ValidID => 1,
UserID => 1,
);
}
# add user
else {
print "Add customer_user '$Line[$Fields{login}]' ($Line[$Fields{firstname}],$Line[$Fields{lastname}]) with password '$Line[$Fields{pw}]'\n";
$CustomerUserData{UserID} = $CommonObject{CustomerUserObject}->CustomerUserAdd(
UserSalutation => $Line[$Fields{salutation}] || '',
UserFirstname => $Line[$Fields{firstname}],
UserLastname => $Line[$Fields{lastname}],
UserLogin => $Line[$Fields{login}],
UserPassword => $Line[$Fields{pw}],
UserEmail => $Line[$Fields{email}],
CustomerID => $Line[$Fields{customer_id}] || '',
UserCustomerID => $Line[$Fields{customer_id}] || '',
UserComment => $Line[$Fields{comment}] || '',
ValidID => 1,
UserID => 1,
);
}
}
close( IN);
Hilfe bitte

mfg
Michael