Пример #1
0
    def handle(self):
        # Start by checking the prefix cache
        prefix_cache_age = datetime.now() - self.prefix_cache_update_time
        if prefix_cache_age > self.prefix_cache_max_age:
            yield self._update_prefix_cache()

        self._logger.debug("Collecting IP/MAC mappings")

        # Fetch standard MIBs
        ip_mib = IpMib(self.agent)
        mappings = yield ip_mib.get_ifindex_ip_mac_mappings()
        self._logger.debug("Found %d mappings in IP-MIB", len(mappings))

        # Try IPV6-MIB if no IPv6 results were found in IP-MIB
        if not ipv6_address_in_mappings(mappings):
            ipv6_mib = Ipv6Mib(self.agent)
            ipv6_mappings = yield ipv6_mib.get_ifindex_ip_mac_mappings()
            self._logger.debug("Found %d mappings in IPV6-MIB",
                               len(ipv6_mappings))
            mappings.update(ipv6_mappings)

        # If we got no results, or no IPv6 results, try vendor specific MIBs
        if len(mappings) == 0 or not ipv6_address_in_mappings(mappings):
            cisco_ip_mib = CiscoIetfIpMib(self.agent)
            cisco_ip_mappings = yield cisco_ip_mib.get_ifindex_ip_mac_mappings(
            )
            self._logger.debug("Found %d mappings in CISCO-IETF-IP-MIB",
                               len(cisco_ip_mappings))
            mappings.update(cisco_ip_mappings)

        yield self._process_data(mappings)
Пример #2
0
    def handle(self):
        self._logger.debug("Collecting prefixes")
        netbox = self.containers.factory(None, shadows.Netbox)

        ipmib = IpMib(self.agent)
        ciscoip = CiscoIetfIpMib(self.agent)
        ipv6mib = Ipv6Mib(self.agent)

        # Retrieve interface names and keep those who match a VLAN
        # naming pattern
        vlan_interfaces = yield self.get_vlan_interfaces()
        ifc_aliases = yield self._get_ifc_aliases()

        # Traverse address tables from IP-MIB, IPV6-MIB and
        # CISCO-IETF-IP-MIB in that order.
        addresses = set()
        for mib in ipmib, ipv6mib, ciscoip:
            self._logger.debug("Trying address tables from %s",
                               mib.mib['moduleName'])
            df = mib.get_interface_addresses()
            # Special case; some devices will time out while building a bulk
            # response outside our scope when it has no proprietary MIB support
            if mib != ipmib:
                df.addErrback(self._ignore_timeout, set())
            df.addErrback(self._ignore_index_exceptions, mib)
            new_addresses = yield df
            self._logger.debug(
                "Found %d addresses in %s: %r",
                len(new_addresses),
                mib.mib['moduleName'],
                new_addresses,
            )
            addresses.update(new_addresses)

        adminup_ifcs = yield self._get_adminup_ifcs()
        for ifindex, ip, prefix in addresses:
            if ifindex not in adminup_ifcs:
                self._logger.debug(
                    "ignoring collected address %s on admDown ifindex %s", ip,
                    ifindex)
                continue
            if self._prefix_should_be_ignored(prefix):
                self._logger.debug("ignoring prefix %s as configured", prefix)
                continue
            self.create_containers(netbox, ifindex, prefix, ip,
                                   vlan_interfaces, ifc_aliases)
Пример #3
0
 def test_ipv6mib_index(self):
     ip_tuple = (32L, 1L, 13L, 184L, 18L, 52L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L)
     expected = IP('2001:db8:1234::1')
     ip = Ipv6Mib.ipv6address_to_ip(ip_tuple)
     self.assertEquals(ip, expected)
Пример #4
0
 def test_ipv6mib_index(self):
     ip_tuple = (32, 1, 13, 184, 18, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
     expected = IP('2001:db8:1234::1')
     ip = Ipv6Mib.ipv6address_to_ip(ip_tuple)
     assert ip == expected
Пример #5
0
 def test_ipv6mib_index(self):
     ip_tuple = (32L, 1L, 13L, 184L, 18L, 52L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L)
     expected = IP('2001:db8:1234::1')
     ip = Ipv6Mib.ipv6address_to_ip(ip_tuple)
     self.assertEquals(ip, expected)