Esempio n. 1
0
    def guessCommunity(self, ignored, proxy, ip, communities, version=2):
        """Try to guess a community.

        @param proxy: an old proxy to close if different of C{None}
        @param ip: ip of the equipment to test
        @param communities: list of communities to test
        @param version: SNMP version (1 or 2)
        """
        if not communities:
            raise exception.NoCommunity("unable to guess community")
        community = communities[0]
        if proxy:
            proxy.community = community
            proxy.version = version
        else:
            proxy = AgentProxy(ip=str(ip),
                               community=community,
                               version=version)

        # Set timeout/retries
        timeout = self.config.get("timeout", None)
        retries = self.config.get("retries", None)
        if timeout is not None and timeout >= 0:
            proxy.timeout = timeout
        if retries is not None and retries >= 0:
            proxy.retries = retries

        # Set version and communities for next run if this one doesn't succeed
        version -= 1
        if version == 0:
            version = 2
            communities = communities[1:]
        d = proxy.get(['.1.3.6.1.2.1.1.1.0'])
        d.addCallbacks(callback=lambda x, y: y,
                       callbackArgs=(proxy, ),
                       errback=self.guessCommunity,
                       errbackArgs=(proxy, ip, communities, version))
        return d
Esempio n. 2
0
    def guessCommunity(self, ignored, proxy, ip, communities, version=2):
        """Try to guess a community.

        @param proxy: an old proxy to close if different of C{None}
        @param ip: ip of the equipment to test
        @param communities: list of communities to test
        @param version: SNMP version (1 or 2)
        """
        if not communities:
            raise exception.NoCommunity("unable to guess community")
        community = communities[0]
        if proxy:
            proxy.community = community
            proxy.version = version
        else:
            proxy = AgentProxy(ip=str(ip), community=community, version=version)

        # Set timeout/retries
        timeout = self.config.get("timeout", None)
        retries = self.config.get("retries", None)
        if timeout is not None and timeout >= 0:
            proxy.timeout = timeout
        if retries is not None and retries >= 0:
            proxy.retries = retries

        # Set version and communities for next run if this one doesn't succeed
        version -= 1
        if version == 0:
            version = 2
            communities = communities[1:]
        d = proxy.get([".1.3.6.1.2.1.1.1.0"])
        d.addCallbacks(
            callback=lambda x, y: y,
            callbackArgs=(proxy,),
            errback=self.guessCommunity,
            errbackArgs=(proxy, ip, communities, version),
        )
        return d