Ad Widget

Collapse

Use of Template Macros in LLD Item Prototypes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • duncan9562
    Member
    • Jan 2017
    • 46

    #1

    Use of Template Macros in LLD Item Prototypes

    I have a Discovery Rule that is applied to a handful of hosts. The discovery script finds an IP on a host, and uses this to create an item for that host.

    The item is something like custom.check_a[USER,PASS,IP].

    I am able to get the IP from the discovery script into the item prototype by using {#IP}, and when the items are created this is reflected.

    I also have macros assigned to the template that contains the discovery rule which are {$USER} and {$PASS}, which I want to add into the item prototype so that I have the three variables substituted with the macros from the template, and the IP from the discovery script....

    An example of this would be:
    custom.check_a[admin,passord01,8.8.8.8]

    How do I go about referencing the macros from the template in the item prototype?

    Thanks in advance!
  • aigars.kadikis
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Mar 2018
    • 208

    #2
    While you are creating your discovery rule, item prototypes in the same template where configured your {$USER} and {$PASS} then it should not be a problem.
    custom.check_a[{$USER},{$PASS},{#IP}] should work fine.

    Another tip:
    It is a good practice to define {$USER}, {$PASS} variables empty in template level and set these variables only in host level.
    In case if you would like to export the template to a file and give it to friend then the credentials will not be included in xml file.

    Regards,

    Comment

    • duncan9562
      Member
      • Jan 2017
      • 46

      #3
      Originally posted by aigars.kadikis
      While you are creating your discovery rule, item prototypes in the same template where configured your {$USER} and {$PASS} then it should not be a problem.
      custom.check_a[{$USER},{$PASS},{#IP}] should work fine.

      Another tip:
      It is a good practice to define {$USER}, {$PASS} variables empty in template level and set these variables only in host level.
      In case if you would like to export the template to a file and give it to friend then the credentials will not be included in xml file.

      Regards,
      That's for coming back so quickly on this!

      I have tried referencing the Macros in the item prototype as {$USER} and {$PASS}, however when the item is created it looks like this:-
      Code:
      custom.check_a[{$USER},{$PASS},8.8.8.8]
      So, the USER and PASS macros are not being substituted, but the IP from the discovery rule is.

      I have also tried as you said, setting the Macro values against the host, and the host group as opposed to the template...however rebuilding the items for any of the hosts in the group rebuilds them as below:-
      Code:
      custom.check_a[{$USER},{$PASS},8.8.8.8]
      I would expect to see the item (Hosts-->testserver1-->Items) shown with the Macro values in the item, something like:-
      Code:
      custom.check_a[admin,passord01,8.8.8.8]
      Thanks again for your help!


      Comment

      • aigars.kadikis
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Mar 2018
        • 208

        #4
        No, no. The {$MACROS} under item configuration will never expand. That would be a security risk. Otherwise you need to watch your shoulder every time you are opening item section.
        You should preceded to the next steps. Let the items gather the values. Observe the values under Monitoring -> Latest data.

        P.S. If you really want to expand your credentials on screen from item configuration there is one way.. Configure your item to gather the value with interval 5 minutes. Create a trigger prototype (which will detect no activity):
        Code:
        {template:custom.check_a[{$USER},{$PASS},{#IP}].nodata(1m)}=1
        Then you will got bunch of triggers fired up and now you can go in trigger debugging mode (kind of):
        This is a brilliant way how to expand and see the macros used in trigger expression: Can be very useful if using host level macros, temp...


        Regards,

        Comment

        • duncan9562
          Member
          • Jan 2017
          • 46

          #5
          Ah, that makes perfect sense now - when I was looking at the item view for the host I was expecting the Macros to be populated in the item that the Discovery Rule created, but if that is not the case then that is working as expected!

          Thank you very much for your help!!

          Comment

          Working...