Ad Widget

Collapse

HOST macros in Http Agent Item

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sebastiano
    Junior Member
    • Jan 2021
    • 7

    #1

    HOST macros in Http Agent Item

    Dear community,

    I am starting to use Zabbix and I am not very experienced with it. I want to create a template that, for the simplicity of this question, has one item of type HTTP agent. This item is of request type GET and the URL looks like this:
    Code:
    {HOST.CONN}:{HOST.PORT}/count-all
    When I click on "Test" in the item configuration and then on "Get value and test", I can set the macros to test values and the request successfully gets the correct value.

    After saving the item and assigning the template to a host, I can see the template item assigned to the host when viewing the list of items for that host. When clicking on the item and clicking on "Test", I can see that the macros are correctly automatically assigned to the values of the host interface. Clicking "Get value and test" yields the correct value.

    However: when I view "Latest data" for the host, I can see the item with a red exclamation mark in the info column, saying "Cannot perform request: URL using bad/illegal format or missing URL"

    I searched about macros in the documentation and https://www.zabbix.com/documentation...ed_by_location states that the {HOST.PORT} macro is not supported in the HTTP Agent item. Why? Is there any way to access the Port of the interface in a template item?

    Thank you!
  • sebastiano
    Junior Member
    • Jan 2021
    • 7

    #2
    Hello cyber, thank you for your answer.

    In my case, the host agent interface does not use port 10051. I set it to 8101, that is the port where my application that I want to monitor is listening to. And the HOST.PORT macro is correctly set to 8101 when testing the item assigned to the host.

    Adding "https://" in front does not work because of some SSL configuration (but this is not needed anyway because its all in an internal network). Adding "http://" did not change anything.

    Using {$PORT} would force me to define the {$PORT} macro for each host, even though I already defined the port in the host agent interface - is this correct? I just tested using {$PORT} in the template item and defining it in the host macros and it works. But I would like to avoid setting a macro for each host, especially since I already define the exact port in the host agent interface.

    Comment

    • Semiadmin
      Senior Member
      • Oct 2014
      • 1625

      #3
      Just try an internal LLD rule zabbix[host,discovery,interfaces] and put macros {#IF.CONN} and {#IF.PORT} into the http agent item prototype.

      Comment

      • sebastiano
        Junior Member
        • Jan 2021
        • 7

        #4
        Originally posted by Semiadmin
        Just try an internal LLD rule zabbix[host,discovery,interfaces] and put macros {#IF.CONN} and {#IF.PORT} into the http agent item prototype.
        Sadly, I do not know what to do here. What type of discovery rule should I add?

        I guessed and added a discovery rule of type "Zabbix Agent" with key "zabbix[host,discovery,interfaces]". But when testing, the error "Get value from agent failed: cannot connect to [[this-is-my-service]:8081]: [111] Connection refused" occured

        Comment

        • Semiadmin
          Senior Member
          • Oct 2014
          • 1625

          #5
          A Zabbix internal type.

          Comment

          • sebastiano
            Junior Member
            • Jan 2021
            • 7

            #6
            Originally posted by Semiadmin
            A Zabbix internal type.
            Thank you! I created the discovery rule as you described in the template and assigned the template to a host. Then I tested the discovery rule and it yields the (correct) result
            Code:
            [{"{#IF.CONN}":"this-is-my-service","{#IF.IP}":"127.0.0.1","{#IF.DNS}":"this-is-my-service","{#IF.PORT}":"8101","{#IF.TYPE}":"AGENT ","{#IF.DEFAULT}":1}]
            I added an Item prototype to the template with type Http Agent and unique key "test_discovery_item_prototype" and URL "{#IF.CONN}:{#IF.PORT}/count-all"

            Sadly, when I view the discovery rules of that host, I see the discovery rule with a red exclamation mark saying "Cannot create item: item with the same key "test_discovery_item_prototype" already exists."

            But there is no item in this host and no other item prototype in the template! What is the cause of this?

            Comment

            • Semiadmin
              Senior Member
              • Oct 2014
              • 1625

              #7
              You need an LLD macro in the item prototype key parameter and in the item prototype name, for example:
              test_discovery_item_prototype[{#IF.DNS}]

              Comment

              • sebastiano
                Junior Member
                • Jan 2021
                • 7

                #8
                Originally posted by Semiadmin
                You need an LLD macro in the item prototype key parameter and in the item prototype name, for example:
                test_discovery_item_prototype[{#IF.DNS}]
                I changed the item prototype name to "Test Discovery Item Prototype [{IF.DNS}]" and the key to "test_discovery_item_prototype_[{IF.DNS}]". Now the error changed to: "Cannot create item: item with the same key "test_discovery_item_prototype_[{IF.DNS}]" already exists."

                Comment

                • sebastiano
                  Junior Member
                  • Jan 2021
                  • 7

                  #9
                  I forgot the "#" in the item prototype name and key. Now, no more error occurs and I can test the item prototype in the host that has the tempate assigned. The test works!

                  The item also appears in "Latest data". But it does not show any data. Do you know why?

                  Comment

                  • sebastiano
                    Junior Member
                    • Jan 2021
                    • 7

                    #10
                    Now it works. It just took around 30 minutes for the data to show up...
                    Thanks for the help!

                    Comment

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

                      #11
                      HOST.CONN and HOST.PORT refer to a place where agent listens for this host... I really doubt anything will listen in agent port (10051) for your query. Even if HOST.CONN seems fine, then you should give your $PORT with a different macro. and also format your url as it should be .. https://{HOST.CONN}:{$PORT}/count-all

                      Comment

                      Working...