Hello World Module is not registered Kernel/Config.pm

English! place to talk about development, programming and coding
Post Reply
Niroc
Znuny newbie
Posts: 18
Joined: 18 Jun 2015, 10:57
Znuny Version: 5.0.12

Hello World Module is not registered Kernel/Config.pm

Post by Niroc »

I'm trying to complete the helloworld tutorial to create an own module to extend the otrs.
I build now successfully my opm file and installed it via the admin panel.
But when I'm trying to access to AgentHelloWorld (via URL) I'm getting an error which says:
Module Kernel::Modules::AgentHelloWorld not registered in Kernel/Config.pm!
What do I have to do? There is no word about registering something in the Config.pm in the helloworld tutorial
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Hello World Module is not registered Kernel/Config.pm

Post by RStraub »

What you usually need for a working module are three files:
1) an .xml in /opt/otrs/Kernel/Config/Files/, like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<otrs_config version="1.0" init="Application">
        <ConfigItem Name="Frontend::Module###AgentHelloWorld" Required="1" Valid="1">
        <Description Translatable="1">FrontendModuleRegistration for HelloWorld module.</Description>
        <Group>HelloWorld</Group>
        <SubGroup>Frontend::Agent::ModuleRegistration</SubGroup>
        <Setting>
            <FrontendModuleReg>
                <Title>HelloWorld</Title>
                <Group>users</Group>
                <Description>HelloWorld</Description>
                <NavBarName>HelloWorld</NavBarName>
                <NavBar>
                    <Description>HelloWorld</Description>
                    <Name>HelloWorld</Name>
                    <Link>Action=AgentHelloWorld</Link>
                    <NavBar>HelloWorld</NavBar>
                    <Type>Menu</Type>
                    <Prio>8400</Prio>
                    <Block>ItemArea</Block>
                </NavBar>
            </FrontendModuleReg>
        </Setting>
    </ConfigItem>
</otrs_config>
2) a perl module (can be in ~otrs/Custom)
3) a template file (can be in ~otrs/Custom)

After creating the .xml, make sure to either rebuild the config or click on "SysConfig" in the Admin view.

That should suffice to register you module.

Could you please post your perl module and your .xml here ?
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Niroc
Znuny newbie
Posts: 18
Joined: 18 Jun 2015, 10:57
Znuny Version: 5.0.12

Re: Hello World Module is not registered Kernel/Config.pm

Post by Niroc »

this is my .xml file (almost exactly the same, I think)

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<otrs_config version="1.0" init="Application">
        <ConfigItem Name="Frontend::Module###AgentHelloWorld" Required="1" Valid="1">
        <Description Translatable="1">FrontendModuleRegistration for HelloWorld module.</Description>
        <Group>HelloWorld</Group>
        <SubGroup>Frontend::Agent::ModuleRegistration</SubGroup>
        <Setting>
            <FrontendModuleReg>
                <Title>HelloWorld</Title>
                <Group>users</Group>
                <Description>HelloWorld</Description>
                <NavBarName>HelloWorld</NavBarName>
                <NavBar>
                    <Description>HelloWorld</Description>
                    <Name>HelloWorld</Name>
                    <Link>Action=AgentHelloWorld</Link>
                    <NavBar>HelloWorld</NavBar>
                    <Type>Menu</Type>
                    <Prio>8400</Prio>
                    <Block>ItemArea</Block>
                </NavBar>
            </FrontendModuleReg>
        </Setting>
    </ConfigItem>
</otrs_config>
and the helloworld.pm

Code: Select all

# --
# Kernel/System/HelloWorld.pm - core module
# Copyright (C) (year) (name of author) (email of author)
# --
# 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::System::HelloWorld;

use strict;
use warnings;

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless ($Self, $Type);

    return $Self;
}

sub GetHelloWorldText {
    my ( $Self, %Param ) = @_;

    return 'Hello World';
}

1;
and also the AgentHelloWorld.pm

Code: Select all

# --
# Kernel/Modules/AgentHelloWorld.pm - frontend module
# Copyright (C) (year) (name of author) (email of author)
# --
# 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::Modules::AgentHelloWorld;

use strict;
use warnings;

use Kernel::System::HelloWorld;

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {%Param};
    bless ($Self, $Type);

    # check needed objects
    for (qw(ParamObject DBObject TicketObject LayoutObject LogObject QueueObject ConfigObject EncodeObject MainObject)) {
        if ( !$Self->{$_} ) {
            $Self->{LayoutObject}->FatalError( Message => "Got no $_!" );
        }
    }

    # create needed objects
    $Self->{HelloWorldObject} = Kernel::System::HelloWorld->new(%Param);

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;
    my %Data = ();

    $Data{HelloWorldText} = $Self->{HelloWorldObject}->GetHelloWorldText();

    # build output
    my $Output = $Self->{LayoutObject}->Header(Title => "HelloWorld");
    $Output   .= $Self->{LayoutObject}->NavigationBar();
    $Output   .= $Self->{LayoutObject}->Output(
        Data => \%Data,
        TemplateFile => 'AgentHelloWorld',
    );
    $Output   .= $Self->{LayoutObject}->Footer();
    return $Output;
}

1;

after I copied the xml file to the directory you've told me, a new HelloWorld tab showed up on the otrs page.
But after clicking on that it ended up in an error:
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.
Here is also the apache log:
ERROR: OTRS-CGI-44 Perl: 5.18.2 OS: linux Time: Wed Jun 1 14:04:14 2016

Message: Can't perform POST on https://cloud.otrs.com/otrs/public.pl: 500 Can't connect to cloud.otrs.com:443 (Network is unreachable)

RemoteAddress: 192.168.203.220
RequestURI: /otrs/index.pl?Action=AdminPackageManager

Traceback (1075):
Module: Kernel::System::WebUserAgent::Request Line: 209
Module: Kernel::System::CloudService::Backend::Run::Request Line: 331
Module: Kernel::Modules::AdminPackageManager::_GetFeatureAddonData Line: 2069
Module: Kernel::Modules::AdminPackageManager::Run Line: 1575
Module: Kernel::System::Web::InterfaceAgent::Run Line: 1042
Module: ModPerl::ROOT::ModPerl::Registry::opt_otrs_bin_cgi_2dbin_index_2epl::handler Line: 40
Module: (eval) (v1.99) Line: 206
Module: ModPerl::RegistryCooker::run (v1.99) Line: 206
Module: ModPerl::RegistryCooker::default_handler (v1.99) Line: 172
Module: ModPerl::Registry::handler (v1.99) Line: 31

[Wed Jun 01 14:04:22.724716 2016] [:error] [pid 1075] Can't call method "FatalError" on an undefined value at /opt/otrs/Custom/Kernel/Modules/AgentHelloWorld.pm li$
[Wed Jun 01 14:04:36.708375 2016] [:error] [pid 1078] Can't call method "FatalError" on an undefined value at /opt/otrs/Custom/Kernel/Modules/AgentHelloWorld.pm li$
[Wed Jun 1 14:04:37 2016] AgentHelloWorld.pm: Subroutine new redefined at /opt/otrs/Custom/Kernel/Modules/AgentHelloWorld.pm line 17.
[Wed Jun 1 14:04:37 2016] AgentHelloWorld.pm: Subroutine Run redefined at /opt/otrs/Custom/Kernel/Modules/AgentHelloWorld.pm line 37.
[Wed Jun 1 14:04:37 2016] HelloWorld.pm: Subroutine new redefined at /opt/otrs/Custom/Kernel/System/HelloWorld.pm line 15.
[Wed Jun 1 14:04:37 2016] HelloWorld.pm: Subroutine GetHelloWorldText redefined at /opt/otrs/Custom/Kernel/System/HelloWorld.pm line 25.
[Wed Jun 01 14:04:37.430973 2016] [:error] [pid 1079] Can't call method "FatalError" on an undefined value at /opt/otrs/Custom/Kernel/Modules/AgentHelloWorld.pm li$
[Wed Jun 01 14:04:37.979247 2016] [:error] [pid 1077] Can't call method "FatalError" on an undefined value at /opt/otrs/Custom/Kernel/Modules/AgentHelloWorld.pm li$
[Wed Jun 01 14:04:38.425772 2016] [:error] [pid 1076] Can't call method "FatalError" on an undefined value at /opt/otrs/Custom/Kernel/Modules/AgentHelloWorld.pm li$
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Hello World Module is not registered Kernel/Config.pm

Post by RStraub »

Nearly done. The syntax has changed in the last versions. Seems the tutorial is outdated. Try this as your AgentHelloWorld.pm :

Code: Select all

# --
# Kernel/Modules/AgentHelloWorld.pm - frontend module
# Copyright (C) (year) (name of author) (email of author)
# --
# 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::Modules::AgentHelloWorld;

use strict;
use warnings;

use Kernel::System::HelloWorld;

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {%Param};
    bless ($Self, $Type);

    # create needed objects
    $Self->{HelloWorldObject} = Kernel::System::HelloWorld->new(%Param);
    
    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;
    my %Data = ();

    $Data{HelloWorldText} = $Self->{HelloWorldObject}->GetHelloWorldText();

    my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
    # build output
    my $Output = $LayoutObject->Header(Title => "HelloWorld");
    $Output   .= $LayoutObject->NavigationBar();
    $Output   .= $LayoutObject->Output(
        Data => \%Data,
        TemplateFile => 'AgentHelloWorld',
    );
    $Output   .= $LayoutObject->Footer();
    return $Output;
}

1;
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Niroc
Znuny newbie
Posts: 18
Joined: 18 Jun 2015, 10:57
Znuny Version: 5.0.12

Re: Hello World Module is not registered Kernel/Config.pm

Post by Niroc »

results in a new error :/

i'm now getting the message:
file error - AgentHelloWorld.tt: not found
from otrs.
I don't have a .tt file. I also don't know what it is. This tutorial isn't only outdated, it's not beginners friendly too.
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Hello World Module is not registered Kernel/Config.pm

Post by RStraub »

Did you check you are reading the tutorial for the newest version like here ?
https://otrs.github.io/doc/manual/devel ... end-module

Check near the bottom of the page, where it tells you about the template file.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Niroc
Znuny newbie
Posts: 18
Joined: 18 Jun 2015, 10:57
Znuny Version: 5.0.12

Re: Hello World Module is not registered Kernel/Config.pm

Post by Niroc »

I now updated the .sopm file and rebuild the package and uploaded the .tt file itself to /otrs/Custom/Kernel/Output/HTML/Standard but I'm still getting the file is missing error. Uploading the .tt file directly to the Kernel/Output/HTML/Standard directory didn't help.
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Hello World Module is not registered Kernel/Config.pm

Post by RStraub »

Bleh, that's another fault in the tutorial. From version 5 onwards, the templates are located here:
/opt/otrs/Kernel/Output/HTML/Templates/Standard/
or here:
/opt/otrs/Custom/Kernel/Output/HTML/Templates/Standard/
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Niroc
Znuny newbie
Posts: 18
Joined: 18 Jun 2015, 10:57
Znuny Version: 5.0.12

Re: Hello World Module is not registered Kernel/Config.pm

Post by Niroc »

indeed...finally its working :)
I really really thank you!

But I've got a last question. While always rebuilding the package, deinstall it and reinstall it, I noticed that the HelloWorld-tab is still showing up, after deinstalling the package.
How is that possible?
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Hello World Module is not registered Kernel/Config.pm

Post by RStraub »

Caching.

You could use the Console skript to delete the cache.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
fvictorio
Znuny newbie
Posts: 2
Joined: 04 Aug 2016, 13:58
Znuny Version: OTRS Standard 5

Re: Hello World Module is not registered Kernel/Config.pm

Post by fvictorio »

I had the same problem with the templates path. I fixed it and sent a PR (https://github.com/OTRS/doc-developer/pull/15). Hopefully the next person to do the tutorial doesn't have to deal with that.

I didn't change the AgentHelloWorld.pm file, though, and it worked anyway. But maybe that's important too?
Post Reply