def inner(driver): """ Twisted driver class to iterate through devices @param driver: Zenoss driver @type driver: Zenoss driver @return: successful result is a list of IPs that were added @rtype: Twisted deferred """ self.log.debug( "findRemoteDeviceInfo.inner: Doing SNMP lookup on device %s", ip) yield self.config().callRemote('getSnmpConfig', devicePath) communities, ports, version, timeout, retries = driver.next() self.log.debug( "findRemoteDeviceInfo.inner: override acquired community strings" ) # Override the device class communities with the ones set on # this device, if they exist if deviceSnmpCommunities is not None: communities = deviceSnmpCommunities # Reverse the communities so that ones earlier in the list have a # higher weight. communities.reverse() configs = [] for i, community in enumerate(communities): for port in ports: port = int(port) configs.append( SnmpV1Config(ip, weight=i, port=port, timeout=timeout, retries=retries, community=community)) configs.append( SnmpV2cConfig(ip, weight=i + 100, port=port, timeout=timeout, retries=retries, community=community)) yield SnmpAgentDiscoverer().findBestConfig(configs) driver.next() self.log.debug("Finished SNMP lookup on device %s", ip)
def inner(driver): """ Twisted driver class to iterate through devices @param driver: Zenoss driver @type driver: Zenoss driver @return: successful result is a list of IPs that were added @rtype: Twisted deferred """ log.info("Rediscovering SNMP connection info for %s", self.device.id) communities = list(self.device.zSnmpCommunities) communities.reverse() ports = self.device.zSnmpDiscoveryPorts ports = ports if ports else [self.device.zSnmpPort] configs = [] weight = 0 for community in communities: for port in ports: weight += 1 port = int(port) configs.append( SnmpV1Config(self.device.manageIp, weight=weight, port=port, timeout=self.connInfo.zSnmpTimeout, retries=self.connInfo.zSnmpTries, community=community)) configs.append( SnmpV2cConfig(self.device.manageIp, weight=weight + 1000, port=port, timeout=self.connInfo.zSnmpTimeout, retries=self.connInfo.zSnmpTries, community=community)) yield SnmpAgentDiscoverer().findBestConfig(configs) driver.next()
def findRemoteDeviceInfo(self, ip, devicePath, deviceSnmpCommunities=None): """ Scan a device for ways of naming it: PTR DNS record or a SNMP name @param ip: IP address @type ip: string @param devicePath: where in the DMD to put any discovered devices @type devicePath: string @param deviceSnmpCommunities: Optional list of SNMP community strings to try, overriding those set on the device class @type deviceSnmpCommunities: list @return: result is None or a tuple containing (community, port, version, snmp name) @rtype: deferred: Twisted deferred """ self.log.debug("Doing SNMP lookup on device %s", ip) snmp_conf = \ yield self.config().callRemote('getSnmpConfig', devicePath) configs = [] ports = snmp_conf.get('zSnmpDiscoveryPorts') \ or [snmp_conf['zSnmpPort']] timeout, retries = snmp_conf['zSnmpTimeout'], snmp_conf['zSnmpTries'] if snmp_conf['zSnmpVer'] == SnmpV3Config.version: for port in ports: if snmp_conf['zSnmpPrivType'] and snmp_conf['zSnmpAuthType']: configs.append( SnmpV3Config( ip, port=port, timeout=timeout, retries=retries, weight=3, securityName=snmp_conf['zSnmpSecurityName'], authType=snmp_conf['zSnmpAuthType'], authPassphrase=snmp_conf['zSnmpAuthPassword'], privType=snmp_conf['zSnmpPrivType'], privPassphrase=snmp_conf['zSnmpPrivPassword'])) elif snmp_conf['zSnmpAuthType']: configs.append( SnmpV3Config( ip, port=port, timeout=timeout, retries=retries, weight=2, securityName=snmp_conf['zSnmpSecurityName'], authType=snmp_conf['zSnmpAuthType'], authPassphrase=snmp_conf['zSnmpAuthPassword'])) else: configs.append( SnmpV3Config( ip, port=port, timeout=timeout, retries=retries, weight=1, securityName=snmp_conf['zSnmpSecurityName'])) else: self.log.debug("Override acquired community strings") # Override the device class communities with the ones set on # this device, if they exist communities = snmp_conf['zSnmpCommunities'] if deviceSnmpCommunities is not None: communities = deviceSnmpCommunities # Reverse the communities so that ones earlier in the list have a # higher weight. communities.reverse() for i, community in enumerate(communities): for port in ports: port = int(port) configs.append( SnmpV1Config(ip, weight=i, port=port, timeout=timeout, retries=retries, community=community)) configs.append( SnmpV2cConfig(ip, weight=i + 100, port=port, timeout=timeout, retries=retries, community=community)) config = yield SnmpAgentDiscoverer().findBestConfig(configs) self.log.debug("Finished SNMP lookup on device %s", ip) defer.returnValue(config)
def inner(driver): """ Twisted driver class to iterate through devices @param driver: Zenoss driver @type driver: Zenoss driver @return: successful result is a list of IPs that were added @rtype: Twisted deferred """ self.log.debug( "findRemoteDeviceInfo.inner: Doing SNMP lookup on device %s", ip) yield self.config().callRemote('getSnmpConfig', devicePath) snmp_conf = driver.next() configs = [] ports = snmp_conf.get('zSnmpDiscoveryPorts') or [ snmp_conf['zSnmpPort'] ] timeout, retries = snmp_conf['zSnmpTimeout'], snmp_conf[ 'zSnmpTries'] if snmp_conf['zSnmpVer'] == SnmpV3Config.version: for port in ports: if snmp_conf['zSnmpPrivType'] and snmp_conf[ 'zSnmpAuthType']: configs.append( SnmpV3Config( ip, port=port, timeout=timeout, retries=retries, weight=3, securityName=snmp_conf['zSnmpSecurityName'], authType=snmp_conf['zSnmpAuthType'], authPassphrase=snmp_conf['zSnmpAuthPassword'], privType=snmp_conf['zSnmpPrivType'], privPassphrase=snmp_conf['zSnmpPrivPassword'])) elif snmp_conf['zSnmpAuthType']: configs.append( SnmpV3Config( ip, port=port, timeout=timeout, retries=retries, weight=2, securityName=snmp_conf['zSnmpSecurityName'], authType=snmp_conf['zSnmpAuthType'], authPassphrase=snmp_conf['zSnmpAuthPassword'])) else: configs.append( SnmpV3Config( ip, port=port, timeout=timeout, retries=retries, weight=1, securityName=snmp_conf['zSnmpSecurityName'])) else: self.log.debug( "findRemoteDeviceInfo.inner: override acquired community strings" ) # Override the device class communities with the ones set on # this device, if they exist communities = snmp_conf['zSnmpCommunities'] if deviceSnmpCommunities is not None: communities = deviceSnmpCommunities # Reverse the communities so that ones earlier in the list have a # higher weight. communities.reverse() for i, community in enumerate(communities): for port in ports: port = int(port) configs.append( SnmpV1Config(ip, weight=i, port=port, timeout=timeout, retries=retries, community=community)) configs.append( SnmpV2cConfig(ip, weight=i + 100, port=port, timeout=timeout, retries=retries, community=community)) yield SnmpAgentDiscoverer().findBestConfig(configs) driver.next() self.log.debug("Finished SNMP lookup on device %s", ip)