Ad Widget

Collapse

Help with Zabbix Macro Tags

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tashton
    Junior Member
    • Apr 2022
    • 6

    #1

    Help with Zabbix Macro Tags

    Hi Support,

    I am attempting to implement a Template-Level Trigger macro.
    All of our Servers have a strict naming convention, where the first 7 characters of the hostname are also the Sites Name too.

    We have multiple servers per site, and we want to tag all of them as our host group name.

    e.g. Some Example Servers Hostnames: NSF-ART-SVR01, NSF-ART-SVR-02, NSF-ART-SVR03
    Our internal site reference for this site is NSF-ART

    I initially tried creating a tag with Name = SiteCode Value = {{HOST.HOST}.regsub("^.{0,7}","\0")}

    However when we see a Problem with the host, the Tag associated with that host it looks like: SiteCode:{NSF-ART-SVR01.iregsub("^.{0,7}","\0")}
    So it appears it is not fully evaluating the Macro.
    Would any please have some assistance on this?
    Thanks.

  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    https://www.zabbix.com/documentation...ed_by_location
    It mentions "customizing of macro" for 3 things... {ITEM.LASTVALUE<1-9>}, {ITEM.VALUE<1-9>} and {#MACRO}.
    Not for {HOST.HOST}

    The same is on the Macro functions page https://www.zabbix.com/documentation...acro_functions

    Supported macro functions
    Description Parameters Supported for
    regsub (<pattern>,<output>)
    Substring extraction by a regular expression match (case sensitive). pattern - the regular expression to match
    output - the output options. \1 - \9 placeholders are supported to capture groups. \0 returns the matched text.
    {ITEM.VALUE}
    {ITEM.LASTVALUE}

    Low-level discovery macros (except in low-level discovery rule filter)
    iregsub (<pattern>,<output>)
    Substring extraction by a regular expression match (case insensitive). pattern - the regular expression to match
    output - the output options. \1 - \9 placeholders are supported to capture groups. \0 returns the matched text.
    {ITEM.VALUE}
    {ITEM.LASTVALUE}

    Low-level discovery macros (except in low-level discovery rule filter)
    Conclusion... you cannot do this with {HOST.HOST}...

    What I would suggest is to use hosts inventory and fill location field and use {INVENTORY.LOCATION} macro, where you need it. You can use agent items (agent.hostname) to fill inventory... just pull hostname as item, preprocess it (almost same regex you used.. "(^.{0,7})", return \1) and tell it to populate inventory (location field)
    Last edited by cyber; 26-05-2022, 11:26.

    Comment

    • tashton
      Junior Member
      • Apr 2022
      • 6

      #3
      Hi cyber

      Thankyou very much for your reply, that makes a lot of sense - I've tested that pre-processed Item and the Regex works as expected which is great, my last sticking point is that when I try to add this to a template, I get "item agent.hostname already exists, inherited from other templates"; is it at all possible to have this added in it's pre-processed state, alongside the standard, full hostname too?

      Many Thanks

      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #4
        Originally posted by tashton
        Hi cyber

        Thankyou very much for your reply, that makes a lot of sense - I've tested that pre-processed Item and the Regex works as expected which is great, my last sticking point is that when I try to add this to a template, I get "item agent.hostname already exists, inherited from other templates"; is it at all possible to have this added in it's pre-processed state, alongside the standard, full hostname too?

        Many Thanks
        Seems you may already have that item from another template (seems default "Linux by Zabbix agent" uses it) .. Then you may get away with just setting that existing one to fill your inventory. No need to add another one. But yes... if you preprocess it, it will change the value, what you are saving. But you have also "system.hostname" you can use besides agent.hostname.
        Last edited by cyber; 01-06-2022, 11:31.

        Comment

        • tashton
          Junior Member
          • Apr 2022
          • 6

          #5
          Thanks cyber - Making progress; I've actually just edited the default Generic Windows Template to put the system.hostname into the Inventory > Location field, however I think I'm stuck on the final step; I can see my Item being successfully applied to my host (In Latest Data for the host I can see my successfully pre-processed Item) and when I go to Inventory and Check Location it's blank, but I can see its says its pulling it from my Item I created; When I click that link to view that Item and hit test, (per below) it is all successful and the resultant value displays, it just seems its not actually populating in Location despite the upstream data existing and being correct. Thanks for all the help so far, do you have any ideas on this one?
          Click image for larger version

Name:	ZabbixLocationInventory.png
Views:	1367
Size:	58.4 KB
ID:	445511

          Comment

          • cyber
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Dec 2006
            • 4807

            #6
            Did you set your item to populate the field? Is your hosts inventory set to "Automatic" or "Manual" or "Disabled"?
            If its disabled, then I dont think it will populate....

            Click image for larger version  Name:	location.png Views:	0 Size:	11.6 KB ID:	445518

            Comment

            • tashton
              Junior Member
              • Apr 2022
              • 6

              #7
              Thanks - Yep its set to Populate Location and Inventory has been set to Automatic.

              Comment

              Working...