Last active
August 29, 2015 14:05
-
-
Save mabe-at/854f562155c5301a7331 to your computer and use it in GitHub Desktop.
OTRS Generic Agent salearn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# use ../ as lib location | |
use File::Basename; | |
use FindBin qw($RealBin); | |
use lib dirname($RealBin); | |
use lib dirname($RealBin)."/Kernel/cpan-lib"; | |
use strict; | |
# to get it readable for the webserver user and writable for otrs | |
# group (just in case) | |
umask 002; | |
use Kernel::Config; | |
use Kernel::System::Time; | |
use Kernel::System::DB; | |
use Kernel::System::Log; | |
use Kernel::System::Main; | |
use Kernel::System::Ticket; | |
use Kernel::System::Ticket::Article; | |
my %CommonObject = (); | |
$CommonObject{ConfigObject} = Kernel::Config->new(); | |
$CommonObject{LogObject} = Kernel::System::Log->new( | |
LogPrefix => 'OTRS-SA', | |
%CommonObject, | |
); | |
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject); | |
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject); | |
my $SpamDir = dirname($RealBin)."/spam"; | |
eval { | |
if (!-d $SpamDir) { | |
die $SpamDir." does not exist!"; | |
} | |
# create needed objects | |
$CommonObject{DBObject} = Kernel::System::DB->new( | |
%CommonObject | |
); | |
$CommonObject{TicketObject} = Kernel::System::Ticket->new( | |
%CommonObject | |
); | |
my $TNR=$ARGV[0]; | |
my $TID=$ARGV[1]; | |
# get Articles | |
my @AIDs = $CommonObject{TicketObject}->ArticleIndex( | |
TicketID => $TID, | |
); | |
my $AID = $AIDs[0]; | |
my $PlainText = $CommonObject{TicketObject}->ArticlePlain( | |
ArticleID => $AID, | |
); | |
open(F, ">>".$SpamDir."/$AID"); | |
print F $PlainText; | |
close(F); | |
$CommonObject{LogObject}->Log( | |
Priority => 'notice', | |
Message => "Spam learned for Ticket $TNR, saved as $AID", | |
); | |
}; | |
if ($@) { | |
# log error message | |
$CommonObject{LogObject}->Log( | |
Priority => 'error', | |
Message => $@, | |
); | |
exit 75; | |
} | |
exit (0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment