Using the perl interface

Moderator: crythias

Locked
fakeroot
Znuny newbie
Posts: 9
Joined: 25 Apr 2012, 11:05
Znuny Version: 3.1.2

Using the perl interface

Post by fakeroot »

Hi'

As a newcomer to otrs it has been great to experiment with the perl interface of otrs. Using for instance $TicketObject->TicketCreate and $TicketObject->ArticleCreate has been a great way to import bulks of data from other sources, and quick deletions have been easy as well, and certainly much easier than doing point and click in web interfaces.

It would be great as well to use the perl interface to populate the CMDB and create intralinks between its entities as well. However, documentation for that part seems more hidden to me, so the question simply goes as to the structure of the perl interface into the CMDB.

* How is an entity added to/removed from the CMDB via perl.

* How is a link interconnecting CMDB entities created/deleted via perl.

Thanks in advance for any help and pointers.

Best regards.

Thomas.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Using the perl interface

Post by reneeb »

Code: Select all

cd /opt/otrs
perldoc Kernel/System/ITSMConfigItem.pm
and

Code: Select all

perldoc Kernel/System/LinkObject.pm
How those modules are used can be seen in Kernel/Modules/AgentITSMConfigItemEdit.pm
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
fakeroot
Znuny newbie
Posts: 9
Joined: 25 Apr 2012, 11:05
Znuny Version: 3.1.2

Re: Using the perl interface

Post by fakeroot »

Hi'

Thanks for providing pointers to ITSMConfigItem.pm and LinkObject.pm, which I have already looked at with perldoc. However, I did not find any immediate clue on the interface for actually populating a new item. In other words, method ConfigItemAdd() seems to only add a new configuration item, but how to actually associate it with a class and how to fill in data according to the specifications of that class did not spring clear into my mind via the information provided to perldoc. I do take note of AgentITSMConfigItemEdit.pm as well, but that module does not contain perldoc sections, so I take it, that I will need to study the code in detail here. If you by chance have an example available, then that would be highly appreciated.

Best regards.

Thomas.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Using the perl interface

Post by reneeb »

Code: Select all

my $Class = $Self->{GeneralCatalogObject}->ItemGet(
    Class => 'ITSM::ConfigItem::Class',
    Name => 'Computer',
);

my $ConfigItemID = $Self->{ConfigItemObject}->ConfigItemAdd(
        ClassID => $Class{ID},
        UserID  => $Self->{UserID},
);

my %Version = (
    Vendor => 'Perl-Services.de',
    Description => 'OTRS Add-On blablabla',
    # weiter je nach Definition des Config Items
);

my $XMLDefinition = $Self->{DefinitionObject}->DefinitionGet(
    ClassID => $Class{ID},
);

            $Self->{ConfigItemObject}->VersionAdd(
                %Version,
                ConfigItemID => $ConfigItemID,
                DefinitionID => $XMLDefinition->{DefinitionID},
                UserID       => $Self->{UserID},
            );
Das
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
fakeroot
Znuny newbie
Posts: 9
Joined: 25 Apr 2012, 11:05
Znuny Version: 3.1.2

Re: Using the perl interface

Post by fakeroot »

Hi'

Thanks for that template. It needed a little modification, but with the below quoted snippet I am almost at the goal.

Code: Select all

my $Class = $GeneralCatalogObject->ItemGet(
    Class => 'ITSM::ConfigItem::Class',
    Name => 'Computer',
);

my $XMLDefinition = $ConfigItemObject->DefinitionGet(
    ClassID => $Class->{ItemID},
);

my %XMLData = (
    Description => 'The best ever ubuntu desktop',
    OperatingSystem => "Ubuntu linux"
);

#my $ConfigItemID = $ConfigItemObject->ConfigItemAdd(
#        ClassID => $Class->{ItemID},
#        UserID  => 2,
#);

$ConfigItemObject->VersionAdd(
#    ConfigItemID => $ConfigItemID,
    ConfigItemID => 1,
    Name => "myhostname",
    DefinitionID => $XMLDefinition->{DefinitionID},
    DeplStateID  => 42,
    InciStateID  => 11,
    XMLData => \%XMLData,
    UserID       => 2,
);
However, the data in the XMLData hash, which I try to include via the \%XMLData reference, does not show in the web interface. Can you spot immediately, what I am doing wrong.

Best regards.

Thomas.
Locked