📄 ciscomodule.java
字号:
package no.ntnu.nav.getDeviceData.deviceplugins.CiscoModule;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.regex.Matcher;import java.util.regex.Pattern;import no.ntnu.nav.ConfigParser.ConfigParser;import no.ntnu.nav.SimpleSnmp.SimpleSnmp;import no.ntnu.nav.SimpleSnmp.TimeoutException;import no.ntnu.nav.getDeviceData.Netbox;import no.ntnu.nav.getDeviceData.dataplugins.DataContainer;import no.ntnu.nav.getDeviceData.dataplugins.DataContainers;import no.ntnu.nav.getDeviceData.dataplugins.Module.Module;import no.ntnu.nav.getDeviceData.dataplugins.Module.ModuleContainer;import no.ntnu.nav.getDeviceData.dataplugins.ModuleMon.ModuleMonContainer;import no.ntnu.nav.getDeviceData.dataplugins.Netbox.NetboxContainer;import no.ntnu.nav.getDeviceData.dataplugins.Netbox.NetboxData;import no.ntnu.nav.getDeviceData.deviceplugins.DeviceHandler;import no.ntnu.nav.logger.Log;import no.ntnu.nav.util.MultiMap;import no.ntnu.nav.util.util;/** * <p> * DeviceHandler for collecting Cisco module info. * </p> * * <p> * This plugin handles the following OID keys: * </p> * * <p> * <ui> * <li>cCard*</li> * <li>cL3*</li> * <li>catModule*</li> * </ul> * </p> */public class CiscoModule implements DeviceHandler{ public static final boolean DEBUG = false; public static final int HANDLE_PRI_MODULE = -20; private static String[] canHandleOids = { "cChassisId", "cCardSlotNumber", "cL3Serial", "cL3Model", "cL3HwVer", "cL3FwVer", "cL3SwVer", "catModuleModel", "catModuleHwVer", "catModuleFwVer", "catModuleSwVer", "catModuleSerial", "physClass", "physSwVer", "physDescr", "physSerial", "physHwVer", "physFwVer", "physModelName", }; SimpleSnmp sSnmp; public int canHandleDevice(Netbox nb) { int v = nb.isSupportedOids(canHandleOids) ? HANDLE_PRI_MODULE : NEVER_HANDLE; Log.d("CMOD_CANHANDLE", "CHECK_CAN_HANDLE", "Can handle device: " + v); return v; } public void handleDevice(Netbox nb, SimpleSnmp sSnmp, ConfigParser cp, DataContainers containers) throws TimeoutException { Log.setDefaultSubsystem("CMOD_DEVHANDLER"); NetboxContainer nc; { DataContainer dc = containers.getContainer("NetboxContainer"); if (dc == null) { Log.w("NO_CONTAINER", "No NetboxContainer found, plugin may not be loaded"); return; } if (!(dc instanceof NetboxContainer)) { Log.w("NO_CONTAINER", "Container is not a NetboxContainer! " + dc); return; } nc = (NetboxContainer)dc; } ModuleContainer mc; { DataContainer dc = containers.getContainer("ModuleContainer"); if (dc == null) { Log.w("NO_CONTAINER", "No ModuleContainer found, plugin may not be loaded"); return; } if (!(dc instanceof ModuleContainer)) { Log.w("NO_CONTAINER", "Container is not a ModuleContainer! " + dc); return; } mc = (ModuleContainer)dc; } ModuleMonContainer mmc; { DataContainer dc = containers.getContainer("ModuleMonContainer"); if (dc == null) { Log.w("NO_CONTAINER", "No ModuleMonContainer found, plugin may not be loaded"); return; } if (!(dc instanceof ModuleMonContainer)) { Log.w("NO_CONTAINER", "Container is not a ModuleMonContainer! " + dc); return; } mmc = (ModuleMonContainer)dc; } this.sSnmp = sSnmp; boolean fetch = processCiscoModule(nb, nc, mc, mmc); // Commit data if (fetch) { mc.commit(); } } /* * Cisco modules * */ boolean processCiscoModule(Netbox nb, NetboxContainer nc, ModuleContainer mc, ModuleMonContainer mmc) throws TimeoutException { /* "catModuleModel", "catModuleHwVer", "catModuleFwVer", "catModuleSwVer", "catModuleSerial", */ /* "cCardIndex", "cCardDescr", "cCardSerial", "cCardSlotNumber", "cCardContainedByIndex", */ /* "cL3Serial", "cL3Model", "cl3HwVer", "cl3SwVer", */ /* Highest pri "physClass", "physSwVer", "physDescr", "physName", "physSerial", "physHwVer", "physFwVer", "physModelName", "physParentRelPos", */ // Try to fetch the serial for the chassis if (nc.netboxDataFactory(nb).getSerial() == null) { List chassisIdList = sSnmp.getAll(nb.getOid("cChassisId"), true); if (chassisIdList != null && !chassisIdList.isEmpty()) { String[] s = (String[])chassisIdList.get(0); nc.netboxDataFactory(nb).setSerial(s[1]); } } // HwVer for the chassis if (nc.netboxDataFactory(nb).getHwVer() == null) { List chassisVerList = sSnmp.getAll(nb.getOid("cChassisVersion"), true); if (chassisVerList != null && !chassisVerList.isEmpty()) { String[] s = (String[])chassisVerList.get(0); nc.netboxDataFactory(nb).setHwVer(s[1]); Log.d("CCARD_OID", "Set chassis HwVer to " + s[1]); } } // The card OIDs Map cardSlotNum = sSnmp.getAllMap(nb.getOid("cCardSlotNumber")); // The cL3 OIDs Map cl3Serial = sSnmp.getAllMap(nb.getOid("cL3Serial"), true); Map cl3Model = sSnmp.getAllMap(nb.getOid("cL3Model"), true); Map cl3HwVer = sSnmp.getAllMap(nb.getOid("cL3HwVer"), true); Map cl3FwVer = sSnmp.getAllMap(nb.getOid("cL3FwVer"), true); Map cl3SwVer = sSnmp.getAllMap(nb.getOid("cL3SwVer"), true); // The catModule OIDs Map catModModel = sSnmp.getAllMap(nb.getOid("catModuleModel"), true); Map catModHwVer = sSnmp.getAllMap(nb.getOid("catModuleHwVer"), true); Map catModFwVer = sSnmp.getAllMap(nb.getOid("catModuleFwVer"), true); Map catModSwVer = sSnmp.getAllMap(nb.getOid("catModuleSwVer"), true); Map catModSerial = sSnmp.getAllMap(nb.getOid("catModuleSerial"), true); // catModule* if (catModModel != null) { for (Iterator it = catModModel.entrySet().iterator(); it.hasNext();) { Map.Entry me = (Map.Entry)it.next(); String module = (String)me.getKey(); Log.d("CATMOD_OID", "Created module " + module + " from catModModel"); mc.moduleFactory(module).setModel((String)me.getValue()); } } if (catModHwVer != null) { for (Iterator it = catModHwVer.entrySet().iterator(); it.hasNext();) { Map.Entry me = (Map.Entry)it.next(); String module = (String)me.getKey(); mc.moduleFactory(module).setHwVer((String)me.getValue()); Log.d("CATMOD_OID", "Set HwVer for module " + module + " to " + (String)me.getValue()); } } if (catModFwVer != null) { for (Iterator it = catModFwVer.entrySet().iterator(); it.hasNext();) { Map.Entry me = (Map.Entry)it.next(); String module = (String)me.getKey(); mc.moduleFactory(module).setFwVer((String)me.getValue()); } } if (catModSwVer != null) { for (Iterator it = catModSwVer.entrySet().iterator(); it.hasNext();) { Map.Entry me = (Map.Entry)it.next(); String module = (String)me.getKey(); mc.moduleFactory(module).setSwVer((String)me.getValue()); } } if (catModSerial != null) { for (Iterator it = catModSerial.entrySet().iterator(); it.hasNext();) { Map.Entry me = (Map.Entry)it.next(); String module = (String)me.getKey(); mc.moduleFactory(module).setSerial((String)me.getValue()); } } // cCard* if (cardSlotNum != null) { Map cardDescr = sSnmp.getAllMap(nb.getOid("cCardDescr"), true); Map cardSerial = sSnmp.getAllMap(nb.getOid("cCardSerial"), true); Map cardHwVer = sSnmp.getAllMap(nb.getOid("cCardHwVersion"), true); Map cardSwVer = sSnmp.getAllMap(nb.getOid("cCardSwVersion"), true); Map cardContainedByIndex = sSnmp.getAllMap(nb.getOid("cCardContainedByIndex")); for (Iterator it = cardSlotNum.entrySet().iterator(); it.hasNext();) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -