def snmp_f5(**kwargs): ip = str(kwargs['ip']) community = str(kwargs['community']) model = str(network.snmp(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(network.snmp(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(ip, community, parent): oid = (1, 3, 6, 1, 4, 1, 343, 2, 19, 1, 2, 10, 12, 0) # Max blades message = network.snmp(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(network.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 _cisco_snmp_model(model_oid, sn_oid, **kwargs): ip = str(kwargs['ip']) community = str(kwargs['community']) model = network.snmp(ip, community, model_oid, attempts=2, timeout=3) sn = network.snmp(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) 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 = network.snmp(ip, community, sn_oid, attempts=2, timeout=3) or \ network.snmp(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 = network.snmp(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