Ad Widget

Collapse

Removing inactive nodes and the problem with Zabbix 5.0 auto-registration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • artsiom82
    Member
    • Nov 2016
    • 33

    #1

    Removing inactive nodes and the problem with Zabbix 5.0 auto-registration

    Good day
    1. Set up auto-registration. Hosts are registered through two different proxies. So if the hostnames are the same, then normally they are not registered, but "merged" into one. Do not offer the "system.uname" option, since with thousands of hosts the chance of coincidence is extremely high. I see an option in the host name to add for example the short name of the proxy (for example proxy_01), total it will be comp proxy_01, is this real? and if yes how i can do it? or there is another solution?
    2. During auto-registration, when it will be necessary to delete inactive hosts, we configured the deletion through "auto-detection", but the hosts are not deleted .. Tell me please, what am I doing wrong?
  • artsiom82
    Member
    • Nov 2016
    • 33

    #2
    Friends, I can`t believe nobody knows? Pls help..

    Comment

    • gofree
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2017
      • 400

      #3
      zabbix v5 is beta1 - there are only ferwpeople that will invest time in beta release troubleshooting - hope you didnt put v5 in production

      if your worried about system.name use DNS or IP for host naming - I prefer DNS.

      Comment

      • artsiom82
        Member
        • Nov 2016
        • 33

        #4
        Originally posted by gofree
        zabbix v5 is beta1 - there are only ferwpeople that will invest time in beta release troubleshooting - hope you didnt put v5 in production

        if your worried about system.name use DNS or IP for host naming - I prefer DNS.
        same problem in previous versions like 4, i can`t use DNS or IP because
        Originally posted by artsiom82
        Do not offer the "system.uname" option, since with thousands of hosts the chance of coincidence is extremely high. I see an option in the host name to add for example the short name of the proxy (for example proxy_01), total it will be comp proxy_01, is this real? and if yes how i can do it? or there is another solution?

        Comment

        • gofree
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Dec 2017
          • 400

          #5


          To DNS, isn't it discovered as fqdn (can't say it's late night, already falling asleep) ? In such case the chances are slim.

          Usually
          people have problem that large networks can't be scanned in timely manner. Please share you configurations, to add and to remove hosts.

          Comment

          • tim.mooney
            Senior Member
            • Dec 2012
            • 1427

            #6
            Originally posted by artsiom82
            i can`t use DNS or IP because
            I'm sorry but I don't understand your reasoning. The suggestion offered by gofree makes good sense. system.uname is not the same as DNS. I work at an organization with many thousand devices and every one has a unique fully qualified domain name (FQDN) in the DNS. The only place where you might typically have duplication in the DNS is for DNS-based load-balancing, and that's typically done with CNAMEs anyway, so every device typically has a unique A or AAAA record.

            Comment

            • artsiom82
              Member
              • Nov 2016
              • 33

              #7
              Originally posted by tim.mooney

              I'm sorry but I don't understand your reasoning. The suggestion offered by gofree makes good sense. system.uname is not the same as DNS. I work at an organization with many thousand devices and every one has a unique fully qualified domain name (FQDN) in the DNS. The only place where you might typically have duplication in the DNS is for DNS-based load-balancing, and that's typically done with CNAMEs anyway, so every device typically has a unique A or AAAA record.
              we have many organisations... in different places, and thanks i solve the problem by adding UID to hostname
              now i am trying to solve problem with deleting hosts by python script (found in internet), but it runs and nothing happens...
              Code:
              #!/usr/bin/python
              #
              #   Prerequisites:
              #       yum install python-pip
              #       pip install zabbix-api
              
              import time
              from zabbix_api import ZabbixAPI, Already_Exists
              changetime = time.time() - 604800 # One week ago
              z = ZabbixAPI(server="http://127.0.0.1/zabbix")
              z.login("user", "password")
              for trigger in z.trigger.get({"output": [ "triggerid", "description", "priority", "lastchange" ], "filter": { "value": 1 , "description": 'Zabbix agent on {HOST.NAME} is unreachable for 5 minutes'}, "sortfield": "priority", "sortorder": "DESC"}):
                  trigger["lastchange"] = int(trigger["lastchange"])
              if trigger["lastchange"] <= changetime:
                      trigmsg = z.trigger.get({"triggerids": trigger["triggerid"], "selectHosts": "extend"})
                      for tm in trigmsg:
                          for l in tm['hosts']:
                              z.host.update({ 'hostid' : int(l['hostid']), 'status' : 1 })
              i am zero on python can you or anybody help me please?

              Comment

              • Avinasha
                Member
                • Jan 2018
                • 40

                #8
                artsiom82 I'm not sure whether you were able to achieve what you wanted. I googled and ended up here. Basically, I was lazy to write one script myself but had to do that. Copying here just in case if its going to help somebody else. In my script, I'm disabling nodes when the agent is unreachable for more than 24 hours. change value 86400(equal to a day 60X60X24) to whatever you need. I have also restricted this to work only on one particular group with Group ID 17.

                Code:
                import json
                import time
                from pyzabbix import ZabbixAPI ## Make sure you have pyzabbix imported
                zapi = ZabbixAPI('http://<your zabbix IP>/zabbix/') ###zabbix URL
                zapi.login('USER', 'PASSWORD') ###user login
                print("Connected to Zabbix API Version %s" % zapi.api_version())
                
                changetime = int(time.time() - 86400); ### 60X60X24 = 86400 seconds of a day
                print(changetime)
                
                json_request = zapi.do_request('trigger.get',({"output": [ "triggerid", "description", "priority", "lastchange" ],"filter": { "value": 1 ,"groupids":17,"description": 'Zabbix agent is not available (for {$AGENT.TIMEOUT})'}, "sortfield": "priority", "sortorder": "DESC"})) ### Change the alert to whatever you have in your environment. copy it as is in Template Module Zabbix Agent. Also #modify or remove the groupids filter I have here
                
                #print(json_request)
                trigger1 = json_request.get("result")
                #print(trigger1)
                
                for trigger in trigger1:[INDENT]#print(trigger["lastchange"])[/INDENT][INDENT]#print(trigger["triggerid"])
                
                trigger["lastchange"] = int(trigger["lastchange"])
                trigger["triggerid"] = int(trigger["triggerid"])
                if trigger["lastchange"] <= changetime:[/INDENT][INDENT=2]trigger_hst = zapi.do_request('trigger.get',{"triggerids": trigger["triggerid"], "selectHosts": "extend"})
                trigger2 = trigger_hst.get("result")
                
                #print(trigger2)
                for tm in trigger2:[/INDENT][INDENT=3]#print(tm)
                
                for l in tm["hosts"]:[/INDENT][INDENT=4]hst_disable = zapi.do_request('host.update',({ 'hostid' : int(l['hostid']), 'status' : 1 })) # Node will be disabled
                #hst_del = zapi.do_request('host.delete,({'hostid' : int(l['hostid'])})) ### Nodes Must be deleted I wasn't able to test it[/INDENT]
                Regards,
                Avinasha
                Last edited by Avinasha; 12-01-2021, 11:38.

                Comment

                Working...