perl - 如何通过 OTRS 中的 Web 服务(SOAP 或 REST)将配置项链接/获取到工单

标签 perl web-services rest soap otrs

我想知道如何通过 SOAP 或 REST Web 服务获取票证并将其链接到配置项。 我已在管理控制台中导入此 Restfull Web service 并使用此 url 成功创建并获取票证信息 http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/1

但问题是当我获取票证信息时,链接的配置项信息没有出现。

我在谷歌上进行了大量搜索,发现票证可以通过 OTRS GUI 链接到配置项,并且在 AgentTicketzoom 页面中它将显示,我希望通过网络服务来完成此操作。 任何人都可以帮助我解决这个问题,或者建议一些有关如何创建 Web 服务以从票证中获取链接对象信息的文档。

更新#1

我已成功将 Web Controller 添加到现有的票证连接器中。 url 是带有 POST 调用的 http://XXX.XXX.XXX.XXX/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorRest/LinkObject。但我收到此错误

{"faultcode":"服务器","faultstring":"没有 ConfigObject!"}

我还检查了初始参数

$VAR1 = {  'Password' => '1234567',  'RequestMethod' => 'POST','SourceKey' => '1',  'SourceObject' => 'Ticket',  'State' => 'valid',  'TargetKey' => '2',  'TargetObject' => 'ITSMConfigItem',  'Type' => 'ParentChild',  'UserID' => '1',  'UserLogin' => '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b232323232355232323233b2323232355181416" rel="noreferrer noopener nofollow">[email protected]</a>'};

$VAR1 = {  'ErrorMessage' => 'Got no ConfigObject!',  'Success' => 0};

最佳答案

是的,票证可以通过 GUI 链接到 configItem,并且可以通过 Web 服务完成。

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

然后通过新的 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要了解通用接口(interface)是如何构建的,请添加一个新的连接器 ( LinkObject )

要注册连接器及其操作 - 将 XML 文件放入/Kernel/Config/Files/...

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

然后将此连接器文件添加到/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',
            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    => '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", 'Ticket',
"TargetKey", $ticket_id2,
"Type", 'ParentChild',
"State", 'Valid',
"UserID", '1'
));

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

祝你好运!

更新#2

要注册 Web 服务 - 按添加新 Web 服务按钮,根据需要命名并设置以下设置(选择 LinkAdd 操作)并保存

OTRS webservice

更新 #3

这是 OTRS 5 的更新模块文件

    # --
# 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 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    => '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

关于perl - 如何通过 OTRS 中的 Web 服务(SOAP 或 REST)将配置项链接/获取到工单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34675372/

相关文章:

asp.net - System.IO.FileNotFoundException : Could not load file or assembly 'file:///C:\Windows\Microsoft. NET\Framework\v4.0.30319\-i

web-services - nusoap 可以返回字符串数组吗?

java - HttpServlet 类与 Jersey 的混淆

Spring MVC @RequestParam对象列表

javascript - 如何在 Perl 中向 ajaxError 返回数据

perl - 查找总和为某个所需数字的数字组合

linux - cURL 不发送文件数据

perl - perl split() 中的分隔符保留模式

asp.net - ServiceStack - 返回类时为空 json

java - Spring Boot 异常处理