def execute_cli(self): s = self.scripts.get_switch() match = self.rx_ver.search(s) if match.group("platform"): platform = match.group("platform") else: match = self.rx_ver_old.search(s) m = self.motd platform = self.rx_motd.search(m).group("platform") r = { "vendor": "DLink", "platform": get_platform(platform, match.group("hardware")), "version": match.group("version"), "attributes": { "Boot PROM": match.group("bootprom"), "HW version": match.group("hardware"), }, } ser = self.rx_ser.search(s) if ser and ser.group("serial") not in ["System", "Power"]: r["attributes"]["Serial Number"] = ser.group("serial") fwt = self.rx_fwt.search(s) if fwt and fwt.group("fwt") != match.group("version"): r["attributes"]["Firmware Type"] = fwt.group("fwt") return r
def execute_snmp(self): """ AGENT-MIB and AGENT-GENERAL-MIB - D-Link private MIBs """ platform = self.snmp.get("1.3.6.1.2.1.47.1.1.1.1.7.1", cached=True) hardware = self.snmp.get("1.3.6.1.2.1.47.1.1.1.1.8.1", cached=True) version = self.snmp.get("1.3.6.1.2.1.47.1.1.1.1.9.1", cached=True) bootprom = self.snmp.get("1.3.6.1.2.1.47.1.1.1.1.10.1", cached=True) serial = self.snmp.get("1.3.6.1.2.1.47.1.1.1.1.11.1", cached=True) # Found in some devices if str(bootprom) == str(version): bootprom = "" if not serial: # AGENT-GENERAL-MIB::agentSerialNumber serial = self.snmp.get("1.3.6.1.4.1.171.12.1.1.12.0", cached=True) # AGENT-GENERAL-MIB::agentFirmwareType fwt = self.snmp.get("1.3.6.1.4.1.171.12.1.1.13.0", cached=True) if not platform or not version: v = self.snmp.get(mib["SNMPv2-MIB::sysDescr.0"], cached=True) match = self.rx_platform.search(v) platform = match.group("platform") version = match.group("version") if version is None: # RMON2-MIB::probeSoftwareRev version = self.snmp.get("1.3.6.1.2.1.16.19.2", cached=True) if not version: version = self.snmp.get("1.3.6.1.2.1.16.19.2.0", cached=True) # RMON2-MIB::probeHardwareRev hardware = self.snmp.get("1.3.6.1.2.1.16.19.3", cached=True) if not hardware: hardware = self.snmp.get("1.3.6.1.2.1.16.19.3.0", cached=True) if not version: # AGENT-MIB::swMultiImageInfoEntry info_entry = "1.3.6.1.4.1.171.12.1.2.7.1" image_id = 0 for oid, v in self.snmp.getnext(info_entry, max_repetitions=10): # AGENT-MIB::swMultiImageInfoID if oid.startswith("%s.1" % info_entry): image_id = int(v) # AGENT-MIB::swMultiImageVersion if oid.startswith("%s.2.%s" % (info_entry, image_id)): version = v if version.startswith("Build "): version = version[6:] break r = { "vendor": "DLink", "platform": get_platform(platform, hardware), "version": version, "attributes": {}, } if bootprom: r["attributes"]["Boot PROM"] = bootprom if hardware: r["attributes"]["HW version"] = hardware if serial: r["attributes"]["Serial Number"] = serial if fwt and fwt != version: r["attributes"]["Firmware Type"] = fwt return r
def execute(self): r = [] stacks = [] s = self.scripts.get_switch() match = self.rx_dev.search(s) revision = match.group("revision") part_no = get_platform(match.group("part_no"), revision) p = { "type": "CHASSIS", "vendor": "DLINK", "part_no": [part_no], "revision": revision } ser = self.rx_ser.search(s) if (ser and ser.group("serial") != "System" and ser.group("serial") != "Power"): p["serial"] = ser.group("serial") p["description"] = self.rx_des.search(s).group("descr") try: s = self.cli("show stack_device") for match in self.rx_stack.finditer(s): stacks += [match.groupdict()] except self.CLISyntaxError: pass r += [p] box_id = 1 match = self.rx_mod.search(s) if match: p = { "type": "MODULE", "vendor": "DLINK", "part_no": [match.group("part_no")], } if match.group("descr"): p["description"] = match.group("descr") r += [p] match = self.rx_mod1.search(s) if match and match.group("part_no") != "None": p = { "type": "MODULE", "number": "1", "vendor": "DLINK", "part_no": [match.group("part_no")], } if match.group("descr"): p["description"] = match.group("descr") r += [p] match = self.rx_mod2.search(s) if match and match.group("part_no") != "None": p = { "type": "MODULE", "number": "2", "vendor": "DLINK", "part_no": [match.group("part_no")], } if match.group("descr"): p["description"] = match.group("descr") r += [p] try: s = self.cli("show module_info") for l in s.splitlines(): match = self.rx_mod3.search(l) if match and match.group("part_no") != "-": p = { "type": "MODULE", "number": match.group("number"), "vendor": "DLINK", "part_no": [match.group("part_no")], "description": [match.group("descr")], } r += [p] except self.CLISyntaxError: pass try: c = self.cli("show ports media_type") for match in self.rx_media_type.finditer(c): if match.group("unit") and match.group("unit") != box_id: box_id = match.group("unit") for i in stacks: if i["box_id"] == box_id: p = { "type": "CHASSIS", "vendor": "DLINK", "part_no": [i["part_no"]], "revision": i["revision"] } if i["serial"]: p["serial"] = i["serial"] r += [p] break vendor = match.group("vendor") part_no = match.group("part_no") description = match.group("part_no") revision = match.group("revision") mbd = int(match.group("mbd")) nm = int(match.group("nm")) if vendor in self.fake_vendors: vendor = "NONAME" part_no = 'NoName | Transceiver | ' if mbd == 1300 and nm == 1310: part_no = part_no + '1G | SFP BXU' elif mbd == 1300 and nm == 1550: part_no = part_no + '1G | SFP BXD' elif mbd == 1200 and nm == 1310: part_no = part_no + '1G | SFP BX10U' elif mbd >= 1200 and nm == 1490: part_no = part_no + '1G | SFP BX10D' elif mbd >= 1000 and nm == 0: if description.endswith(tuple([" EX", "-EX"])): part_no = part_no + '1G | SFP EX' elif description.endswith(tuple([" LH", "-LH"])): part_no = part_no + '1G | SFP LH' elif description.endswith(tuple([" LX", "-LX"])): part_no = part_no + '1G | SFP LX' elif description.endswith(tuple([" SX", "-SX"])): part_no = part_no + '1G | SFP SX' elif description.endswith(tuple([" T", "-T"])): part_no = part_no + '1G | SFP T' elif description.endswith(tuple([" TX", "-TX"])): part_no = part_no + '1G | SFP TX' elif description.endswith(tuple([" ZX", "-ZX"])): part_no = part_no + '1G | SFP ZX' else: part_no = part_no + '1G | SFP' elif mbd == 100 and nm == 1310: part_no = part_no + '100M | SFP BX100U' elif mbd == 100 and nm == 1550: part_no = part_no + '100M | SFP BX100D' else: part_no = part_no + 'Unknown SFP' i = { "type": "XCVR", "number": match.group("port"), "vendor": vendor, "part_no": part_no, "serial": match.group("serial"), "description": "%s, %dMbd, %dnm" % (description, mbd, nm) } if revision is not None: i["revision"] = revision r += [i] except self.CLISyntaxError: pass return r