Ejemplo n.º 1
0
 def updateHostList(self):
     """
     Fetches all netboxes from the NAVdb, and updates
     internal data structures.
     """
     LOGGER.debug("Getting hosts from database...")
     hosts = self.db.hosts_to_ping()
     netboxmap = {}
     self.ipToNetboxid = {}
     for host in hosts:
         netboxid, sysname, ip, up = host
         netbox = Netbox(netboxid, sysname, ip, up)
         if not self.netboxmap.has_key(netbox.netboxid):
             # new netbox. Be sure to get it's state
             if netbox.up != 'y':
                 LOGGER.debug(
                     "Got new netbox, %s, currently "
                     "marked down in navDB", netbox.ip)
                 self.down.append(netbox.netboxid)
         if not self.replies.has_key(netbox.netboxid):
             self.replies[netbox.netboxid] = circbuf.CircBuf()
             if netbox.up != 'y':
                 buf = self.replies[netbox.netboxid]
                 # This genious line marks all-down for the whole buf
                 map(buf.push, [-1] * len(buf))
         netboxmap[netbox.netboxid] = netbox
         self.ipToNetboxid[netbox.ip] = netbox.netboxid
     # Update netboxmap
     self.netboxmap = netboxmap
     LOGGER.debug("We now got %i hosts in our list to ping",
                  len(self.netboxmap))
     # then update our pinger object
     self.pinger.set_hosts(self.ipToNetboxid.keys())
Ejemplo n.º 2
0
 def update_host_list(self):
     """
     Fetches all netboxes from the NAVdb, and updates
     internal data structures.
     """
     _logger.debug("Getting hosts from database...")
     netbox_included_groups = self.config.get("groups_included", "").split()
     netbox_excluded_groups = self.config.get("groups_excluded", "").split()
     hosts = self.db.hosts_to_ping(netbox_included_groups, netbox_excluded_groups)
     netboxmap = {}
     self.ip_to_netboxid = {}
     for host in hosts:
         netboxid, sysname, ip, up = host
         netbox = Netbox(netboxid, sysname, ip, up)
         if netbox.netboxid not in self.netboxmap:
             # new netbox. Be sure to get it's state
             if netbox.up != 'y':
                 _logger.debug(
                     "Got new netbox, %s, currently " "marked down in navDB",
                     netbox.ip,
                 )
                 self.down.append(netbox.netboxid)
         if netbox.netboxid not in self.replies:
             self.replies[netbox.netboxid] = circbuf.CircBuf(self._nrping)
             if netbox.up != 'y':
                 self.replies[netbox.netboxid].reset_all_to(-1)
         netboxmap[netbox.netboxid] = netbox
         self.ip_to_netboxid[netbox.ip] = netbox.netboxid
     # Update netboxmap
     self.netboxmap = netboxmap
     _logger.debug("We now got %i hosts in our list to ping", len(self.netboxmap))
     # then update our pinger object
     self.pinger.set_hosts(self.ip_to_netboxid.keys())
Ejemplo n.º 3
0
    def __init__(self, ip):
        self.ip = ip
        # Random value for the cookie
        self.rnd = random.randint(10000, 2**16 - 1)
        # Time the echo was sent
        self.time = 0
        # Used in nextseq
        self.certain = 0

        # Check IP version and choose packet class
        if self.is_valid_ipv6():
            self.ipv6 = True
            self.packet = PacketV6()
        else:
            self.ipv6 = False
            self.packet = PacketV4()

        self.packet.id = os.getpid() % 65536
        self.replies = circbuf.CircBuf()