Sendv2Trap.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:1k
- /* $Id: Sendv2Trap.java,v 1.1 2002/06/15 14:41:18 ram Exp $ */
- /*
- * @(#)Sendv2Trap.java
- * Copyright (c) 1996-2001 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- /**
- * This is an example program to explain how to write an application to send a
- * v2 Trap message using com.adventnet.snmp.beans packages of AdventNetSNMP2 api.
- *
- * java Sendv2Trap
- *
- */
- import java.lang.*;
- import java.util.*;
- import java.net.*;
- import com.adventnet.snmp.beans.*;
- public class Sendv2Trap {
- public static void main(String args[]) {
- // instantiate SNMP target bean
- SnmpTarget target = new SnmpTarget();
- target.settargetHost("hostname");
- //set the Target Port on which the target host would be listening to receive traps.
- target.setTargetPort(162);
- //Set the SNMP version.
- target.setSnmpVersion(target.VERSION2C);
- //Set the community.
- target.setCommunity(community);
-
- //Send v2c trap
- String values[] = {"testing"};
- try
- {
- // use SnmpTarget methods to send trap with specified OIDs/values
- target.snmpSendNotification(1000, trapoid, values);
- // allow time to send trap before exiting
- Thread.sleep(500);
- }
- catch (Exception e)
- {
- System.err.println("Error Sending Trap: "+e.getMessage());
- }
- System.exit(0);
- }
- }