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

SNMP编程

开发平台:

C/C++

  1. /* $Id: SnmpPolling.java,v 1.1 2002/06/15 14:40:08 ram Exp $ */
  2. /* SnmpPolling.java
  3.  * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
  4.  * Please read the associated COPYRIGHTS file for more details.
  5.  */
  6. /**
  7.  * This is a tutorial example program to explain how to write an application to do
  8.  * the polling operations using com.adventnet.snmp.beans package of
  9.  * AdventNetSNMP api.
  10.  *
  11.  * The user could run this application by giving the following usage.
  12.  *  
  13.  * java SnmpPolling hostname OID 
  14.  *
  15.  * where 
  16.  *
  17.  * hostname is the RemoteHost (agent).The Format is string without double qoutes/IpAddress.
  18.  * OID is the Object Identifier. The entire OID can be given or it can be given in the form of 1.1.0.
  19.  * If the oid is not starting with a dot (.) it will be prefixed by .1.3.6.1.2.1 .
  20.  * So the entire OID of 1.1.0 will become .1.3.6.1.2.1.1.1.0 .
  21.  *
  22.  * Example usage:
  23.  *
  24.  * java SnmpPolling adventnet 1.1.0 
  25.  *
  26.  */
  27. import com.adventnet.snmp.beans.*;
  28. public class SnmpPolling implements ResultListener  {
  29.     SnmpPoller poller = new SnmpPoller();
  30.     
  31. public static void main(String args[]) {
  32.       if( args.length < 2)
  33. {
  34. System.out.println("Usage : java SnmpPolling hostname OID ");
  35. System.exit(0);
  36. }
  37.         // Take care of getting the hostname and the OID
  38. String remoteHost = args[0];
  39.         String OID = args[1];      
  40. SnmpPolling polling = new SnmpPolling();
  41. //set host and other parameters
  42. polling.poller.setTargetHost(remoteHost);  
  43. polling.poller.setObjectID(OID);  
  44. polling.poller.setPollInterval(1); 
  45. polling.poller.addResultListener(polling);
  46. }
  47.    
  48.     public void setNumericResult(long l){
  49.     }
  50.     public void setResult(ResultEvent result){
  51.  try { 
  52.             System.out.println(result.getStringValue());
  53.         } catch (DataException de) {
  54.             System.out.println("Error in getting agent data: "+de +
  55.                        result.getErrorString());
  56.         }
  57.     }
  58.     
  59.    
  60.      public void setStringResult(String s){
  61.      }
  62. }