Automate logging of OTRS change requests from command line

English! place to talk about development, programming and coding
Post Reply
nagabhus
Znuny newbie
Posts: 5
Joined: 20 Dec 2013, 09:00
Znuny Version: otrs-3.2.2

Automate logging of OTRS change requests from command line

Post by nagabhus »

Hi,

I'm working on automating logging of OTRS "change" request from command line through a script. I see the current ticket API exposed by OTRS can handle logging of OTRS tickets from command line. However my goal is to achieve the same with otrs ITSM feature to log "change" tickets. Is there any API available from OTRS, which could be leveraged to achieve this?

Even if all you can offer is where to start, it would help me to know how to proceed.

Thanks,
Sindhu
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Automate logging of OTRS change requests from command li

Post by crythias »

By what method are you monitoring the logging of OTRS tickets from the command line? (ie, AddHistory?)

perldoc Kernel/System/ITSMChange.pm

It will call EventHandler ChangeverbPre and ChangeverbPost

At that point, you can create an event to address the update.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
nagabhus
Znuny newbie
Posts: 5
Joined: 20 Dec 2013, 09:00
Znuny Version: otrs-3.2.2

Re: Automate logging of OTRS change requests from command li

Post by nagabhus »

Thanks much for your inputs.

>> By what method are you monitoring the logging of OTRS tickets from the command line? (ie, AddHistory?)
I don't intend to monitor the logging of OTRS tickets from command line. This monitoring is not required in my environment.

I happened to write a small perl script per your direction to log a change request using the module Kernel::System::ITSMChange . However I get the error "Got no UserObject! at /opt/otrs/Kernel/System/ITSMChange.pm line 108."
While logging tickets through GUI, Agent frontendmodule always know the UserID of the currently logged in agent which would get passed to UserObject eventually. But how can I pass the user info into USerObject while logging ticket through cmd line?

Below is my code

Code: Select all

#!/usr/bin/perl -w

use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Time;
use Kernel::System::Log;
use Kernel::System::DB;
use Kernel::System::Ticket;
use Kernel::System::Main;
use Kernel::System::ITSMChange;

my $ConfigObject = Kernel::Config->new();

my $EncodeObject = Kernel::System::Encode->new(
        ConfigObject => $ConfigObject,
    );

my $LogObject = Kernel::System::Log->new(
        ConfigObject => $ConfigObject,
        EncodeObject => $EncodeObject,
    );

my $MainObject = Kernel::System::Main->new(
        ConfigObject => $ConfigObject,
        EncodeObject => $EncodeObject,
        LogObject    => $LogObject,
    );

my $TimeObject = Kernel::System::Time->new(
        ConfigObject => $ConfigObject,
        LogObject    => $LogObject,
    );

my $DBObject = Kernel::System::DB->new(
        ConfigObject => $ConfigObject,
        EncodeObject => $EncodeObject,
        LogObject    => $LogObject,
        MainObject   => $MainObject,
    );

my $ChangeObject = Kernel::System::ITSMChange->new(
        ConfigObject => $ConfigObject,
        EncodeObject => $EncodeObject,
        LogObject    => $LogObject,
        DBObject     => $DBObject,
        TimeObject   => $TimeObject,
        MainObject   => $MainObject,
    );

my $ChangeID = $ChangeObject->ChangeAdd(
        ChangeTitle     => 'Replacement of mail server',       # (optional)
        Description     => 'New mail server is faster',        # (optional)
        Justification   => 'Old mail server too slow',         # (optional)
#        ChangeStateID   => 4,                                  # (optional) or ChangeState => 'accepted'
#        ChangeState     => 'accepted',                         # (optional) or ChangeStateID => 4
#        ChangeManagerID => 5,                                  # (optional)
#        ChangeBuilderID => 6,                                  # (optional)
#        CategoryID      => 7,                                  # (optional) or Category => '3 normal'
#        Category        => '3 normal',                         # (optional) or CategoryID => 4
#        ImpactID        => 8,                                  # (optional) or Impact => '4 high'
#        Impact          => '4 high',                           # (optional) or ImpactID => 5
#        PriorityID      => 9,                                  # (optional) or Priority => '5 very high'
        Priority        => '5 very high',                      # (optional) or PriorityID => 6
#        CABAgents       => [ 1, 2, 4 ],     # UserIDs          # (optional)
#        CABCustomers    => [ 'tt', 'mm' ],  # CustomerUserIDs  # (optional)
#        RequestedTime   => '2006-01-19 23:59:59',              # (optional)
#        ChangeFreeKey1  => 'Sun',                              # (optional) change freekey fields from 1 to ITSMChange::FreeText::MaxNumber
#        ChangeFreeText1 => 'Earth',                            # (optional) change freetext fields from 1 to ITSMChange::FreeText::MaxNumber
        UserID          => 1,
    );
   

print "Change added. Change ID  is $ChangeID"; 
[/quote]
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Automate logging of OTRS change requests from command li

Post by crythias »

If it says you need a User Object, you need a user object.

I think it's a document bug that the ITSMChange docs don't ask for it, though.

It needs: DBObject ConfigObject EncodeObject LogObject UserObject GroupObject MainObject TimeObject

Add

Code: Select all

use Kernel::System::User;

Code: Select all

    my $UserObject = Kernel::System::User->new(
        ConfigObject => $ConfigObject,
        LogObject    => $LogObject,
        MainObject   => $MainObject,
        TimeObject   => $TimeObject,
        DBObject     => $DBObject,
        EncodeObject => $EncodeObject,
    );
Basically, the concept for how ChangeAdd is similar to how the ticket is generated: There's a base ticket/base change that's created and then an article (for a ticket)/Change Update that's added for the change.
nagabhus wrote:But how can I pass the user info into USerObject while logging ticket through cmd line?
It depends how you'd obtain this information, but the overall description of ChangeUpdate and ChangeAdd only require a UserID.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
nagabhus
Znuny newbie
Posts: 5
Joined: 20 Dec 2013, 09:00
Znuny Version: otrs-3.2.2

Re: Automate logging of OTRS change requests from command li

Post by nagabhus »

Thanks much. That solved it all :)
[SOLVED]
Post Reply