Ad Widget

Collapse

Monitoring host changing IP

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alastor82
    Junior Member
    • Oct 2022
    • 6

    #1

    Monitoring host changing IP

    Hi everyone, I'm new here so I apologize in advance for every mistake I will make (and for my english as well).
    I guess this issue is already known, I've found some question about it but no answer that fix it for me.
    I'm trying to setup a Zabbix server to monitor hosts in DHCP, so i want it to update the host interface when the IP changes.
    I've Zabbix 6.0 running in a CentOS 8 and the hosts I want to monitor are windows 10 machines.
    They have agent2 installed and I'm using them as active.
    I've set up an autoregistration action to retrieve every host where hostmetadata contains a custom string, link them to "windows by zabbix agent active" template and everything works.
    But when the host IP changes, Zabbix server keep trying retrieve information using the old IP and see the host as unavailable.

    I've tried using discovery rule but in this case Zabbix see the host that changed IP as a new host (changing the hostname adding "2" at the end of it when an hostname with the same name already exists). So I end up with orphan hosts and new hosts with the right IP but the wrong hostname, not exactly what i wanted.

    Is it possible to achieve what I'm trying to do? Thanks for any suggestion.
  • Answer selected by alastor82 at 28-10-2022, 22:09.
    Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1782

    I've set it as zabbix agent active item. Does it mean even this would work with no need for the server ti know the host ip?
    Yes, for active items the server won't ever connect to the agent IP, the agent will open all the connections.

    Markku

    Comment


    • alastor82
      alastor82 commented
      Editing a comment
      Thanks a lot, it's pretty helpful, It may sound trivial but I didn't realize it before, it will help me setting it up properly
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1782

    #2
    Zabbix server keep trying retrieve information using the old IP and see the host as unavailable.
    In that case your items are not active, they are passive.

    Use only active items, then the agent will connect to the server with whatever IP address it has, get the monitored items and deliver the results to the server.

    When using only active items you can set the agent interface IP address to for example 127.0.0.1, the server won't use it.

    Markku

    Comment


    • alastor82
      alastor82 commented
      Editing a comment
      Thanks for the reply, you're totally right, I'm sorry but I'm new and Zabbix is amazing but quite complex sometimes. Just a question, I've added a new item to retrieve info about installed software on the host (I'm not in front of the PC but was somerhing likes system.run[wmic product get] after enabling remote command in agent conf). I've set it as zabbix agent active item. Does it mean even this would work with no need for the server ti know the host ip? Thanks again
  • alastor82
    Junior Member
    • Oct 2022
    • 6

    #3
    Update: actually Zabbix was able to retrieve data from the host after changing IP. I was confused because the ZBX agent availability in the front end was grey (sometimes yellow) but the host new IP was added as new interface and used to get informations. Now my question Is: can I get rid of the host old interfaces/IP? I know I can achieve this by deleting the host but i'm looking for a way ti automatize the process. Thanks

    Comment

    • Markku
      Senior Member
      Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
      • Sep 2018
      • 1782

      #4
      Now my question Is: can I get rid of the host old interfaces/IP?
      If you delete the HostMetdata configuration (or modify the related autoregistration rule) then the agent won't be registered again and again.

      Markku

      Comment

      • Markku
        Senior Member
        Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
        • Sep 2018
        • 1782

        #5
        I've set it as zabbix agent active item. Does it mean even this would work with no need for the server ti know the host ip?
        Yes, for active items the server won't ever connect to the agent IP, the agent will open all the connections.

        Markku

        Comment


        • alastor82
          alastor82 commented
          Editing a comment
          Thanks a lot, it's pretty helpful, It may sound trivial but I didn't realize it before, it will help me setting it up properly
      • alastor82
        Junior Member
        • Oct 2022
        • 6

        #6
        I probably didn't explain it properly, but I would like Zabbix to know when the host ip changes and update it in the host data (even if it's not needed for Active checks as you've explained, I feel it would still be useful to know the actual ip of the machine from the front end). What happens now when a host changes its IP is that the new IP is added as another interface but the server keeps the host old ip as an unavailable interface (and i guess the IP used by the host agent for registering the first time is set as default). So my question was if it's possible for the Server to automatic delete interfaces/ip not used anymore from the host data

        Comment

        • Markku
          Senior Member
          Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
          • Sep 2018
          • 1782

          #7
          Right, that is totally different case then. I wouldn't try to use the host configuration data in that case at all because that's now monitoring data in practice.

          I would create an active item "host.ip" (etc) and populate that every minute using a UserParameter in the agent. Using "discard unchanged with heartbeat" preprosessing rule ensures that the IP is not saved in the database every time when unchanged.

          Just remove the ListenIP configuration from the agent and then it won't send the IP with the autoregistration messages.

          But the answer to your question about deleting the old interfaces: no, I don't think that's happening automatically. That's presumably because the autoregistration doesn't collect the IP addresses automatically either: it requires you to manually configure the ListenIP directive in the agents.

          Markku

          Comment

          • alastor82
            Junior Member
            • Oct 2022
            • 6

            #8
            Thank you Markku, I'm not really sure how to set and use userparameter but l'll make some test on monday. I will update this post. Have a nice weekend

            Comment

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

              #9
              https://www.zabbix.com/documentation...ault-interface Have you tried this?

              Comment

              • alastor82
                Junior Member
                • Oct 2022
                • 6

                #10
                Hi cyber, thanks for the reply. Yes, I did find and try that.
                It works if I manually configure the host agent configuration (zabbix_agent2.conf) to have HostInterface = Actual_host_ip_entered_manually. After restarting the agent on the host, the server update the Interface to the proper IP (Availability remains red but that's probably just matter of time).
                But I don't want to change the agent configuration file every time the host change its ip. I'm trying to find what command to add as the HostInterface value to update the host_ip automatically. So far, no luck. Can you give me any advice? Thanks again

                Comment

                • Markku
                  Senior Member
                  Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
                  • Sep 2018
                  • 1782

                  #11
                  It might be that I'm wrong about this:

                  That's presumably because the autoregistration doesn't collect the IP addresses automatically either: it requires you to manually configure the ListenIP directive in the agents.
                  In any case, the cybers idea is worth trying: setting HostInterface statically to the host name (instead of IP address) maybe prevents creating additional interfaces.

                  The IP address (that you needed, not Zabbix) would still need to be saved dynamically with a UserParameter is similar mechanism (a PowerShell command that returns the host IP address).

                  Markku

                  Comment

                  • alastor82
                    Junior Member
                    • Oct 2022
                    • 6

                    #12
                    Hi Markku, yes that is what I was trying to accomplish. I didn't have too much time today for working on it, I've had other tasks to do. Probably I could extract the IP from ipconfig command and some regular expression, but it's tricky. Maybe I should try working with low discovery rule, I'm not really sure. I'll be back to office on wednesday, I'll run some test and update this post.

                    Comment

                    Working...