LinkAdd - Pyotrs
Moderator: crythias
LinkAdd - Pyotrs
Hello,
I've been working on configuring the OTRS API to accept the LinkAdd command by API.
Based on https://stackoverflow.com/questions/346 ... -rest-in-o I've been trying to configure my OTRS 6 environment, but cannot seem to get this part working.
XML has been configured and LinkAdd has been added to the webservice, Webservices are created, and the linkadd api can be requested.
Sadly it does not work. I'm getting a response
DebugLog error: Summary: Returning provider data to remote system (HTTP Code: 500) Data : {"faultcode":"Server","faultstring":"Can't load operation backend module Kernel::GenericInterface::Operation::LinkObject::LinkAdd!"}.
DebugLog error: Summary: Operation could not be initialized Data : $VAR1 = { 'ErrorMessage' => 'Can\'t load operation backend module Kernel::GenericInterface::Operation::LinkObject::LinkAdd!', 'Success' => 0};.
I'm understanding the issue seems like to be in the module being started. The LinkAdd pm file has been created, but seems to be invalid.
Did anyone fix this or does anyone have a solution for this?
Thank you in advance!
Volrath
I've been working on configuring the OTRS API to accept the LinkAdd command by API.
Based on https://stackoverflow.com/questions/346 ... -rest-in-o I've been trying to configure my OTRS 6 environment, but cannot seem to get this part working.
XML has been configured and LinkAdd has been added to the webservice, Webservices are created, and the linkadd api can be requested.
Sadly it does not work. I'm getting a response
DebugLog error: Summary: Returning provider data to remote system (HTTP Code: 500) Data : {"faultcode":"Server","faultstring":"Can't load operation backend module Kernel::GenericInterface::Operation::LinkObject::LinkAdd!"}.
DebugLog error: Summary: Operation could not be initialized Data : $VAR1 = { 'ErrorMessage' => 'Can\'t load operation backend module Kernel::GenericInterface::Operation::LinkObject::LinkAdd!', 'Success' => 0};.
I'm understanding the issue seems like to be in the module being started. The LinkAdd pm file has been created, but seems to be invalid.
Did anyone fix this or does anyone have a solution for this?
Thank you in advance!
Volrath
-
- Administrator
- Posts: 3968
- Joined: 18 Dec 2007, 12:23
- Znuny Version: Znuny and Znuny LTS
- Real Name: Roy Kaldung
- Company: Znuny
- Contact:
Re: LinkAdd - Pyotrs
Hi,
The XML from the post is for OTRS 5, you have to migrate it to version 6.
- Roy
The XML from the post is for OTRS 5, you have to migrate it to version 6.
- Roy
Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO
Use a test system - always.
Do you need professional services? Check out https://www.znuny.com/
Do you want to contribute or want to know where it goes ?
Use a test system - always.
Do you need professional services? Check out https://www.znuny.com/
Do you want to contribute or want to know where it goes ?
Re: LinkAdd - Pyotrs
Hello Roy,
thank you for your response.
That is correct, i've manipulated the xml file so it fits the OTRS 6 format. But using this still doesn't solve the issue.
The xml is correctly parsed when i perform the "otrs.Console.pl Maint::Config::Rebuild --cleanup" command. but maybe i'm missing something.
the value i've put in there is:
Put after that, the xml points the system to the PM file.
which results in the error stated in my first post.
Volrath
thank you for your response.
That is correct, i've manipulated the xml file so it fits the OTRS 6 format. But using this still doesn't solve the issue.
The xml is correctly parsed when i perform the "otrs.Console.pl Maint::Config::Rebuild --cleanup" command. but maybe i'm missing something.
the value i've put in there is:
Code: Select all
<Setting Name="GenericInterface::Operation::Module###LinkObject::LinkAdd" Required="0" Valid="1">
<Description Translatable="1">GenericInterface module registration for the operation layer.</Description>
<Navigation>GenericInterface::Operation::ModuleRegistration</Navigation>
<Value>
<Hash>
<Item Key="Name">LinkAdd</Item>
<Item Key="Controller">LinkObject</Item>
<Item Key="ConfigDialog">AdminGenericInterfaceOperationDefault</Item>
</Hash>
</Value>
</Setting>
which results in the error stated in my first post.
Volrath
-
- Znuny superhero
- Posts: 889
- Joined: 15 Dec 2016, 15:13
- Znuny Version: All
- Real Name: Emin
- Company: Efflux GmbH
- Contact:
Re: LinkAdd - Pyotrs
Hello Volrath,
Did you execute the SetPermission script?
Does your XML start and end with these tags?
And is your file in otrs/Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm?
Try to make that LinkAdd doesn't execute anything but rather just returns 'true'. Does that help with the error?
Best regards
Emin
Did you execute the SetPermission script?
Does your XML start and end with these tags?
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="2.0" init="Application">
...
</otrs_config>
Try to make that LinkAdd doesn't execute anything but rather just returns 'true'. Does that help with the error?
Best regards
Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/
Free and premium add-ons: German | English
Free and premium add-ons: German | English
Re: LinkAdd - Pyotrs
Hello Emin,
Thank you for your reply.
To make sure everything was set up correctly i've run the SetPermission Script again.
The brackets have indeed been set in the XML part.
the LinkAdd.pm script is correctly places indeed, but i'm getting the feeling it is not working correctly.
making it return only true would be an option. For doing that, what content should be in the file?
Cause adding only return true; doesn't seem to do the trick.
Volrath
Thank you for your reply.
To make sure everything was set up correctly i've run the SetPermission Script again.
The brackets have indeed been set in the XML part.
the LinkAdd.pm script is correctly places indeed, but i'm getting the feeling it is not working correctly.
making it return only true would be an option. For doing that, what content should be in the file?
Cause adding only return true; doesn't seem to do the trick.
Volrath
-
- Znuny superhero
- Posts: 889
- Joined: 15 Dec 2016, 15:13
- Znuny Version: All
- Real Name: Emin
- Company: Efflux GmbH
- Contact:
Re: LinkAdd - Pyotrs
I am not sure how your file looks and if you made some changes to it.
I would change the Run subroutine to
— Emin
I would change the Run subroutine to
Code: Select all
sub Run {
my ( $Self, %Param ) = @_;
return 1;
# Comment out everything below this to get sure it's not a syntax error.
}
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/
Free and premium add-ons: German | English
Free and premium add-ons: German | English
Re: LinkAdd - Pyotrs
hmmm something did change after performing the reset of all the permissions.
At this point calling the API call, results in an HTTP Error (500).
Within the System logging it shows me "Need SourceObject!", this is being send towards the API with the script, but i cannot determin where the error is coming from exactly based no the formatting of the message.
If i debug the Webservice, i see all the information the script and api call is correctly formatted and recieved.
It does show " Detected operation LinkAdd" (with no data provided) and after that
but nothing after that.... so in my opinion it looks like the PM is not getting loaded correctly.... hmm
Does anyone have a working LinkAdd.pm file for version 6 of OTRS?
At this point calling the API call, results in an HTTP Error (500).
Within the System logging it shows me "Need SourceObject!", this is being send towards the API with the script, but i cannot determin where the error is coming from exactly based no the formatting of the message.
If i debug the Webservice, i see all the information the script and api call is correctly formatted and recieved.
It does show " Detected operation LinkAdd" (with no data provided) and after that
Code: Select all
"$VAR1 = {
'SessionID' => 'xxxxxxxxxxxx',
'SourceKey' => 22782,
'SourceObject' => 'Ticket',
'State' => 'Valid',
'TargetKey' => 20431,
'TargetObject' => 'Ticket',
'Type' => 'Normal'
};
Does anyone have a working LinkAdd.pm file for version 6 of OTRS?
-
- Znuny superhero
- Posts: 889
- Joined: 15 Dec 2016, 15:13
- Znuny Version: All
- Real Name: Emin
- Company: Efflux GmbH
- Contact:
Re: LinkAdd - Pyotrs
That's progress!
Your call is working, it just doesn't receive the needed parameters in the correct format.
This file is generating the error: https://github.com/OTRS/otrs/blob/rel-6 ... ct.pm#L313
BTW: I just analyzed the code on Stack Overflow and it's not authenticating correctly. This is an example of how it should be done.
You should get sure that you don't create vulnerabilities.
— Emin
Your call is working, it just doesn't receive the needed parameters in the correct format.
This file is generating the error: https://github.com/OTRS/otrs/blob/rel-6 ... ct.pm#L313
BTW: I just analyzed the code on Stack Overflow and it's not authenticating correctly. This is an example of how it should be done.
You should get sure that you don't create vulnerabilities.
— Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/
Free and premium add-ons: German | English
Free and premium add-ons: German | English
Re: LinkAdd - Pyotrs
hmm i've been rebuilding the Linkadd from scratch to make sure everything is set up correctly.
Created the XML files, creating the PM file with the correct rights structure.
the PM file looks like this at the moment.
what I noticed was that Pyotrs uses a session ID that is being send towards the script.
I changed this manually to send the userID instead of the session ID.
I see all the data getting in OTRS, but no response from the PM file.
No Errors in the logging this time ....
But still have the error on the script side... pointing me to line 2044 of lib.py, containting the _send_request . and the message "Failed to Access OTRS. connection aborted BadStatusLine"
Created the XML files, creating the PM file with the correct rights structure.
the PM file looks like this at the moment.
Code: Select all
# --
# 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 PUBLIC INTERFACE
=head2 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;
}
=head2 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 ) = @_;
my ( $UserID, $UserType ) = $Self->Auth(
%Param,
);
return $Self->ReturnError(
ErrorCode => 'LinkAdd.AuthFail',
ErrorMessage => "LinkAdd: Authorization failing!",
) if !$UserID;
# 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,
);
return {
Success => 1,
Data => {
Result => $LinkID,
},
};
}
1;
=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
I changed this manually to send the userID instead of the session ID.
I see all the data getting in OTRS, but no response from the PM file.
No Errors in the logging this time ....
But still have the error on the script side... pointing me to line 2044 of lib.py, containting the _send_request . and the message "Failed to Access OTRS. connection aborted BadStatusLine"
-
- Znuny superhero
- Posts: 889
- Joined: 15 Dec 2016, 15:13
- Znuny Version: All
- Real Name: Emin
- Company: Efflux GmbH
- Contact:
Re: LinkAdd - Pyotrs
Please show your POST request.
If you're getting nothing returned, you made a step backwards.
Working with sessions is fine as well.
If you're getting nothing returned, you made a step backwards.
Working with sessions is fine as well.
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/
Free and premium add-ons: German | English
Free and premium add-ons: German | English
Re: LinkAdd - Pyotrs
The script i'm using to perform the request is created with pyotrs.
at this point the code is as simple as this; (ofcourse the variables for setting up the connection are filled in)
based on the debugger info within OTRS this information is indeed recieved.
also the incoming data before mapping seems correct; but... after that nothing happens
based on the communication sequence, everything seems to be correct. contacting every correct path in the webservices.
at this point the code is as simple as this; (ofcourse the variables for setting up the connection are filled in)
Code: Select all
client = Client(OTRS_URL, OTRS_USERNAME, OTRS_PASSWORD)
client.session_create()
client.link_add(20431,21829,src_object_type="Ticket",dst_object_type="Ticket",link_type="Normal",state="Valid")
Code: Select all
Received data by provider from remote system (10/13/2020 12:35:12, debug)
{"SourceObject": "Ticket", "UserID": 7, "State": "Valid", "TargetKey": 21829, "Type": "Normal", "SourceKey": 20431, "TargetObject": "Ticket"}
Code: Select all
$VAR1 = {
'SourceKey' => 20431,
'SourceObject' => 'Ticket',
'State' => 'Valid',
'TargetKey' => 21829,
'TargetObject' => 'Ticket',
'Type' => 'Normal',
'UserID' => 7
};
based on the communication sequence, everything seems to be correct. contacting every correct path in the webservices.
-
- Znuny superhero
- Posts: 889
- Joined: 15 Dec 2016, 15:13
- Znuny Version: All
- Real Name: Emin
- Company: Efflux GmbH
- Contact:
Re: LinkAdd - Pyotrs
Check the log of your web server.
I rewrote the run subroutine. This is working for me:
And this is the request:
— Emin
I rewrote the run subroutine. This is working for me:
Code: Select all
sub Run {
my ($Self, %Param) = @_;
my ($UserID, $UserType) = $Self->Auth(%Param);
return $Self->ReturnError(
ErrorCode => 'LinkAdd.AuthFail',
ErrorMessage => "LinkAdd: Authorization failing!",
) if !$UserID;
# Check needed parameters.
for my $Needed (qw(SourceObject SourceKey TargetObject TargetKey Type State)) {
if (!$Param{Data}->{$Needed}) {
return $Self->ReturnError(
ErrorCode => 'LinkAdd.MissingParameter',
ErrorMessage => "LinkAdd: $Needed parameter is missing!",
);
}
}
$Param{Data}->{UserID} = $UserID; # Comment this out if you want to pass the UserID in your request.
my $Success = $Kernel::OM->Get('Kernel::System::LinkObject')->LinkAdd(%{$Param{Data}});
return {
Success => 1,
ErrorMessage => '', # In case of an error. TODO: Add debugging if wanted.
Data => {
Result => $Success, # 0 or 1
},
};
}
You do not have the required permissions to view the files attached to this post.
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/
Free and premium add-ons: German | English
Free and premium add-ons: German | English
Re: LinkAdd - Pyotrs
Hello Emin,
Thank you for rewriting the run subroutine.
I've added it.
I didn't see the webserver logs within the OTRS environment, so didn't think of looking there.
The line in there told me :
which is referencing to the following line of code in my .pm file;
looking at the Common.pm file within operations tab shows me that there is only an Auth() object.
Changing the value to Kernel::GenericInterface::Operation->new( %{$Self} ); fixes this, but gives me an issue at line 91
which is the following line
Thank you for rewriting the run subroutine.
I've added it.
I didn't see the webserver logs within the OTRS environment, so didn't think of looking there.
The line in there told me :
Code: Select all
Can't locate object method "new" via package "Kernel::GenericInterface::Operation::Common" at /opt/otrs//Kernel/GenericInterface/Operation/LinkObject/LinkAdd.pm line 54.\n
Code: Select all
53 # create additional objects
54 $Self->{CommonObject} = Kernel::GenericInterface::Operation::Common->new( %{$Self} );
55 $Self->{LinkObject}
56 = $Kernel::OM->Get('Kernel::System::LinkObject');
57
Changing the value to Kernel::GenericInterface::Operation->new( %{$Self} ); fixes this, but gives me an issue at line 91
which is the following line
Code: Select all
my ($UserID, $UserType) = $Self->Auth(%Param);
-
- Znuny superhero
- Posts: 889
- Joined: 15 Dec 2016, 15:13
- Znuny Version: All
- Real Name: Emin
- Company: Efflux GmbH
- Contact:
Re: LinkAdd - Pyotrs
Replace your file with this one, delete the OTRS cache (bin/otrs.Console.pl Maint::Cache::Delete) and restart your web server.
Code: Select all
# --
# Copyright (C) 2019–present Efflux GmbH, https://efflux.de/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::GenericInterface::Operation::LinkObject::LinkAdd;
use strict;
use warnings;
use Kernel::System::LinkObject;
use Kernel::System::VariableCheck qw(IsStringWithData IsHashRefWithData);
use parent qw(
Kernel::GenericInterface::Operation::Common
);
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};
}
return $Self;
}
=head2 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) = @_;
my ($UserID, $UserType) = $Self->Auth(%Param);
return $Self->ReturnError(
ErrorCode => 'LinkAdd.AuthFail',
ErrorMessage => "LinkAdd: Authorization failing!",
) if !$UserID;
# Check needed parameters.
for my $Needed (qw(SourceObject SourceKey TargetObject TargetKey Type State)) {
if (!$Param{Data}->{$Needed}) {
return $Self->ReturnError(
ErrorCode => 'LinkAdd.MissingParameter',
ErrorMessage => "LinkAdd: $Needed parameter is missing!",
);
}
}
$Param{Data}->{UserID} = $UserID; # Comment this out if you want to pass the UserID in your request.
my $Success = $Kernel::OM->Get('Kernel::System::LinkObject')->LinkAdd(%{$Param{Data}});
return {
Success => 1,
ErrorMessage => '', # In case of an error. TODO: Add debugging if wanted.
Data => {
Result => $Success, # 0 or 1
},
};
}
1;
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/
Free and premium add-ons: German | English
Free and premium add-ons: German | English
Re: LinkAdd - Pyotrs
Hello Emin,
Thank you for this file. it does seem to work now!
Still getting a response error, but that is something that i can fix in my opinion. The action seems to work correctly.
The funny thing is.. i'm getting the feeling the issue was in restarting the Webserver, cause adding this file and running it, did work the first time, i changed a little thing to use the Session ID again, and the script instantly stopped working. Getting the message the PM file could not be found/used.
After restarting the webservice the file worked again.
Thank you very much for helping me fix this frustrating component
Your Forum rank fits you very well!
Thank you for this file. it does seem to work now!
Still getting a response error, but that is something that i can fix in my opinion. The action seems to work correctly.
The funny thing is.. i'm getting the feeling the issue was in restarting the Webserver, cause adding this file and running it, did work the first time, i changed a little thing to use the Session ID again, and the script instantly stopped working. Getting the message the PM file could not be found/used.
After restarting the webservice the file worked again.
Thank you very much for helping me fix this frustrating component
Your Forum rank fits you very well!
-
- Znuny superhero
- Posts: 889
- Joined: 15 Dec 2016, 15:13
- Znuny Version: All
- Real Name: Emin
- Company: Efflux GmbH
- Contact:
Re: LinkAdd - Pyotrs
You're welcome =). I'm happy that it's working now.
It's almost always the cache/web server and that's almost everyone's first learning who gets into OTRS programming.
Feel free to post if you should be stuck again.
Best regards
Emin
It's almost always the cache/web server and that's almost everyone's first learning who gets into OTRS programming.
Feel free to post if you should be stuck again.
Best regards
Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/
Free and premium add-ons: German | English
Free and premium add-ons: German | English