SnmpTrapBrowser.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
- /* $Id: SnmpTrapBrowser.java,v 1.2 2002/06/18 07:19:55 kousalya Exp $ */
- /* SnmpTrapBrowser.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import com.adventnet.snmp.beans.*;
- import com.adventnet.snmp.ui.*;
- public class SnmpTrapBrowser implements TrapListener, TrapParserListener, ActionListener {
-
- SnmpTarget target = new SnmpTarget();
- SnmpTrapReceiver trapreceiver = new SnmpTrapReceiver();
- TrapBrowser trapbrowser = new TrapBrowser();
- TrapParserBean trapparser = new TrapParserBean();
- JButton setbutton = new JButton();
- String values [] = {"testing"};
- public static void main(String args[]) {
-
- SnmpTrapBrowser snmpops = new SnmpTrapBrowser();
- JFrame frame = new JFrame();
- frame.setVisible(true);
- frame.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent evt)
- {
- System.exit(0);
- }
- });
- frame.setSize(615,400);
- frame.setTitle( " Tutorial Example for receiving SNMP Traps" );
- frame.getContentPane().setLayout(null);
- snmpops.trapreceiver.setPort(8001);
- snmpops.trapparser.setFileName("new_trap_parser.parser");
- frame.getContentPane().add(snmpops.trapbrowser);
- snmpops.trapbrowser.setBounds(105,15,460,285);
-
- frame.getContentPane().add(snmpops.setbutton);
- snmpops.setbutton.setBounds(240,320,105,25);
- snmpops.setbutton.setText("Send Trap");
-
- snmpops.trapreceiver.addTrapListener(snmpops);
- snmpops.trapparser.addParserListener(snmpops);
- snmpops.setbutton.addActionListener(snmpops);
-
- try {
- snmpops.target.loadMibs("RFC1213-MIB");
- } catch (Exception e) {
- System.err.println("Set Error: "+e.getMessage());
- }
- frame.show();
- }
- public void actionPerformed(ActionEvent e) {
-
- target.setTargetPort( 8001 );
- target.setObjectID("1.5.0");
- try {
- target.snmpSendTrap("1.2.0", "localhost", 0, 6, 1000, values);
- } catch (Exception ex) {
- System.err.println("Set Error: "+ex.getMessage());
- }
-
- }
-
- public void receivedTrap(TrapEvent trapEvent) {
-
- trapparser.parseEvtAndFire(trapEvent);
-
- }
- public void eventParsed(ParsedTrapEvent parseevent) {
- trapbrowser.displayEvent(parseevent);
- }
-
- }
-