getMibTableInfo.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:3k
源码类别:

SNMP编程

开发平台:

C/C++

  1. /* $Id: getMibTableInfo.src,v 1.3 2002/09/09 05:43:43 pushpar Exp $ */ 
  2. /*
  3.  * @(#)getMibTableInfo.java
  4.  * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
  5.  * Please read the associated COPYRIGHTS file for more details.
  6.  */
  7. /**
  8.  * This is an example program to explain how to use some of the methods of 
  9.  * the mibs  package specific to Table nodes.
  10.  * The user could run this application by giving the Usage.
  11.  *  
  12.  * java getMibTableInfo [-m MIB_files] OID   
  13.  *
  14.  * If the oid is not starting with a dot (.) it will be prefixed by .1.3.6.1.2.1 .
  15.  * So the entire OID of 1.1.0 will become .1.3.6.1.2.1.1.1.0 . You can also
  16.  * give the entire OID .
  17.  * 
  18.  *
  19.  * Options:
  20.  * [-d]                - Debug output. By default off.
  21.  * -m   <MIBfile>      - MIB files.To load multiple mibs give within double quotes files seperated by a blank space. Mandatory.      
  22.  * <OID>  Mandatory    - Object Identifier.
  23.  */
  24. import com.adventnet.snmp.mibs.*;
  25. import com.adventnet.snmp.snmp2.*;
  26. public class getMibTableInfo {
  27. private static final int DEBUG = 0;
  28. private static final int MIBS = 1;
  29. public static void main(String args[]) {
  30. // Take care of getting options     
  31. String usage = "getMibTableInfo -m <MIB_files> OID";
  32. String options[] = { "-d", "-m" };
  33. String values[] = { "None", null};
  34. ParseOptions opt = new ParseOptions(args,options,values, usage);
  35. if (opt.remArgs.length<1 || opt.remArgs.length > 1) opt.usage_error();
  36. MibOperations mibOps = new MibOperations();
  37. if (values[DEBUG].equals("Set")) mibOps.setDebug( true );
  38. // To load MIBs from compiled file
  39. mibOps.setLoadFromCompiledMibs(true);
  40. // Loading MIBS
  41. if (values[MIBS] != null) {
  42. try {
  43. System.out.println("Loading MIBs: "+values[MIBS]);
  44. mibOps.loadMibModules(values[MIBS]);
  45. } catch (Exception ex) {
  46. System.out.println("Error loading MIBs: "+ex);
  47. }
  48. }else {
  49. System.out.println("Loading MIBs is mandatory");
  50. System.exit(0);
  51. }
  52. SnmpOID oid = mibOps.getSnmpOID(opt.remArgs[0]);
  53. MibNode node = mibOps.getMibNode(oid);
  54. if(node == null) {
  55. System.out.println("Invalid OID or the Node " + opt.remArgs[0] + " is not avialable");
  56. System.exit(0);
  57. }
  58. //check for table
  59. if(node.isTable()) {
  60. System.out.println("nThe node is a Table");
  61. System.out.println("nThe Table Entry: " + node.getChild(1));
  62. System.out.println("nTable Items: " + node.getTableItems());
  63. }else if(node.isTableEntry()) {// check for table entry
  64. System.out.println("nThe node is a TableEntry");
  65. System.out.println("nisAugmentedEntry: " + node.getIsAugmented());
  66. System.out.println("nAugments Node " + node.getAugments());  
  67. System.out.println("nIndex Names: " + node.getIndexNames());
  68. }else if(node.isTableColumn()) {// check for table column
  69. System.out.println("nThe node ia a Table Column");
  70. System.out.println("nisReadable: " + node.isReadable());
  71. System.out.println("nisWritable: " + node.isWriteable());
  72. System.out.println("nIndexes for the table column: " + node.getIndexes(mibOps));
  73. }else {
  74. System.out.println("nThe given OID is not a table or table entry or a table column");
  75. }
  76. }
  77. }