|
HOME | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | 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 Set |
getModulesInfo()
|
static boolean |
isMibFileLoaded()
Tests if there's at least one mib file already loaded |
static boolean |
isMibFileLoaded(String fileName)
Checks if the passed mib file has been 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(Reader[] readers,
boolean isStrict)
Loads multiple MIB files. |
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,
boolean appendDotZero)
Looks up OID for passed mibNodeName , case insensitive. |
static SnmpOID |
lookupOID(String mibNodeName,
String mibVersion)
Looks up OID for passed mibNodeName , case insensitive. |
static SnmpOID |
lookupOID(String mibNodeName,
String mibVersion,
boolean appendDotZero)
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(Reader[] readers,
boolean isStrict)
Parses MIBs loaded from Reader array. |
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 |
translateSnmpV1Trap(SnmpOID enterprise,
int generic,
int specific)
Returns the SNMPv1 trap name defined in the MIB file. |
static String |
translateSnmpV1Trap(SnmpV1Trap trap)
Returns the SNMPv1 trap name defined in the MIB file. |
static String |
translateValue(MibTreeNode node,
String value)
|
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 names
IOException
MibParseException
loadMib(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 file
IOException
MibParseException
loadMib(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.
IOException
MibParseException
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.
IOException
MibParseException
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 happens
IOException
- raised if mib file not found
MibParseException
- 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 found
MibParseException
- 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 file
IOException
- raised if mib file not found
MibParseException
- 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 found
MibParseException
- raised if mib file is corruptedpublic static void loadMib(Reader r, boolean isStrict) throws IOException, MibParseException
IOException
MibParseException
public static void loadMib(Reader r, boolean isStrict, String mibVersion) throws IOException, MibParseException
IOException
MibParseException
public static void loadMibs(Reader[] readers, boolean isStrict) throws IOException, MibParseException
readers
- Reader objects for loading MIBsisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log file
IOException
MibParseException
loadMib(java.lang.String)
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(String fileName)
fileName
- fully qualified file name of a MIBpublic 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 name
public static SnmpOID lookupOID(String mibNodeName, boolean appendDotZero)
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.
appendDotZero
- if true, append ".0" to the returned scalar variable.mibNodeName
- mib node name
public 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 SnmpOID lookupOID(String mibNodeName, String mibVersion, boolean appendDotZero)
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 nameappendDotZero
- if true, append ".0" to the returned scalar variable.mibVersion
- 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 translated
public static String translateSnmpV1Trap(SnmpV1Trap trap)
public static String translateSnmpV1Trap(SnmpOID enterprise, int generic, int specific)
public 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(MibTreeNode node, String value)
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 MIB
IOException
MibParseException
loadMib(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 file
IOException
MibParseException
public static MibTreeNode parseMibs(Reader[] readers, boolean isStrict) throws IOException, MibParseException
readers
- Reader arrayisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log file
IOException
MibParseException
public 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 file
IOException
MibParseException
public static MibTreeNode parseMibs(String[] fileNames) throws IOException, MibParseException
fileNames
- file names of the MIBs
IOException
MibParseException
parseMibs(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 file
IOException
MibParseException
public static MibTreeNode[] parseMibsWithoutMerge(String[] fileNames) throws IOException, MibParseException
fileNames
- file names of the MIBs
fileNames
IOException
MibParseException
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 file
fileNames
IOException
MibParseException
public static Set getModulesInfo()
|
HOME | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |