Custom Filter Module based on dev docs example

Moderator: crythias

Post Reply
100percent
Znuny newbie
Posts: 5
Joined: 18 Jan 2022, 21:53
Znuny Version: 6 Community
Real Name: Scott Toderash
Company: 100% Helpdesk

Custom Filter Module based on dev docs example

Post by 100percent »

I used the example in the developer docs
https://doc.znuny.org/doc/manual/develo ... ayers.html
and I created a Perl module in Kernel/System/PostMaster/Filter
and an XML file in Kernel/Config/Files
hoping these hooks would pick up my code and execute it.

I see no evidence that it is being executed, so there must be another step somewhere.

I noticed Kernel/Config/Files/XML so I moved the XML file there but it made no difference.

I restarted the scheduler daemon to make sure it would be using the most recent changes. Do I have to register this module somewhere? I can't find anything telling me how other than creating the XML file.

I just need to figure out how to get it to execute my code.
root
Administrator
Posts: 3934
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Custom Filter Module based on dev docs example

Post by root »

Hi,

Kernel/Config/Files/XML is the proper location. Have you executing
bin/otrs.Console.pl Maint::Config;:Rebuild
after putting all your files in place?

- 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 ?
100percent
Znuny newbie
Posts: 5
Joined: 18 Jan 2022, 21:53
Znuny Version: 6 Community
Real Name: Scott Toderash
Company: 100% Helpdesk

Re: Custom Filter Module based on dev docs example

Post by 100percent »

I did not do that step. I will try that.

What exactly does the Rebuild do?
root
Administrator
Posts: 3934
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Custom Filter Module based on dev docs example

Post by root »

100percent wrote: 20 Jan 2022, 00:08 I did not do that step. I will try that.

What exactly does the Rebuild do?
Hi,

Generates the sytem configuration settings out if the XML files. See https://doc.znuny.org/doc/manual/develo ... xml-config

- 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 ?
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: Custom Filter Module based on dev docs example

Post by reneeb »

If you used the XML sample from the developer manual for your config file, it is the wrong version. The tagnames etc. changed from framework version 5 to 6.

Old:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<otrs_config version="1.0" init="Application">
    <ConfigItem Name="Frontend::Module###AgentQuickClose" Required="0" Valid="1">
        <Description Translatable="1">Frontend module registration for the QuickClose agent interface.</Description>
        <Group>QuickClose</Group>
        <SubGroup>Frontend::Agent::ModuleRegistration</SubGroup>
        <Setting>
            <FrontendModuleReg>
                <Description>QuickClose</Description>
                <NavBarName></NavBarName>
                <Title Translatable="1">QuickClose</Title>
            </FrontendModuleReg>
        </Setting>
    </ConfigItem>
 </otrs_config>
New:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<otrs_config version="2.0" init="Application">
    <Setting Name="Frontend::Module###AgentQuickClose" Required="0" Valid="1">
        <Description Translatable="1">Frontend module registration for the QuickClose agent interface.</Description>
        <Navigation>Frontend::Agent::ModuleRegistration</Navigation>
        <Value>
            <Item ValueType="FrontendRegistration">
                <Hash>
                    <Item Key="Group">
                        <Array>
                        </Array>
                    </Item>
                    <Item Key="GroupRo">
                        <Array>
                        </Array>
                    </Item>
                    <Item Key="Description">QuickClose</Item>
                    <Item Key="NavBarName"></Item>
                    <Item Key="Title" Translatable="1">QuickClose</Item>
                </Hash>
            </Item>
        </Value>
    </Setting>
</otrs_config>
This is just an excerpt. If you post your config file, I can convert it from the old version to the new one. If you have a Znuny LTS version, there is a tool: https://github.com/znuny/Znuny/blob/rel ... ructure.pm

Just run

Code: Select all

perl bin/otrs.Console.pl Dev::Tools::Migrate::ConfigXMLStructure --source-directory <path/to/you/current_config.xml>
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
100percent
Znuny newbie
Posts: 5
Joined: 18 Jan 2022, 21:53
Znuny Version: 6 Community
Real Name: Scott Toderash
Company: 100% Helpdesk

Re: Custom Filter Module based on dev docs example

Post by 100percent »

I'm returning to this today to try some more. The rebuild threw errors, although changing the format to the new XML version helped.

However now the rebuild gives me several errors of "Message: Need Data!" (but I don't know what data) and then fails on SQL insert:

[Wed Jan 26 13:14:01 2022] otrs.Console.pl: DBD::mysql::db do failed: Column 'effective_value' cannot be null at /home/pcthd/otrs-rel-6_0/Kernel/System/DB.pm line 470.
ERROR: OTRS-otrs.Console.pl-Maint::Config::Rebuild-10 Perl: 5.16.3 OS: linux Time: Wed Jan 26 13:14:01 2022

Message: Column 'effective_value' cannot be null, SQL: '
INSERT INTO sysconfig_default (
name,description,navigation,is_invisible,is_readonly,is_required,is_valid,has_configlevel,user_modification_possible,user_modification_active,user_preferences_group,xml_content_raw,xml_content_parsed,xml_filename,effective_value,is_dirty,exclusive_lock_guid,create_time,create_by,change_time,change_by
)VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,'2022-01-26 13:14:01',?,'2022-01-26 13:14:01',? )'

So now I know that the rebuild process takes the XML data and inserts it into a table called sysconfig_default. That's helpful. I'm guessing that if I fill in more values in the XML file then the insert will succeed. I don't know what it's looking for though.
skullz
Znuny superhero
Posts: 618
Joined: 24 Feb 2012, 03:58
Znuny Version: LTS and Features
Real Name: Mo Azfar
Location: Kuala Lumpur, MY
Contact:

Re: Custom Filter Module based on dev docs example

Post by skullz »

effective_value represent default value of the config..
can you share your xml at least ?
100percent
Znuny newbie
Posts: 5
Joined: 18 Jan 2022, 21:53
Znuny Version: 6 Community
Real Name: Scott Toderash
Company: 100% Helpdesk

Re: Custom Filter Module based on dev docs example

Post by 100percent »

Here is the XML. The name of my module is 100Percent.pm. This is almost identical to the XML from the developer docs, since that is what it's based on.

<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="2.0" init="Config">
<Setting Name="PostMaster::PreFilterModule###1-100Percent" Required="0" Valid="1">
<Description Translatable="1">Custom module to tag CustomerID in new tickets.</Description>
<Navigation>Core::Email::PostMaster</Navigation>
<Hash>
<Item Key="Module">Kernel::System::PostMaster::Filter::100Percent</Item>
<Item Key="Match">
<Hash>
<Item Key="From">noreply@</Item>
</Hash>
</Item>
<Item Key="Set">
<Hash>
<Item Key="X-OTRS-Ignore">yes</Item>
</Hash>
</Item>
</Hash>
</Setting>
</otrs_config>
root
Administrator
Posts: 3934
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Custom Filter Module based on dev docs example

Post by root »

Hi,

I would say this XML is not a valid one for version 6. I do not see <Value> node. From where do you got the example?

- 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 ?
100percent
Znuny newbie
Posts: 5
Joined: 18 Jan 2022, 21:53
Znuny Version: 6 Community
Real Name: Scott Toderash
Company: 100% Helpdesk

Re: Custom Filter Module based on dev docs example

Post by 100percent »

https://doc.znuny.org/doc/manual/develo ... ayers.html
I don't know what the value is supposed to be. I only want it to load my module and execute my code.
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: Custom Filter Module based on dev docs example

Post by reneeb »

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="2.0" init="Config">
    <Setting Name="PostMaster::PreFilterModule###1-100Percent" Required="0" Valid="1">
    <Description Translatable="1">Custom module to tag CustomerID in new tickets.</Description>
    <Navigation>Core::Email::PostMaster</Navigation>
    <Value>
        <Hash>
            <Item Key="Module">Kernel::System::PostMaster::Filter::100Percent</Item>
            <Item Key="Match">
                 <Hash>
                     <Item Key="From">noreply@</Item>
                 </Hash>
             </Item>
             <Item Key="Set">
                  <Hash>
                      <Item Key="X-OTRS-Ignore">yes</Item>
                  </Hash>
              </Item>
            </Hash>
        </Value>
    </Setting>
</otrs_config>
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
Post Reply