Ad Widget

Collapse

How to overwrite MACRO values from the configuration of the Zabbix Agent?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mgarcia
    Junior Member
    • Mar 2024
    • 12

    #1

    How to overwrite MACRO values from the configuration of the Zabbix Agent?

    Currently, Im using the Template "Apache by Zabbix agent" in a Autoregistration action.

    I would like to know if there is any possibility that from the Zabbix Agent configuration the value of a MACRO of the template can be setup.

    For example, I would like to set from the Agent the value of APACHE.STATUS.PORT because different servers can have Apache listening in different ports, so instead of having different templates in the Zabbix server, I could set the port in the server itself.

    And another question, is it possible that a configuration option set in zabbix_agent2.conf can be overridden by loading another .conf file that has been loaded with the "Include" option?

    Thank you very much,
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    User macros can also be set on host level. And that is the place where Zabbix looks first

    Zabbix resolves macros according to the following precedence:
    1. host level macros (checked first)
    2. macros defined for first level templates of the host (i.e., templates linked directly to the host), sorted by template ID
    3. macros defined for second level templates of the host, sorted by template ID
    4. macros defined for third level templates of the host, sorted by template ID, etc.
    5. global macros (checked last)
    But, if you want to do it during autoreg, then you probably have to whip up somekind of a script, that will update host macro during the registration process. Script execution via "send message to.."

    About include files... I think yes, if you include a file, it is read after initial config file, thus values will override initial values. It is very easy to test, I suppose..

    Comment

    • mgarcia
      Junior Member
      • Mar 2024
      • 12

      #3
      Thank you very much for your response,

      I have been reading that documentation but, to be honest, it was not clear to me where do I have to set those values.

      What I want is that these values:

      Click image for larger version

Name:	image.png
Views:	2210
Size:	32.7 KB
ID:	480251
      Or.... in that value, I have to add a command to retrieve the value from the host..... the documentation it's not very clear to me.

      And about the Include files, I can tell you that, for example, by default when installing the agent2, the file "zabbix_agent2.conf" has the value "Server=127.0.0.1" and "ServerActive=127.0.0.1" and in another file I try to override those values without luck.

      Comment

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

        #4

        If you already have added template to a host, you can go to hosts config, Macros section and press "inherited and host macros", you should see those macros now. If you press "change" and enter a new value, you are effectively creating a host level macro with same name and different value. After that it appears also to "host macros". As host level is searched first, value is taken from there and the one from template is ignored.
        If you plan to insert such macros already on autoreg, you just need to know exact macro name and insert it to host config. Later, if viewing over GUI, it will appear same as previously explained under "macros" -> "host macros".

        Maybe you should take closer look, what and where did you include.. I just tested with Server and ServerActive.. main file set them to "localhost" and I overwrite them in included file with correct values... worked just fine. Your include lines should be after the parameters you are trying to override..

        Comment

        • mgarcia
          Junior Member
          • Mar 2024
          • 12

          #5
          Oh, from you reply I think I didn't explain myself correctly. I don't want to change the value of the MACRO in the GUI directly in the host, I don't want to do it here

          Click image for larger version

Name:	image.png
Views:	2466
Size:	26.1 KB
ID:	480261

          What I want is that based in some parameter added in the Agent configuration file or in the server itself, that "85" value is sent to the Zabbix Server from the agent, so in that way, I can have 2 different servers with autodiscovery, and each of them sent for example, the Apache port that is configured.

          So server1 would send, for example, "80", and server2 would send "85". That way, the template for both of them is the same and from the agent I can decide to which port should the agent be checking Apache.

          I want that the value APACHE.STATUS.PORT is dynamically set from the Agent, not setting it up in the Zabbix Server GUI

          Comment

          • mgarcia
            Junior Member
            • Mar 2024
            • 12

            #6
            Originally posted by cyber
            Maybe you should take closer look, what and where did you include.. I just tested with Server and ServerActive.. main file set them to "localhost" and I overwrite them in included file with correct values... worked just fine. Your include lines should be after the parameters you are trying to override..
            yes, you are right, that works. I had a typo in the parameter name and now the parameter is overwritten properly.

            Comment

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

              #7
              If you want something to happen based on info in agent config file, then you probably need to populate HostMetadata parameter and then do tricks with it during autoregistration... Never tried it myself...

              Comment

              • mgarcia
                Junior Member
                • Mar 2024
                • 12

                #8
                Thank you very much anyway for your time.

                I'm already using the Hostmetadata approach to assign a different copy of the template based on that, but I find it nasty. So I have:

                Server1
                HostMetadata=:env=uat:app=apache80:

                Server2
                HostMetadata=:env=uat:app=apache85:

                And then two autoregistrations actions to apply the a copy of the Apache template with the PORT macro set to the value that the HOST needs.... but I think there should be a better way to achieve this.

                Click image for larger version

Name:	image.png
Views:	2179
Size:	42.5 KB
ID:	480359

                Comment

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

                  #9
                  Condition: host medatadata contains "whatever" -> operation: send notification to API capable user over a script type media, which takes {HOST.METADATA} and {HOST.HOST }as input and does things in background over API.. ie. setting host level macros for template..:P
                  Can get away with one action. And your script can have a lot of different subsections based on metadata keywords.

                  Comment

                  • mgarcia
                    Junior Member
                    • Mar 2024
                    • 12

                    #10

                    Thanks again; I will try to figure it out. I will post the solution here if I found something

                    Comment

                    Working...