- /* $Id: SnmpSendTrap.java,v 1.1 2002/06/15 14:40:08 ram Exp $ */
- /*
- * @(#)SnmpSendTrap.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- /**
- * This is a tutorial example program to explain how to write an application to
- * send a v1 Trap message using com.adventnet.snmp.beans package of
- * AdventNetSNMP api.
- *
- * The user could run this application by giving the following usage.
- *
- * java SnmpSendTrap mibfile hostname enterprise agent-addr generic-trap specific-trap timeticks OID value
- *
- * where
- *
- *
- *
- * hostname is the RemoteHost (agent).The Format is string without double qoutes/IpAddress.
- *
- * mibfile is the name of the mib to be loaded
- *
- * enterprise is the Object Identifier (sysObjectID for generic traps)
- *
- * agent-addr is the IP address of the agent sending the trap
- *
- * generic-trap is the generic trap type INTEGER (0..6)
- *
- * specific-trap is the specific trap code INTEGER(0..2147483647)
- *
- * timeticks is the value of object sysUpTime when the event occurred
- *
- * value is the object instance value to be set
- *
- *
- *
- *
- */
- import com.adventnet.snmp.beans.*;
- public class SnmpSendTrap {
- public static void main(String args[]) {
- if( args.length < 1)
- {
- System.out.println("Usage : java SnmpSendTrap mibfile hostname enterprise-oid agent-addr generic-trap specific-trap timeticks OID value ");
- System.exit(0);
- }
- // Take care of getting all the parameters
- String mibs = args[0];
- String remoteHost = args[1];
- String enterprise = args[2];
- String agenthost = args[3];
- int generictype = Integer.parseInt (args[4]);
- int specifictype = Integer.parseInt (args[5]);
- long uptime = Integer.parseInt (args[6]);
- String OID = args[7];
- String values[] = {args[8]};
- // Instantiate the SnmpTarget bean
- SnmpTarget target = new SnmpTarget();
- //set host and other parameters
- target.setTargetHost(remoteHost);
- target.setTargetPort( 8001 );
- target.setObjectID(OID);
- // load the mib file
- try {
- target.loadMibs(mibs);
- } catch (Exception e) {
- System.err.println("Set Error: "+e.getMessage());
- }
- // send a v1 trap
- try {
- target.snmpSendTrap(enterprise, agenthost, generictype, specifictype, uptime, values);
- System.out.println("Response PDU received from " +target.getTargetHost()+ ", community: " + target.getCommunity());
- System.out.println("OBJECT ID: "+target.getObjectID());
- } catch (Exception e) {
- System.err.println("Set Error: "+e.getMessage());
- }
- System.exit(0);
- }
- }