Perl   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了perl – 如何通过OTRS中的Web服务(SOAP或REST)将配置项链接/获取到故障单大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道如何通过SOAP或REST Webservice获取和链接票证到配置项.
我已在管理控制台中导入此 Restfull Web service并使用此URL成功创建并获取票证信息
http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/1.

但问题是当我获得票证信息时链接的配置项信息不会出现.

我在google上做了很多搜索,发现票证可以通过OTRS GUI链接到Config Item,在AgentTicketzoom页面中会显示,我希望通过Web服务完成.
任何人都可以帮助我解决这个问题,或者建议一些关于如何创建Web服务以从票证中获取链接对象信息的文档.

更新#1

我成功地将web控制器添加到我现有的Ticket连接器.网址是http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorRest/LinkObject与POST Call.but我收到此错误

{“faultcode”:“Server”,“faultString”:“没有ConfigObject!”}

我也检查了初始参数

$VAR1 = {  'password' => '1234567','requestMethod' => 'POST','sourceKey' => '1','sourceObject' => 'Ticket','State' => 'valid','TargetKey' => '2','TargetObject' => 'ITSMConfigItem','Type' => 'ParentChild','UserID' => '1','UserLogin' => 'XXXXX.XXXX@XXXX.com'};

$VAR1 = {  'Errormessage' => 'Got no ConfigObject!','success' => 0};

解决方法

是的,票证可以通过GUI链接到configItem,它可以通过Web服务完成.

首先,您应该编写一个新的通用接口连接器操作,该操作将处理来自LinkObject类的方法LinkAdd(APIdoc)

然后通过新的XML文件创建并注册新操作,如下所示:

文件名:GenericInterfaceLinkObjectConnector.xml

<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="1.0" init="Application">
<ConfigItem Name="GenericInterface::Operation::Module###LinkObject::LinkAdd" required="0" Valid="1">
        <Description Translatable="1">GenericInterface module registration for the operation layer.</Description>
        <Group>GenericInterface</Group>
        <SubGroup>GenericInterface::Operation::ModuleRegistration</SubGroup>
        <SetTing>
            <Hash>
                <Item Key="Name">LinkAdd</Item>
                <Item Key="Controller">LinkObject</Item>
                <Item Key="ConfigDialog">AdminGenericInterfaceOperationDefault</Item>
            </Hash>
        </SetTing>
    </ConfigItem>
</otrs_config>

之后,您可以从OTRS GUI发布新的提供程序Webservice,其中使用了新创建的连接器.

确保您传递了方法所需的所有参数!

$True = $LinkObject->LinkAdd(
    sourceObject => 'Ticket',sourceKey    => '321',TargetObject => 'FAQ',TargetKey    => '5',Type         => 'ParentChild',State        => 'Valid',UserID       => 1,);

更新:

请阅读此Document以了解如何构建通用接口,然后请添加新的连接器(LinkObject)

注册连接器及其操作 – 将XML文件放在/ Kernel / Config / Files / …

然后转到Sysconfig – > GenericInterface – > GenericInterface :: Operation :: ModuleRegistration并在GenericInterface :: Operation :: Module ### LinkObject :: LinkAdd旁边设置一个勾号并保存更改

然后将此Connector文件添加到/Custom/Kernel/GenericInterface/Operation/LinkObject/LinkAdd.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::LinkAdd;

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::LinkAdd - GenericInterface Link Create 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 ConfigObject MainObject LogObject TimeObject DBObject EncodeObject 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::System->LinkObject->new( %{$Self} );

    return $Self;
}

=item Run()

Create a new link.

    my $Result = $OperationObject->Run(
        Data => {
            sourceObject => 'Ticket',TargetObject => 'Ticket',TargetKey    => '12345',},);

    $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    => 'LinkAdd.MissingParameter',Errormessage => "LinkAdd: The request is empty!",);
    }



    my $LinkID = $Self->{LinkObject}->LinkAdd(
        %Param,);

    if ( !$LinkID ) {
        return $Self->{CommonObject}->ReturnError(
            ErrorCode    => 'LinkAdd.AuthFail',Errormessage => "LinkAdd: 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

然后它应该出现,可以从管理员使用 – > Web服务 – >可用操作下拉列表当然可以用作Web服务.

php使用示例如下所示:

#### Initialize new client session ####
$client = new SoapClient(
 null,array(
 'LOCATIOn' => $url,'uri' => "Core",'trace' => 1,'login' => $username,'password' => $password,'style' => SOAP_RPC,'use' => SOAP_ENCODED
 )
);
#### Create and send the SOAP Function Call ####
$success = $client->__soapCall("Dispatch",array($username,$password,"LinkObject","LinkAdd","sourceObject",'Ticket',"sourceKey",$ticket_id1,"TargetObject","TargetKey",$ticket_id2,"Type",'ParentChild',"State",'Valid',"UserID",'1'
));

如果出现错误 – 启用调试,请查看系统日志并检查OTRS的所有初始设置

祝你好运!

更新#2

要注册Web服务 – 按“添加新的Web服务”按钮,根据需要对其进行命名并设置以下设置(选择LinkAdd操作)并保存

更新#3

这是OTRS 5的更新模块文件

# --
# Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm - GenericInterface LinkAdd operation BACkend
# Copyright (C) 2016 ArtyCo (Artjoms Petrovs),$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',see L<http://www.gnu.org/licenses/agpl.txt>.

=cut

大佬总结

以上是大佬教程为你收集整理的perl – 如何通过OTRS中的Web服务(SOAP或REST)将配置项链接/获取到故障单全部内容,希望文章能够帮你解决perl – 如何通过OTRS中的Web服务(SOAP或REST)将配置项链接/获取到故障单所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。