|
HOME | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ireasoning.protocol.snmp.MibUtil
This class provides methods for parsing MIBs, translating numeric format oid to text format, translating numeric value to text value, lookup oid based on mib node name.
Examples:
MibUtil.loadMib2();//preload MIB-II (RFC1213) module MibUtil.loadMib("mibs/IF-MIB"); // translate node names into oids String s = MibUtil.translateOID(".1.3.6.1.2.1.2.2.1.7", false);//translate ifAdminStatus's OID assert(s, "ifAdminStatus");//assert that s equals to ifAdminStatus s = MibUtil.translateOID(".1.3.6.1.2.1.2.2.1.7", true); assert(s, ".iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifAdminStatus"); //look up oid value for node name s = MibUtil.lookupOID("sysDescr").toString(); assert(s, ".1.3.6.1.2.1.1.1.0"); s = MibUtil.lookupOID("system.sysDescr.0").toString(); assert(s, ".1.3.6.1.2.1.1.1.0"); s = MibUtil.lookupOID("ifAdminStatus.2").toString(); assert(s, ".1.3.6.1.2.1.2.2.1.7.2"); s = MibUtil.lookupOID("ifEntry.ifAdminStatus.2").toString(); assert(s, ".1.3.6.1.2.1.2.2.1.7.2"); //translate value s = MibUtil.translateValue(".1.3.6.1.2.1.2.2.1.7" , "1"); //for ifAdminStatus: { up(1), down(2) } assert(s, "up");
//Parse MIB and check node syntax type MibUtil.setResolveSyntax(true);//To resolve syntax type, so node.getRealSyntaxType() will return meaningful result MibTreeNode root = MibUtil.parseMib("mibs/IF-MIB"); //parse if-mib assert(root.getModuleIdentity(), "ifMIB"); assert(root.getModuleName(), "IF-MIB"); MibTreeNode node = (MibTreeNode) root.searchIgnoreCase("ifRcvAddressAddress"); assert(node.getRealSyntaxType() == MibTreeNode.SYN_STRING); //ifRcvAddressAddress is PhysAddress, which is an Octet String node = (MibTreeNode) root.searchIgnoreCase("ifRcvAddressStatus"); assert(node.getRealSyntaxType() == MibTreeNode.SYN_INTEGER);//ifRcvAddressStatus is RowStatus, which is an Integer32 node = (MibTreeNode) root.searchIgnoreCase("ifType"); assert(node.getRealSyntaxType() == MibTreeNode.SYN_INTEGER);//ifType is IANAifType, which is an Integer32 Syntax syn = node.getSyntax(); assert(syn.get("2"), "regular1822"); assert(syn.getType(), "IANAifType"); assert(syn.getSyntaxMap().size(), 54);
Method Summary | |
static boolean |
isMibFileLoaded()
Tests if there's at least one mib file already loaded |
static void |
loadMib(Reader r,
boolean isStrict)
Loads MIB file from Reader object |
static void |
loadMib(Reader r,
boolean isStrict,
String mibVersion)
Loads MIB file from Reader object |
static void |
loadMib(String fileName)
Loads mib file, so translateOID, translateValue, and other methods can take effect. |
static void |
loadMib(String fileName,
boolean isStrict)
Loads mib file, so translateOID, translateValue, and other methods can take effect. |
static void |
loadMib(String fileName,
boolean isStrict,
String mibVersion)
Loads mib file, so translateOID, translateValue, and other methods can take effect. |
static void |
loadMib(String fileName,
String mibVersion)
Loads mib file, so translateOID, translateValue, and other methods can take effect. |
static void |
loadMib2()
Loads MIB-II (RFC1213) from the built-in resource file. |
static void |
loadMibs(String[] fileNames)
Loads multiple MIB files. |
static void |
loadMibs(String[] fileNames,
boolean isStrict)
Loads multiple MIB files. |
static void |
loadMibs(String[] fileNames,
boolean isStrict,
String mibVersion)
Loads multiple MIB files. |
static void |
loadMibs(String[] fileNames,
String mibVersion)
Loads multiple MIB files. |
static SnmpOID |
lookupOID(String mibNodeName)
Looks up OID for passed mibNodeName , case insensitive. |
static SnmpOID |
lookupOID(String mibNodeName,
String mibVersion)
Looks up OID for passed mibNodeName , case insensitive. |
static MibTreeNode |
parseMib(Reader r,
boolean isStrict)
Returns the MIB tree representation in a MibTreeNode object, which is the root of the MIB tree. |
static MibTreeNode |
parseMib(String fileName)
Returns the MIB tree representation in a MibTreeNode object, which is the root of the MIB tree. |
static MibTreeNode |
parseMib(String fileName,
boolean isStrict)
Returns the MIB tree representation in a MibTreeNode object, which is the root of the MIB tree. |
static MibTreeNode |
parseMibs(String[] fileNames)
Parses passed MIB files strictly. |
static MibTreeNode |
parseMibs(String[] fileNames,
boolean isStrict)
Parses passed MIB files. |
static MibTreeNode[] |
parseMibsWithoutMerge(String[] fileNames)
Parses passed MIB files strictly. |
static MibTreeNode[] |
parseMibsWithoutMerge(String[] fileNames,
boolean isStrict)
Parses passed MIB files. |
static void |
setResolveSyntax(boolean b)
If true, MIB parser will resolve each MIB node's syntax to basic node syntax, such as OID, Octect String, Integer, etc. |
static NameValue |
translate(SnmpOID oid,
String value,
boolean fullName)
Translates oid and its value |
static NameValue |
translate(String oid,
String value,
boolean fullName)
Translates oid and its value |
static String |
translateOID(SnmpOID oid,
boolean fullName)
Translates oid from numeric to string format. |
static String |
translateOID(String oid,
boolean fullName)
Translates oid from numeric to string format. |
static String |
translateValue(SnmpOID oid,
String value)
Translates value part of SnmpVarBind. |
static String |
translateValue(String oid,
String value)
Translates value part of SnmpVarBind. |
static void |
unloadAllMibs()
Unloads all the loaded MIBs |
static void |
unloadMib(String fileName)
Unloads MIB file |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void setResolveSyntax(boolean b)
By default, MIB parser does not resolve syntax types.
This method needs to be invoked before loading a MIB for it to take effect.
MibTreeNode.getRealSyntaxType()
public static void loadMibs(String[] fileNames) throws IOException, MibParseException
fileNames
- MIB file namesloadMib(java.lang.String)
public static void loadMibs(String[] fileNames, boolean isStrict) throws IOException, MibParseException
fileNames
- MIB file namesisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log fileloadMib(java.lang.String)
public static void loadMibs(String[] fileNames, String mibVersion) throws IOException, MibParseException
fileNames
- MIB file namesmibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
Use null
if only no multiple versions of a mib.loadMib(java.lang.String)
public static void loadMibs(String[] fileNames, boolean isStrict, String mibVersion) throws IOException, MibParseException
fileNames
- MIB file namesisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log filemibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
Use null
if only no multiple versions of a mib.loadMib(java.lang.String)
public static void loadMib(String fileName) throws IOException, MibParseException
Both loadMib
and parseMib
methods can load MIB.
The difference between them is parseMib
returns a MibTreeNode
object
which can be used to navigate thru the MIB tree, but parseMib
doesn't build an
internal data model to facilitate the translation between oid and name.
fileName
- mib file name. If this file is already loaded, nothing happensIOException
- raised if mib file not foundMibParseException
- raised if mib file is corruptedparseMib(String fileName)
public static void loadMib(String fileName, String mibVersion) throws IOException, MibParseException
fileName
- mib file name. If this file is already loaded, nothing happensmibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
Use null
if only no multiple versions of a mib.IOException
- raised if mib file not foundMibParseException
- raised if mib file is corruptedpublic static void loadMib(String fileName, boolean isStrict) throws IOException, MibParseException
fileName
- mib file name. If this file is already loaded, nothing happensisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log fileIOException
- raised if mib file not foundMibParseException
- raised if mib file is corruptedpublic static void loadMib(String fileName, boolean isStrict, String mibVersion) throws IOException, MibParseException
fileName
- mib file name. If this file is already loaded, nothing happensisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log filemibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
Use null
if only no multiple versions of a mib.IOException
- raised if mib file not foundMibParseException
- raised if mib file is corruptedpublic static void loadMib(Reader r, boolean isStrict) throws IOException, MibParseException
public static void loadMib(Reader r, boolean isStrict, String mibVersion) throws IOException, MibParseException
public static void loadMib2()
public static void unloadMib(String fileName)
fileName
- mib file to unload. If this file was not loaded, nothing happenspublic static void unloadAllMibs()
public static boolean isMibFileLoaded()
public static SnmpOID lookupOID(String mibNodeName)
mibNodeName
, case insensitive. For instance, if
passed "sysUpTime" (or "sysuptime" "sysuptime.0" "system.sysUpTime" ".sysUpTime"), the returned OID will be
".1.3.6.1.2.1.1.3.0"; for "ifTable", it returns ".1.3.6.1.2.1.2.2" ; for "ifAdminStatus.2",
it returns ".1.3.6.1.2.1.2.2.1.7.2". If passed mibNodeName
is a numerical OID, it'll be returned
in a SnmpOID
object.
mibNodeName
- mib node namepublic static SnmpOID lookupOID(String mibNodeName, String mibVersion)
mibNodeName
, case insensitive. For instance, if
passed "sysUpTime" (or "sysuptime" "sysuptime.0" "system.sysUpTime" ".sysUpTime"), the returned OID will be
".1.3.6.1.2.1.1.3.0"; for "ifTable", it returns ".1.3.6.1.2.1.2.2" ; for "ifAdminStatus.2",
it returns ".1.3.6.1.2.1.2.2.1.7.2". If passed mibNodeName
is a numerical OID, it'll be returned
in a SnmpOID
object.
mibNodeName
- mib node namemibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
Use null
if only no multiple versions of a mib.public static String translateOID(String oid, boolean fullName)
fullName
- true to use fully qualified name. Otherwise only the
last of second to last field is returnedoid
- OID to be translated.public static String translateOID(SnmpOID oid, boolean fullName)
fullName
- true to use fully qualified name. Otherwise only the
last of second to last field is returnedoid
- OID to be translatedpublic static String translateValue(String oid, String value)
ifAdminStatus OBJECT-TYPE SYNTAX INTEGER { up(1), -- ready to pass packets down(2), testing(3) -- in some test mode }MibUtil.translateValue(".1.3.6.1.2.1.2.2.1.7.1" // oid of ifAdminStatus.1
public static String translateValue(SnmpOID oid, String value)
ifAdminStatus OBJECT-TYPE SYNTAX INTEGER { up(1), -- ready to pass packets down(2), testing(3) -- in some test mode }MibUtil.translateValue(".1.3.6.1.2.1.2.2.1.7.1" // oid of ifAdminStatus.1
public static NameValue translate(String oid, String value, boolean fullName)
translateValue(java.lang.String, java.lang.String)
,
translateOID(java.lang.String, boolean)
public static NameValue translate(SnmpOID oid, String value, boolean fullName)
translateValue(java.lang.String, java.lang.String)
,
translateOID(java.lang.String, boolean)
public static MibTreeNode parseMib(String fileName) throws IOException, MibParseException
fileName
- file name of the MIBloadMib(String fileName)
public static MibTreeNode parseMib(Reader r, boolean isStrict) throws IOException, MibParseException
r
- Reader object used to load MIB contentisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log filepublic static MibTreeNode parseMib(String fileName, boolean isStrict) throws IOException, MibParseException
fileName
- file name of the MIBisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log filepublic static MibTreeNode parseMibs(String[] fileNames) throws IOException, MibParseException
fileNames
- file names of the MIBsparseMibs(String[] fileNames, boolean isStrict)
public static MibTreeNode parseMibs(String[] fileNames, boolean isStrict) throws IOException, MibParseException
fileNames
- file names of the MIBsisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log filepublic static MibTreeNode[] parseMibsWithoutMerge(String[] fileNames) throws IOException, MibParseException
fileNames
- file names of the MIBsfileNames
public static MibTreeNode[] parseMibsWithoutMerge(String[] fileNames, boolean isStrict) throws IOException, MibParseException
fileNames
- file names of the MIBsisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log filefileNames
|
HOME | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |