Ad Widget

Collapse

Using LLD macro in item key?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • etfz
    Junior Member
    • Apr 2024
    • 19

    #1

    Using LLD macro in item key?

    Hi,

    Sort of new to Zabbix and don't really fully understand how all the components work, but I have successfully set up monitor for VMware and had it discover all virtual machines, as well as set up some LLD macros that links virtual machines to additional templates based on VMware tags.

    What I would like to do now is something similar, but using arbitrary TCP services. So far I managed to create and link hosts to a template using a fixed port by using a simple check with a key like so:
    Code:
    net.tcp.service[tcp,,17041]
    I'm imagining retrieving the desired port from a VMware custom attribute using an LLD macro:
    Code:
    {#VM.CA.PORT} = $..vmcustomattribute[?(@.name == "my-port")].value.first()
    But I don't know how to get this into the item key, if at all possible. I tried using the variable directly in the key, but that gave me an "Invalid third parameter" message.

    Ideally, I would also like to have a hardcoded fallback port if the custom attribute is not defined.

    Thank you
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4808

    #2
    item prototype as
    Code:
    net.tcp.service[tcp,,{#VM.CA.PORT}]

    Comment

    • etfz
      Junior Member
      • Apr 2024
      • 19

      #3
      After getting to know the platform a little I think I know what I really want. I would like to use an existing template for this.

      Using Apache by HTTP as an example; it has a template macro {$APACHE.STATUS.PORT}, which is used in an item like so:
      Code:
      net.tcp.service[http,"{HOST.CONN}","{$APACHE.STATUS.PORT}"]
      So then, I would like to somehow create a macro that overrides the one from the template, based on the LLD macro I previously created.

      Or if there is some other way of getting the LLD macro into a template.

      Comment

      • etfz
        Junior Member
        • Apr 2024
        • 19

        #4
        Went over this once again; now that I've learnt that you can configure templates and macros directly on discovered hosts, I will probably just do that instead of discovering that from VMware, but for closure, I did get very close with my original idea. Here's what I did:

        1. Create an LLD macro on the VMware - Discover VMware VMs discovery rule.

        LLD macro JSONPath
        {#VM.HTTP_PORT} $.vm_customattribute[?(@.name == "http-port")].value.first()

        2. Create a user macro on the VMware - Discover VMware VMs host prototype.

        Macro Value
        {$HTTP_PORT} {#VM.HTTP_PORT}

        3. Create a template and add a macro, defining the default value.

        Macro Value
        {$HTTP_PORT} 80

        4. Finally, add an item where the key uses the macro:
        Code:
        net.tcp.service[http,,{$HTTP_PORT}]
        The problem is that if no VMware attribute is defined on the virtual machine, the user macro gets the literal value {#VM.HTTP_PORT}, breaking the TCP check. (invalid third parameter) I don't know whether there is a good solution to that.
        Last edited by etfz; 25-11-2024, 16:50.

        Comment

        Working...