Ad Widget

Collapse

Template Name as a Macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leigh.latham
    Junior Member
    • Nov 2019
    • 3

    #1

    Template Name as a Macro

    Hey,

    Building an integration in Python for Zabbix and I've finished the 'coding phase', I'm just trying to set up the template so that it can be used across multiple versions of Zabbix. To achieve this, I'd like to push all versions of the template clearly labelled to the project's Git repo.

    To save some time and make future updates of the template easier, I'd like to set the template XML file to use the entity declared at the top of the file across all of the key values within the file itself.

    I have currently achieved a situation where I'm able to define the template name at the top as an entity and now I can reuse that entity in the child keys. However, I believe I need to pass that value somehow into the trigger prototypes so they can refer to the current template version when they are executed.

    The entity is declared at the top of the document like so:

    <!DOCTYPE template [
    <!ENTITY template_name "Zabbix v4.4">
    ]>

    I have then declared a user macro and assigned it appropriately, like so:

    [XML]
    <macros>
    <macro macro="{$TEMPLATE_VERSION}" value="&template_name;"/>
    </macros>
    [/XML]

    The trigger prototype looks like the blow. Please see the 'bold' TEMPLATE_VERSION where I'm attempting to use the version name dynamically. When I remove this reference below and insert it with a hardcoded template name, I can see the macro and its value are available within Zabbix UI so I know the process is somewhat working.

    When I leave the reference below in, it fails validation with error: Check expression part starting from "{{$TEMPLATE_VERSION}: so I believe I'm either formatting this incorrectly or this simply isn't allowed.

    [XML]
    <trigger_prototype>
    <expression>{{$TEMPLATE_VERSION}:method.name["--i", "600","--m", "ALIAS","--n", "NAMESPACE","--s", "VALUE","--r", "{$VAR1}","--d", "DEPENDABLE={#VAR2}","--a", "{$ACCOUNT}"].last()}>0</expression>
    <recovery_mode>0</recovery_mode>
    <recovery_expression/>
    <name>CHECK 1 {#NAME}</name>
    <correlation_mode>0</correlation_mode>
    <correlation_tag/>
    <url/>
    <status>0</status>
    <priority>5</priority>
    <description/>
    <type>0</type>
    <manual_close>0</manual_close>
    <dependencies/>
    <tags/>
    </trigger_prototype>
    [/XML]

    Is anyone able to advise where I may be going wrong here?

    I have also tried variations of the above such as '{$TEMPLATE_VERSION:' - it seems that for some reason the user macro at the start of the trigger prototype isn't being respected the same as when it's a further right of the total expression.

    I did also notice there was a TRIGGER.TEMPLATE.NAME macro native to Zabbix but I couldn't get that to work either. Is that suited for this purpose also?

    Thanks in advance.
  • leigh.latham
    Junior Member
    • Nov 2019
    • 3

    #2
    Can I bump this?

    Does anyone have any suggestions at all as to how to achieve this?

    Simply trying to save my self a lot of work in future where I'm able to change the template name in XML to reference the correct version of the application while not having to update every trigger expression.

    Comment

    Working...