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

SNMP编程

开发平台:

C/C++

  1. /* $Id: ejbLeafDetails.java,v 1.3 2002/09/09 05:43:16 tonyjpaul Exp $ */
  2. /*
  3.  * @(#)ejbLeafDetails.java
  4.  * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
  5.  * Please read the associated COPYRIGHTS file for more details.
  6.  */
  7. /**
  8.  *  Use ejb to do a get leafnode details based on the mibs loaded.
  9.  *  The ejb server is specified with the -EJBServer option
  10.  *  and defaults to localhost if not specified.
  11.  *  This allows loading MIBs as specified, and converts to/from
  12.  *  names for loaded MIB data.
  13.  *  Once a MIB is loaded on the server, its is available for subsequent
  14.  *  operations.  
  15.  *
  16.  * java ejbLeafDetails [options]  -m MIB_FILES  Numeric-Leaf-OID
  17.  *
  18.  */
  19. import com.adventnet.snmp.ejb.*;
  20. import com.adventnet.snmp.snmp2.*;
  21. import com.adventnet.snmp.mibs.*;
  22. import javax.naming.*;
  23. import weblogic.jndi.*;
  24. import java.util.Hashtable;
  25. import java.util.Vector;
  26. public class ejbLeafDetails  {
  27. static final int USM_SECURITY_MODEL = 3;
  28. public static void main(String args[]) {
  29. // Take care of getting options
  30.         String usage = "ejbLeafDetails [-SnmpEJBServer hostName] [-m MIB_files]  Numeric-LEAF-OID";
  31.         String options[] = { "-SnmpEJBServer",  "-m"};
  32.         String values[] = { null, null};
  33.         
  34.     ParseOptions opt = new ParseOptions(args,options,values, usage);
  35.     // check for at least hostname and one OID in remaining arguments
  36.     if (opt.remArgs.length<1) opt.usage_error();
  37. //This block performs a lookup on the EJBComponent.
  38. //The lookup is specific to the ApplicationServer used.
  39.  
  40. try {
  41.     Environment env = new Environment();
  42. if(values[0]!=null)
  43.   env.setProviderUrl(values[0]+"/MibOperationsEJB");
  44. else env.setProviderUrl("t3://localhost:7001/MibOperationsEJB");
  45.     Context ctx = env.getInitialContext();
  46.  
  47.     MibOperationsHome home = (MibOperationsHome) ctx.lookup("MibOperationsEJB");
  48. com.adventnet.snmp.ejb.MibOperations mibops = (com.adventnet.snmp.ejb.MibOperations) home.create();
  49. try {
  50. mibops.loadMibModules(values[1]);
  51. } catch (Exception e)  {
  52.             System.out.println("Exception : "+e);
  53.             System.exit(1);
  54.         }
  55.          
  56.  SnmpOID oid = new SnmpOID(opt.remArgs[0]);
  57.  MibNode nodetemp= mibops.getMibNode(oid);
  58.  LeafSyntax leafnode = nodetemp.getSyntax();
  59.  System.out.println("Value : "+leafnode.getType());
  60.  System.out.println("Data-type : "+leafnode.getEquivname());
  61.  
  62.    
  63.    } catch( Exception e ){
  64.         System.err.println( "Exception:" + e );
  65.         e.printStackTrace();
  66. }
  67. }
  68. }