Код: Выделить всё
#!/usr/bin/perl -w
# --
# bin/otrs.RandomTicketCreate.pl - генератор рандомных тикетов
# Copyright (C) 2013 Меркушов Виктор merkushov.victor@gmail.com
# --
# This program is free software;
# --
use strict;
use warnings;
use utf8;
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use vars qw($VERSION $Self);
$VERSION = qw($Revision: 1.0 $) [1];
use Getopt::Long;
use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Time;
use Kernel::System::DB;
use Kernel::System::Main;
use Kernel::System::User;
use Kernel::System::Ticket;
my %Opts = ();
GetOptions(
'filename|f=s' => \$Opts{f},
'count|c' => \$Opts{c},
'help|h' => \$Opts{h},
);
if ( $Opts{h} ) {
print "otrs.RandomTicketCreate.pl <Revision $VERSION> - генератор рандомных тикетов для системы OTRS\n";
print "Copyright (C) 2013 Меркушов Виктор merkushov.victor\@gmail.com\n";
print "usage: otrs.RandomTicketCreate.pl --filename <source_file> [--count <ticket_count>] \n";
exit 1;
}
unless ( $Opts{f} ) {
print "Unknown path to the data to test tickets.\n";
exit 1;
}
$Opts{c} ||= 10;
# create common objects
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new(%CommonObject);
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject} = Kernel::System::Log->new(
LogPrefix => 'OTRS-otrs.RandomTicketCreate',
%CommonObject,
);
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
$CommonObject{UserObject} = Kernel::System::User->new(%CommonObject);
$CommonObject{TicketObject} = Kernel::System::Ticket->new(%CommonObject);
my $Data = '';
if ( -f $Opts{f} ) {
open( my $Fh, '<', $Opts{f} ) || die "ERROR: $!";
binmode $Fh, ':utf8';
while ( <$Fh> ) {
$Data .= $_;
}
close ($Fh);
} else {
warn "Can't open file " . $Opts{f};
}
$Data =~ s/\n/ /g;
for my $Counter ( 1..$Opts{c} ) {
my ( $TicketID, $ArticleID );
if ( $Data =~ s/\w[^\.!?]{8,1000}.// ) {
$TicketID = $CommonObject{TicketObject}->TicketCreate(
Title => $&,
Queue => 'Raw',
Lock => 'unlock',
PriorityID => '3',
State => 'new',
CustomerID => '1',
CustomerUser => 'customer@example.com',
OwnerID => 1,
UserID => 1,
);
}
if ( $TicketID and $Data =~ s/\w[^\.!?]{8,1000}.// ) {
$ArticleID = $CommonObject{TicketObject}->ArticleCreate(
TicketID => $TicketID,
ArticleType => 'note-internal', # email-external|email-internal|phone|fax|...
SenderType => 'agent', # agent|system|customer
From => 'Some other Agent <email2@example.com>', # not required but useful
To => 'Some Customer A <customer-a@example.com>', # not required but useful
Subject => 'Title', # required
Body => $&, # required
Charset => 'UTF-8',
MimeType => 'text/plain',
HistoryType => 'WebRequestCustomer', # EmailCustomer|Move|AddNote|PriorityUpdate|WebRequestCustomer|...
HistoryComment => 'New Article!',
UserID => 1,
);
}
}
exit 1;