📄 ciscomodule.java
字号:
if (cardContainedByIndex != null) { String containedBy = (String)cardContainedByIndex.get(cardIndex); if (containedBy != null && !"0".equals(containedBy)) continue; } try { if (Integer.parseInt(module) < 0) module = "0"; } catch (NumberFormatException e) { System.err.println("Error, module is not a number: " + module); e.printStackTrace(System.err); } Log.d("CCARD_OID", "Created module " + module + " from cCard"); Module m = mc.moduleFactory(module); if (cardDescr != null && m.getDescr() == null) m.setDescr((String)cardDescr.get(cardIndex)); if (cardSerial != null && m.getSerial() == null) m.setSerial((String)cardSerial.get(cardIndex)); if (cardHwVer != null && m.getHwVer() == null) { m.setHwVer((String)cardHwVer.get(cardIndex)); Log.d("CCARD_OID", "Set HwVer for module " + m.getModule() + " to " + (String)cardHwVer.get(cardIndex)); } if (cardSwVer != null && m.getSwVer() == null) m.setSwVer((String)cardSwVer.get(cardIndex)); } } // Find module translation using phys OIDs Map modTrans = new HashMap(); { Map physClass = sSnmp.getAllMap(nb.getOid("physClass"), false, 0, true); // Ask for oidToModuleMap if (physClass != null) { Map oidToModuleMapping = (Map)physClass.remove("OidToModuleMapping"); MultiMap classMap = util.reverse(physClass); // modules for (Iterator it = classMap.get("9").iterator(); it.hasNext();) { String id = (String)it.next(); int module; try { if (oidToModuleMapping != null && oidToModuleMapping.containsKey(id)) { module = Integer.parseInt((String)oidToModuleMapping.get(id)); } else { module = Integer.parseInt(id); if (module < 1000 || (module%1000) != 0) continue; // if physName is supported, try to get module number from this String physNameOid = nb.getOid("physName"); if (physNameOid != null) { boolean foundMod = false; List physNameL = sSnmp.getNext(physNameOid+"."+(module+1), 1, true, false); if (!physNameL.isEmpty()) { String portif = ((String[])physNameL.get(0))[1]; String modulePattern = "((.*?)(\\d+))/(\\d+)(/(\\d+))?"; if (portif.matches(modulePattern)) { Matcher m = Pattern.compile(modulePattern).matcher(portif); m.matches(); int newModule = Integer.parseInt(m.group(3)); modTrans.put(""+(module/1000), ""+newModule); foundMod = true; } } if (!foundMod) { physNameL = sSnmp.getNext(physNameOid+"."+(module), 1, true, false); if (!physNameL.isEmpty()) { String portif = ((String[])physNameL.get(0))[1]; try { int newModule = Integer.parseInt(portif); modTrans.put(""+(module/1000), ""+newModule); } catch (NumberFormatException exp) { Log.e("CMOD_PHYSOID", "The module number '" + portif + "' is not a valid integer (" + nb.getSysname() + ")"); } } } } } } catch (NumberFormatException e) { } } } } Log.d("MODTRANS", "" + modTrans); // cL3* { Set valid; if (cl3Serial != null && !(valid = getValidCL3Modules(cl3Serial)).isEmpty()) { for (Iterator it = valid.iterator(); it.hasNext();) { String module = (String)it.next(); String nModule = modTrans.containsKey(module) ? (String)modTrans.get(module) : module; Log.d("CL3_OID", "Created module " + nModule + " from cL3: " + cl3Serial.get(module+"000")); mc.moduleFactory(nModule).setSerial((String)cl3Serial.get(module+"000")); } } if (cl3Model != null && !(valid = getValidCL3Modules(cl3Model)).isEmpty()) { for (Iterator it = valid.iterator(); it.hasNext();) { String module = (String)it.next(); String nModule = modTrans.containsKey(module) ? (String)modTrans.get(module) : module; mc.moduleFactory(nModule).setDescr((String)cl3Model.get(module+"000")); } } if (cl3HwVer != null && !(valid = getValidCL3Modules(cl3HwVer)).isEmpty()) { for (Iterator it = valid.iterator(); it.hasNext();) { String module = (String)it.next(); String nModule = modTrans.containsKey(module) ? (String)modTrans.get(module) : module; mc.moduleFactory(nModule).setHwVer((String)cl3HwVer.get(module+"000")); Log.d("CL3_OID", "Set HwVer for module " + nModule + " to " + (String)cl3HwVer.get(module+"000")); } } if (cl3FwVer != null && !(valid = getValidCL3Modules(cl3FwVer)).isEmpty()) { for (Iterator it = valid.iterator(); it.hasNext();) { String module = (String)it.next(); String nModule = modTrans.containsKey(module) ? (String)modTrans.get(module) : module; mc.moduleFactory(nModule).setFwVer((String)cl3FwVer.get(module+"000")); } } if (cl3SwVer != null && !(valid = getValidCL3Modules(cl3SwVer)).isEmpty()) { for (Iterator it = valid.iterator(); it.hasNext();) { String module = (String)it.next(); String nModule = modTrans.containsKey(module) ? (String)modTrans.get(module) : module; mc.moduleFactory(nModule).setSwVer((String)cl3SwVer.get(module+"000")); } } } // The phys OIDs Map physClass = sSnmp.getAllMap(nb.getOid("physClass"), false, 0, true); // Ask for oidToModuleMap if (physClass != null) { Map physDescr = sSnmp.getAllMap(nb.getOid("physDescr"), true); Map physSerial = sSnmp.getAllMap(nb.getOid("physSerial"), true); Map physHwVer = sSnmp.getAllMap(nb.getOid("physHwVer"), true); Map physFwVer = sSnmp.getAllMap(nb.getOid("physFwVer"), true); Map physSwVer = sSnmp.getAllMap(nb.getOid("physSwVer"), true); Map physModelName = sSnmp.getAllMap(nb.getOid("physModelName"), true); //Map physParentPos = sSnmp.getAllMap(nb.getOid("physParentRelPos"), true); /* PhysicalClass 1:other 2:unknown 3:chassis 4:backplane 5:container 6:powerSupply 7:fan 8:sensor 9:module 10:port 11:stack */ Map oidToModuleMapping = (Map)physClass.remove("OidToModuleMapping"); MultiMap classMap = util.reverse(physClass); // chassis for (Iterator it = util.intSortedSetFactory(classMap.get("3")).iterator(); it.hasNext();) { String id = (String)it.next(); NetboxData nd = nc.netboxDataFactory(nb); if (nd.getSerial() == null && physSerial != null && physSerial.containsKey(id)) nd.setSerial((String)physSerial.get(id)); if (physHwVer != null && physHwVer.containsKey(id)) { String version = (String)physHwVer.get(id); if (version.length() > 0 && !"N/A".equals(version.toUpperCase())) { nd.setHwVer(version); Log.d("CMOD_PHYSOID", "Set HwVer for chassis to " + version); } } if (physFwVer != null && physFwVer.containsKey(id)) nd.setFwVer((String)physFwVer.get(id)); if (physSwVer != null && physSwVer.containsKey(id)) nd.setSwVer((String)physSwVer.get(id)); break; // Only do first } // modules for (Iterator it = classMap.get("9").iterator(); it.hasNext();) { String id = (String)it.next(); int module; try { if (oidToModuleMapping != null && oidToModuleMapping.containsKey(id)) { module = Integer.parseInt((String)oidToModuleMapping.get(id)); } else { module = Integer.parseInt(id); if (module < 1000 || (module%1000) != 0) continue; module /= 1000; } } catch (NumberFormatException e) { System.err.println("Working with " + nb + ", NumberFormatException: " + e); e.printStackTrace(System.err); continue; } if (module < 0) module = 0; if (modTrans.containsKey(""+module)) module = Integer.parseInt((String)modTrans.get(""+module)); if (mc.getModule(module) == null && !modTrans.containsKey(""+module)) { // Not allowed to create module Log.w("CMOD_PHYSOID", "Module " + module + " does not exist on netbox " + nb.getSysname() + ", skipping"); continue; } Log.d("CMOD_PHYSOID", "Created module " + module + " from Phys: " + (String)(physSerial != null ? physSerial.get(id) : "null")); Module m = mc.moduleFactory(module); if (physSerial != null && physSerial.containsKey(id) && m.getSerial() == null) m.setSerial((String)physSerial.get(id)); if (physHwVer != null && physHwVer.containsKey(id) && m.getHwVer() == null) { m.setHwVer((String)physHwVer.get(id)); Log.d("CMOD_PHYSOID", "Set HwVer for module " + m.getModule() + " to " + (String)physHwVer.get(id)); } if (physFwVer != null && physFwVer.containsKey(id) && m.getFwVer() == null) m.setFwVer((String)physFwVer.get(id)); if (physSwVer != null && physSwVer.containsKey(id) && m.getSwVer() == null) m.setSwVer((String)physSwVer.get(id)); if (physModelName != null && physModelName.containsKey(id) && m.getModel() == null) m.setModel((String)physModelName.get(id)); if (physDescr != null && physDescr.containsKey(id) && m.getDescr() == null) m.setDescr((String)physDescr.get(id)); } } /** * Iterate the list of known modules to find a module that may * represent the same device as the netbox (chassis) itself. * If such a module exists, we set its Fw/Hw/Sw versions equal to * those of the chassis, as many Cisco devices report inconsistent * version numbers across different MIBs. We only do this because * of a gDD design error which enables the coexistance of multiple * objects representing the same device in a single gDD process. */ for (Iterator it = mc.getModules(); it.hasNext();) { Module module = (Module) it.next(); NetboxData netbox = nc.netboxDataFactory(nb); if (module.getSerial() != null && netbox.getSerial() != null && module.getSerial().equals(netbox.getSerial())) { Log.d("CMOD_CLEANUP", "Module " + module.getModule() + " equals the chassis, setting versions equal to chassis"); module.setFwVer(netbox.getFwVer()); module.setHwVer(netbox.getHwVer()); module.setSwVer(netbox.getSwVer()); // No more than one module can equal the chassis, so we get out here break; } } Set moduleSet = mc.getModuleSet(); if (!moduleSet.isEmpty()) { for (Iterator it = moduleSet.iterator(); it.hasNext();) { String module = (String)it.next(); mmc.moduleUp(nb, module); } Log.d("CMOD_MON", "modulesUp: " + moduleSet); // Previously seen modules that we didn't find now, should be considered as down mmc.setUnknownDown(true); mmc.commit(); return true; } return false; } private Set getValidCL3Modules(Map m) { Set valid = new HashSet(); for (Iterator it = m.entrySet().iterator(); it.hasNext();) { Map.Entry me = (Map.Entry)it.next(); String module = (String)me.getKey(); String val = (String)me.getValue(); if (val == null || val.length() == 0 || "unknown".equalsIgnoreCase(val)) continue; try { int i = Integer.parseInt(module); if ((i % 1000) == 0) valid.add(Integer.toString(i / 1000)); } catch (NumberFormatException e) { } } return valid; } private static boolean isNumber(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -