def _cisco_snmp_model(model_oid, sn_oid, **kwargs): ip = str(kwargs['ip']) version = kwargs.get('snmp_version') if version == '3': community = SNMP_V3_AUTH else: community = str(kwargs['community']) model = snmp_command( ip, community, model_oid, attempts=2, timeout=3, snmp_version=version, ) sn = snmp_command( ip, community, sn_oid, attempts=2, timeout=3, snmp_version=version, ) if not (model and sn): return False, "silent.", kwargs sn = unicode(sn[0][1]) model = 'Cisco %s' % unicode(model[0][1]) dev = Device.create(sn=sn, model_name=model, model_type=DeviceType.switch) ip_address = IPAddress.objects.get(address=str(ip)) ip_address.device = dev ip_address.is_management = True ip_address.save() return True, sn, kwargs
def _snmp_f5(ip_address, snmp_name, snmp_community): if '.f5app' not in snmp_name: raise Error('The SNMP name `%s` is not supported by this plugin.' % ( snmp_name, )) try: model = str( snmp_command( ip_address, snmp_community, [int(i) for i in '1.3.6.1.4.1.3375.2.1.3.5.2.0'.split('.')], attempts=1, timeout=0.5, )[0][1], ) sn = str( snmp_command( ip_address, snmp_community, [int(i) for i in '1.3.6.1.4.1.3375.2.1.3.3.3.0'.split('.')], attempts=1, timeout=0.5, )[0][1], ) except TypeError: raise Error('No answer.') except IndexError: raise Error('Incorrect answer.') result = { 'type': str(DeviceType.load_balancer), 'model_name': 'F5 %s' % model, } if sn not in SERIAL_BLACKLIST: result['serial_number'] = sn return result
def _snmp_f5(ip_address, snmp_name, snmp_community): if '.f5app' not in snmp_name: raise Error('The SNMP name `%s` is not supported by this plugin.' % (snmp_name, )) try: model = str( snmp_command( ip_address, snmp_community, [int(i) for i in '1.3.6.1.4.1.3375.2.1.3.5.2.0'.split('.')], attempts=1, timeout=0.5, )[0][1], ) sn = str( snmp_command( ip_address, snmp_community, [int(i) for i in '1.3.6.1.4.1.3375.2.1.3.3.3.0'.split('.')], attempts=1, timeout=0.5, )[0][1], ) except TypeError: raise Error('No answer.') except IndexError: raise Error('Incorrect answer.') return { 'type': str(DeviceType.load_balancer), 'model_name': 'F5 %s' % model, 'serial_number': sn, }
def snmp_f5(**kwargs): ip = str(kwargs['ip']) community = str(kwargs['community']) model = str(snmp_command(ip, community, [int(i) for i in '1.3.6.1.4.1.3375.2.1.3.5.2.0'.split('.')], attempts=1, timeout=0.5)[0][1]) sn = str(snmp_command(ip, community, [int(i) for i in '1.3.6.1.4.1.3375.2.1.3.3.3.0'.split('.')], attempts=1, timeout=0.5)[0][1]) return 'F5 %s' % model, sn
def snmp_f5(**kwargs): ip = str(kwargs["ip"]) community = str(kwargs["community"]) model = str( snmp_command( ip, community, [int(i) for i in "1.3.6.1.4.1.3375.2.1.3.5.2.0".split(".")], attempts=1, timeout=0.5 )[0][1] ) sn = str( snmp_command( ip, community, [int(i) for i in "1.3.6.1.4.1.3375.2.1.3.3.3.0".split(".")], attempts=1, timeout=0.5 )[0][1] ) return "F5 %s" % model, sn
def _snmp_modular_macs(ip_address, ip_address_is_management, snmp_community): oid = (1, 3, 6, 1, 4, 1, 343, 2, 19, 1, 2, 10, 12, 0) # Max blades message = snmp_command( ip_address, snmp_community, oid, attempts=1, timeout=0.5, ) max_blades = int(message[0][1]) blades_macs = {} for blade_no in range(1, max_blades + 1): oid = (1, 3, 6, 1, 4, 1, 343, 2, 19, 1, 2, 10, 202, 3, 1, 1, blade_no) blades_macs[blade_no] = set( snmp_macs( ip_address, snmp_community, oid, attempts=1, timeout=0.5, ), ) results = [] management_ip_addresses = [] if ip_address_is_management: management_ip_addresses.append(ip_address) for i, macs in blades_macs.iteritems(): unique_macs = macs for j, other_macs in blades_macs.iteritems(): if i == j: continue unique_macs -= other_macs if unique_macs: results.append({ 'type': unicode(DeviceType.blade_server), 'model_name': 'Intel Modular Blade', 'mac_addresses': [ MACAddressField.normalize(mac) for mac in unique_macs ], 'management_ip_addresses': management_ip_addresses, 'chassis_position': i, }) return results
def _snmp_modular(ip, community, parent): oid = (1, 3, 6, 1, 4, 1, 343, 2, 19, 1, 2, 10, 12, 0) # Max blades message = snmp_command(ip, community, oid, attempts=1, timeout=0.5) max_blades = int(message[0][1]) blades_macs = {} for blade_no in range(1, max_blades + 1): oid = (1, 3, 6, 1, 4, 1, 343, 2, 19, 1, 2, 10, 202, 3, 1, 1, blade_no) blades_macs[blade_no] = set(snmp_macs(ip, community, oid, attempts=1, timeout=0.5)) for i, macs in blades_macs.iteritems(): unique_macs = macs for j, other_macs in blades_macs.iteritems(): if i == j: continue unique_macs -= other_macs ethernets = [Eth('Intel Modular MAC', mac, speed=None) for mac in unique_macs] if ethernets: dev = Device.create( name='Intel Modular Blade', model_name='Intel Modular Blade', model_type=DeviceType.blade_server, ethernets=ethernets, management=parent.management, chassis_position=i, position = str(i), parent=parent, ) dev.save(update_last_seen=True)
def _snmp_modular_macs(ip_address, ip_address_is_management, snmp_community): oid = (1, 3, 6, 1, 4, 1, 343, 2, 19, 1, 2, 10, 12, 0) # Max blades message = snmp_command( ip_address, snmp_community, oid, attempts=1, timeout=0.5, ) max_blades = int(message[0][1]) blades_macs = {} for blade_no in range(1, max_blades + 1): oid = (1, 3, 6, 1, 4, 1, 343, 2, 19, 1, 2, 10, 202, 3, 1, 1, blade_no) blades_macs[blade_no] = set( snmp_macs( ip_address, snmp_community, oid, attempts=1, timeout=0.5, ), ) results = [] management_ip_addresses = [] if ip_address_is_management: management_ip_addresses.append(ip_address) for i, macs in blades_macs.iteritems(): unique_macs = macs for j, other_macs in blades_macs.iteritems(): if i == j: continue unique_macs -= other_macs if unique_macs: results.append({ 'type': unicode(DeviceType.blade_server), 'model_name': 'Intel Modular Blade', 'mac_addresses': list(unique_macs), 'management_ip_addresses': management_ip_addresses, 'chassis_position': i, }) return results
def _snmp_modular(ip, community, parent): oid = (1, 3, 6, 1, 4, 1, 343, 2, 19, 1, 2, 10, 12, 0) # Max blades message = snmp_command(ip, community, oid, attempts=1, timeout=0.5) max_blades = int(message[0][1]) blades_macs = {} for blade_no in range(1, max_blades + 1): oid = (1, 3, 6, 1, 4, 1, 343, 2, 19, 1, 2, 10, 202, 3, 1, 1, blade_no) blades_macs[blade_no] = set(snmp_macs(ip, community, oid, attempts=1, timeout=0.5)) for i, macs in blades_macs.iteritems(): unique_macs = macs for j, other_macs in blades_macs.iteritems(): if i == j: continue unique_macs -= other_macs ethernets = [Eth('Intel Modular MAC', mac, speed=None) for mac in unique_macs] if ethernets: dev = Device.create( name='Intel Modular Blade', model_name='Intel Modular Blade', model_type=DeviceType.blade_server, ethernets=ethernets, management=parent.management, chassis_position=i, position = str(i), parent=parent, ) dev.save(update_last_seen=True, priority=SAVE_PRIORITY)
def _cisco_snmp_model(model_oid, sn_oid, **kwargs): ip = str(kwargs["ip"]) community = str(kwargs["community"]) model = snmp_command(ip, community, model_oid, attempts=2, timeout=3) sn = snmp_command(ip, community, sn_oid, attempts=2, timeout=3) if not (model and sn): return False, "silent.", kwargs sn = unicode(sn[0][1]) model = "Cisco %s" % unicode(model[0][1]) dev = Device.create(sn=sn, model_name=model, model_type=DeviceType.switch) ip_address = IPAddress.objects.get(address=str(ip)) ip_address.device = dev ip_address.is_management = True ip_address.save() return True, sn, kwargs
def nortel_snmp(**kwargs): sn_oid = (1, 3, 6, 1, 4, 1, 1872, 2, 5, 1, 3, 1, 18, 0) uuid_oid = (1, 3, 6, 1, 4, 1, 1872, 2, 5, 1, 3, 1, 17, 0) substrings = ["nortel layer2-3 gbe switch", "bnt layer 2/3 copper gigabit ethernet " "switch module for ibm bladecenter"] snmp_name = kwargs.get('snmp_name', '') if not (snmp_name and any(substring in kwargs['snmp_name'].lower() for substring in substrings)): return False, "no match.", kwargs ip = str(kwargs['ip']) version = kwargs.get('snmp_version') if version == '3': community = SNMP_V3_AUTH else: community = str(kwargs['community']) sn = ( snmp_command( ip, community, sn_oid, attempts=2, timeout=3, snmp_version=version, ) or snmp_command( ip, community, uuid_oid, attempts=2, timeout=3, snmp_version=version, ) ) if not sn: return False, "silent.", kwargs sn = unicode(sn[0][1]) model = kwargs['snmp_name'] dev = Device.create(sn=sn, model_name=model, model_type=DeviceType.switch) ip_address, created = IPAddress.concurrent_get_or_create(address=str(ip)) ip_address.device = dev ip_address.is_management = True ip_address.save() kwargs['model'] = model kwargs['sn'] = sn return True, sn, kwargs
def _snmp(ip, community, oid, attempts=2, timeout=3, snmp_version='2c'): result = snmp_command(str(ip), community, oid, attempts=attempts, timeout=timeout, snmp_version=snmp_version) if result is None: message = None else: message = unicode(result[0][1]) return message
def nortel_snmp(**kwargs): sn_oid = (1, 3, 6, 1, 4, 1, 1872, 2, 5, 1, 3, 1, 18, 0) uuid_oid = (1, 3, 6, 1, 4, 1, 1872, 2, 5, 1, 3, 1, 17, 0) substrings = [ "nortel layer2-3 gbe switch", "bnt layer 2/3 copper gigabit ethernet " "switch module for ibm bladecenter" ] snmp_name = kwargs.get('snmp_name', '') if not (snmp_name and any(substring in kwargs['snmp_name'].lower() for substring in substrings)): return False, "no match.", kwargs ip = str(kwargs['ip']) version = kwargs.get('snmp_version') if version == '3': community = SNMP_V3_AUTH else: community = str(kwargs['community']) sn = (snmp_command( ip, community, sn_oid, attempts=2, timeout=3, snmp_version=version, ) or snmp_command( ip, community, uuid_oid, attempts=2, timeout=3, snmp_version=version, )) if not sn: return False, "silent.", kwargs sn = unicode(sn[0][1]) model = kwargs['snmp_name'] dev = Device.create(sn=sn, model_name=model, model_type=DeviceType.switch) ip_address, created = IPAddress.concurrent_get_or_create(address=str(ip)) ip_address.device = dev ip_address.is_management = True ip_address.save() kwargs['model'] = model kwargs['sn'] = sn return True, sn, kwargs
def nortel_snmp(**kwargs): sn_oid = (1,3,6,1,4,1,1872,2,5,1,3,1,18,0) uuid_oid = (1,3,6,1,4,1,1872,2,5,1,3,1,17,0) substring = "nortel layer2-3 gbe switch" if not ('snmp_name' in kwargs and kwargs['snmp_name'] and substring in kwargs['snmp_name'].lower()): return False, "no match.", kwargs ip = str(kwargs['ip']) version = kwargs.get('snmp_version') if version == '3': community = SNMP_V3_AUTH else: community = str(kwargs['community']) sn = ( snmp_command( ip, community, sn_oid, attempts=2, timeout=3, snmp_version=version, ) or snmp_command( ip, community, uuid_oid, attempts=2, timeout=3, snmp_version=version, ) ) if not sn: return False, "silent.", kwargs sn = unicode(sn[0][1]) model = kwargs['snmp_name'] dev = Device.create(sn=sn, model_name=model, model_type=DeviceType.switch) ip_address = IPAddress.objects.get(address=str(ip)) ip_address.device = dev ip_address.is_management = True ip_address.save() kwargs['model'] = model kwargs['sn'] = sn return True, sn, kwargs
def nortel_snmp(**kwargs): sn_oid = (1, 3, 6, 1, 4, 1, 1872, 2, 5, 1, 3, 1, 18, 0) uuid_oid = (1, 3, 6, 1, 4, 1, 1872, 2, 5, 1, 3, 1, 17, 0) substring = "nortel layer2-3 gbe switch" if not ('snmp_name' in kwargs and kwargs['snmp_name'] and substring in kwargs['snmp_name'].lower()): return False, "no match.", kwargs ip = str(kwargs['ip']) version = kwargs.get('snmp_version') if version == '3': community = SNMP_V3_AUTH else: community = str(kwargs['community']) sn = (snmp_command( ip, community, sn_oid, attempts=2, timeout=3, snmp_version=version, ) or snmp_command( ip, community, uuid_oid, attempts=2, timeout=3, snmp_version=version, )) if not sn: return False, "silent.", kwargs sn = unicode(sn[0][1]) model = kwargs['snmp_name'] dev = Device.create(sn=sn, model_name=model, model_type=DeviceType.switch) ip_address = IPAddress.objects.get(address=str(ip)) ip_address.device = dev ip_address.is_management = True ip_address.save() kwargs['model'] = model kwargs['sn'] = sn return True, sn, kwargs
def _snmp( ip, community, oid, attempts=2, timeout=3, snmp_version='2c', priv_protocol=cmdgen.usmDESPrivProtocol ): result = snmp_command( str(ip), community, oid, attempts=attempts, timeout=timeout, snmp_version=snmp_version, priv_protocol=priv_protocol, ) if result is None: message = None else: message = unicode(result[0][1]) return message
def juniper_snmp(**kwargs): sn_oid = (1, 3, 6, 1, 4, 1, 2636, 3, 1, 3, 0) model_oid = (1, 3, 6, 1, 4, 1, 2636, 3, 1, 2, 0) version = kwargs.get('snmp_version') if version == '3': community = SNMP_V3_AUTH else: community = str(kwargs['community']) substring = "juniper networks" if not ('snmp_name' in kwargs and kwargs['snmp_name'] and substring in kwargs['snmp_name'].lower()): return False, "no match.", kwargs ip = str(kwargs['ip']) sn = snmp_command( ip, community, sn_oid, attempts=2, timeout=3, snmp_version=version, ) model = snmp_command( ip, community, model_oid, attempts=2, timeout=3, snmp_version=version, ) if not sn or not model: return False, "silent.", kwargs sn = unicode(str(sn[0][1]), encoding='utf-8') model = unicode(str(model[0][1]), encoding='utf-8') dev = Device.create(sn=sn, model_name=model, model_type=DeviceType.switch) ip_address, created = IPAddress.concurrent_get_or_create(address=str(ip)) ip_address.device = dev ip_address.is_management = True ip_address.save() return True, sn, kwargs
def nortel_snmp(**kwargs): sn_oid = (1, 3, 6, 1, 4, 1, 1872, 2, 5, 1, 3, 1, 18, 0) uuid_oid = (1, 3, 6, 1, 4, 1, 1872, 2, 5, 1, 3, 1, 17, 0) substring = "nortel layer2-3 gbe switch" if not ("snmp_name" in kwargs and kwargs["snmp_name"] and substring in kwargs["snmp_name"].lower()): return False, "no match.", kwargs ip = str(kwargs["ip"]) community = str(kwargs["community"]) sn = snmp_command(ip, community, sn_oid, attempts=2, timeout=3) or snmp_command( ip, community, uuid_oid, attempts=2, timeout=3 ) if not sn: return False, "silent.", kwargs sn = unicode(sn[0][1]) model = kwargs["snmp_name"] dev = Device.create(sn=sn, model_name=model, model_type=DeviceType.switch) ip_address = IPAddress.objects.get(address=str(ip)) ip_address.device = dev ip_address.is_management = True ip_address.save() kwargs["model"] = model kwargs["sn"] = sn return True, sn, kwargs
def _snmp(ip, community, oid, attempts=2, timeout=3, snmp_version="2c"): is_up = False result = snmp_command(str(ip), community, oid, attempts=attempts, timeout=timeout, snmp_version=snmp_version) if result is None: message = "silent." else: message = unicode(result[0][1]) try: ip_address = IPAddress.objects.get(address=str(ip)) except IPAddress.DoesNotExist: message = "IP address not present in DB." pass else: ip_address.snmp_name = message ip_address.snmp_community = unicode(community) ip_address.save() is_up = True return is_up, message
def _snmp(ip, community, oid, attempts=2, timeout=3, snmp_version='2c'): is_up = False result = snmp_command(str(ip), community, oid, attempts=attempts, timeout=timeout, snmp_version=snmp_version) if result is None: message = 'silent.' else: message = unicode(result[0][1]) try: ip_address = IPAddress.objects.get(address=str(ip)) except IPAddress.DoesNotExist: message = "IP address not present in DB." pass else: ip_address.snmp_name = message ip_address.snmp_community = unicode(community) ip_address.save() is_up = True return is_up, message
def _snmp(ip, community, oid, attempts=2, timeout=3, snmp_version='2c', priv_protocol=cmdgen.usmDESPrivProtocol): result = snmp_command( str(ip), community, oid, attempts=attempts, timeout=timeout, snmp_version=snmp_version, priv_protocol=priv_protocol, ) if result is None: message = None else: message = unicode(result[0][1]) return message