def createSession(self, protocol=None, allowCache=False):
     "Create a session based on the properties"
     from pynetsnmp.twistedsnmp import AgentProxy
     cmdLineArgs = []
     if '3' in self.zSnmpVer:
         if self.zSnmpPrivType:
             cmdLineArgs += ['-l', 'authPriv']
             cmdLineArgs += ['-x', self.zSnmpPrivType]
             cmdLineArgs += ['-X', self.zSnmpPrivPassword]
         elif self.zSnmpAuthType:
             cmdLineArgs += ['-l', 'authNoPriv']
         else:
             cmdLineArgs += ['-l', 'noAuthNoPriv']
         if self.zSnmpAuthType:
             cmdLineArgs += ['-a', self.zSnmpAuthType]
             cmdLineArgs += ['-A', self.zSnmpAuthPassword]
         if self.zSnmpEngineId:
             cmdLineArgs += ['-e', self.zSnmpEngineId]
         cmdLineArgs += ['-u', self.zSnmpSecurityName]
     #the parameter tries seems to really be retries so take one off
     retries = max(self.zSnmpTries - 1, 0)
     p = AgentProxy(ip=self.manageIp,
                    port=self.zSnmpPort,
                    timeout=self.zSnmpTimeout,
                    tries=retries,
                    snmpVersion=self.zSnmpVer,
                    community=self.zSnmpCommunity,
                    cmdLineArgs=cmdLineArgs,
                    protocol=protocol,
                    allowCache=allowCache)
     p.snmpConnInfo = self
     return p
예제 #2
0
    def fetchOid(self, oid):
        """
        Retrieve a single value from the device using the +oid+ supplied.
        This is necessary here because Zenoss component templates can only use
        SNMP index, but Sentry devices come from multiple vendors with their own
        MIB trees.
        """
        parent = self.device()
        proxy = AgentProxy(parent.id,
                           parent.zSnmpPort,
                           timeout=parent.zSnmpTimeout,
                           community=parent.zSnmpCommunity,
                           snmpVersion=parent.zSnmpVer,
                           tries=2)
        proxy.open()
        log = logging.getLogger('zen.ZenEvent')
        log.info('SENTRY fetch FETCHING OID %s.  Got proxy open already' % oid)

        defered = proxy.get([oid])

        self.finished = False
        defered.addBoth(self.gotResult, proxy, oid)
        defered.addErrback(self.gotFailure)

        # wait until this call is done
        while not self.finished:
            reactor.iterate(TIMEOUT)

        return self.result
예제 #3
0
    def getAgentProxy(self):
        cmdLineArgs = ['-u', self._securityName]

        if self._privType:
            cmdLineArgs += [
                '-l', 'authPriv',
                '-x', self._privType,
                '-X', self._privPassphrase]
        elif self._authType:
            cmdLineArgs += [
                '-l', 'authNoPriv']
        else:
            cmdLineArgs += [
                '-l', 'noAuthNoPriv']

        if self._authType:
            cmdLineArgs += [
                '-a', self._authType,
                '-A', self._authPassphrase]

        return AgentProxy(
            ip=self._ip,
            port=self._port,
            timeout=self._timeout,
            tries=self._retries,
            snmpVersion=self.version,
            community=self._community,
            cmdLineArgs=cmdLineArgs)
def get_snmp_proxy(host, version, community):
    """Return an SNMP proxy given host, version and community."""
    snmp_proxy = AgentProxy(ip=host, community=community, snmpVersion=version)

    snmp_proxy.open()

    return snmp_proxy
예제 #5
0
 def getAgentProxy(self):
     return AgentProxy(ip=self._ip,
                       port=self._port,
                       timeout=self._timeout,
                       tries=self._retries,
                       snmpVersion=self.version,
                       community=self._community)
def get_snmp_proxy(ds0, config):
    snmpV3Args = getSnmpV3Args(ds0)
    log.debug('snmpV3Args are %s ' % snmpV3Args)
    snmp_proxy = AgentProxy(ip=ds0.manageIp,
                            port=int(ds0.zSnmpPort),
                            timeout=ds0.zSnmpTimeout,
                            snmpVersion=ds0.zSnmpVer,
                            community=ds0.zSnmpCommunity,
                            cmdLineArgs=snmpV3Args,
                            protocol=None,
                            allowCache=False)
    snmp_proxy.open()
    return snmp_proxy