我正在使用带有ITSM的OTRS票务系统5。我可以通过通用接口(REST)选择,更新,删除票证,附件。
我的问题:Rest接口只给我Ticket数据,而不是链接的Configuration项(例如pc)。我知道,我必须为LinkObject添加一个连接器,它为我提供了Ticket中的所有链接项。我的Perl编程技巧不足以自己构建它,有人能告诉我如何获得功能性解决方案吗?经过两周的搜索和尝试,我希望有人在过去解决了这个问题:)
这是我的perl模块产生内部服务器错误(LinkAdd示例来自How to Link / Get Config Item to an Ticket through Webservice (SOAP or REST) in OTRS):
在/Custom/Kernel/GenericInterface/Operation/LinkObject/LinkList.pm
下# --
# Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm - GenericInterface LinkAdd operation backend
# Copyright (C) 2016 ArtyCo (Artjoms Petrovs), http://artjoms.lv/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::GenericInterface::Operation::LinkObject::LinkList;
use strict;
use warnings;
use Kernel::GenericInterface::Operation::Common;
use Kernel::System::LinkObject;
use Kernel::System::VariableCheck qw(IsStringWithData IsHashRefWithData);
=head1 NAME
Kernel::GenericInterface::Operation::LinkObject::LinkList - GenericInterface Link List Operation backend
=head1 SYNOPSIS
=head1 PUBLIC INTERFACE
=over 4
=cut
=item new()
usually, you want to create an instance of this
by using Kernel::GenericInterface::Operation->new();
=cut
sub new {
my ( $Type, %Param ) = @_;
my $Self = {};
bless( $Self, $Type );
# check needed objects
for my $Needed (
qw( DebuggerObject WebserviceID )
)
{
if ( !$Param{$Needed} ) {
return {
Success => 0,
ErrorMessage => "Got no $Needed!"
};
}
$Self->{$Needed} = $Param{$Needed};
}
# create additional objects
$Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} );
$Self->{LinkObject}
= $Kernel::OM->Get('Kernel::System::LinkObject');
return $Self;
}
=item Run()
Create a new link.
my $Result = $OperationObject->Run(
Data => {
SourceObject => 'Ticket',
SourceKey => '321',
TargetObject => 'Ticket',
TargetKey => '12345',
Type => 'ParentChild',
State => 'Valid',
UserID => 1,
},
);
$Result = {
Success => 1, # 0 or 1
ErrorMessage => '', # In case of an error
Data => {
Result => 1, # 0 or 1
},
};
=cut
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
if ( !IsHashRefWithData( $Param{Data} ) ) {
return $Self->{CommonObject}->ReturnError(
ErrorCode => 'LinkList.MissingParameter',
ErrorMessage => "LinkList: The request is empty!",
);
}
my $LinkID = $Self->{LinkObject}->LinkList(
%Param,
);
if ( !$LinkID ) {
return $Self->{CommonObject}->ReturnError(
ErrorCode => 'LinkList.AuthFail',
ErrorMessage => "LinkList: Authorization failing!",
);
}
return {
Success => 1,
Data => {
Result => $LinkID,
},
};
}
1;
=back
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<http://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.
=cut
答案 0 :(得分:0)
您的问题仍然有效吗? 如果是,请注意提供的链接: How to Link / Get Config Item to an Ticket through Webservice (SOAP or REST) in OTRS我对perl模块的评论。 至少,LinkObject实现的方法很少:
my $LinkList = $LinkObject->LinkList(
Object => 'Ticket',
Key => '321',
Object2 => 'FAQ', # (optional)
State => 'Valid',
Type => 'ParentChild', # (optional)
Direction => 'Target', # (optional) default Both (Source|Target|Both)
UserID => 1,
);
my $LinkList = $LinkObject->LinkListWithData(
Object => 'Ticket',
Key => '321',
Object2 => 'FAQ', # (optional)
State => 'Valid',
Type => 'ParentChild', # (optional)
Direction => 'Target', # (optional) default Both (Source|Target|Both)
UserID => 1,
ObjectParameters => { # (optional) backend specific flags
Ticket => {
IgnoreLinkedTicketStateTypes => 0|1,
},
},
);
另外两个只返回钥匙。 我使用LinkListWithData,因为它返回有关已连接CI的完整信息。
另外,我不得不说创建$ Self-&gt; {LinkObject}有一些麻烦 尝试使用而不是
# create additional objects
$Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} );
$Self->{LinkObject} = $Kernel::OM->Get('Kernel::System::LinkObject');
这一个
local $Kernel::OM = Kernel::System::ObjectManager->new( %{$Self} );
$Self->{LinkObject} = $Kernel::OM->Get('Kernel::System::LinkObject');
这可能会有所帮助。 当你调用LinkList方法时,你把%Param,但你的字段放在Map(或HashMap,dunno正好在perl中)$ Param {Data},所以试着用
my $Links = $Self->{LinkObject}->LinkListWithData(
'Object' => $Param{Data}{Object},
'Key' => $Param{Data}{Key},
'Type' => $Param{Data}{Type},
'Object2' => $Param{Data}{Object2},
'State' => $Param{Data}{State},
'UserID' => $Param{Data}{UserID},
);
另外,不要犹豫是否像使用Dumper的fileappender一样进行粗鲁的调试输出(make shure,otrs用户可以创建文件并写入它):
my $outfile = '/opt/otrs/var/log/otrs.log';
my $timestamp = localtime(time);
open(my $file_handle, '>>', $outfile) or die "Can't write to file '$outfile' [$!]\n";
print $file_handle "$timestamp\n";
print $file_handle "=====Custom LinkList started=====\n";
my $tempobjectdump = Dumper $Self;
print $file_handle $tempobjectdump;
while ( my ($key, $value) = each($Param{Data}) ) {
print $file_handle "$key => $value\n";
}