trapd.java

来自「opennms得相关源码 请大家看看」· Java 代码 · 共 552 行 · 第 1/2 页

JAVA
552
字号
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// Modifications://// 2003 Jan 31: Cleaned up some unused imports.// 2003 Jan 08: Added code to associate the IP address in traps with nodes//              and added the option to discover nodes based on traps.//// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.                                                            //// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//       // For more information contact: //      OpenNMS Licensing       <license@opennms.org>//      http://www.opennms.org///      http://www.opennms.com///// Tab Size = 8//package org.opennms.netmgt.trapd;import java.io.IOException;import java.lang.reflect.UndeclaredThrowableException;import java.net.InetAddress;import java.net.SocketException;import java.sql.SQLException;import java.util.Map;import org.apache.log4j.Category;import org.exolab.castor.xml.MarshalException;import org.exolab.castor.xml.ValidationException;import org.opennms.core.fiber.PausableFiber;import org.opennms.core.queue.FifoQueue;import org.opennms.core.queue.FifoQueueException;import org.opennms.core.queue.FifoQueueImpl;import org.opennms.core.utils.ThreadCategory;import org.opennms.netmgt.config.TrapdConfigFactory;import org.opennms.protocols.snmp.SnmpOctetString;import org.opennms.protocols.snmp.SnmpPduPacket;import org.opennms.protocols.snmp.SnmpPduTrap;import org.opennms.protocols.snmp.SnmpTrapHandler;import org.opennms.protocols.snmp.SnmpTrapSession;/** * <p> * The Trapd listens for SNMP traps on the standard port(162). Creates a * SnmpTrapSession and implements the SnmpTrapHandler to get callbacks when * traps are received * </p> *  * <p> * The received traps are converted into XML and sent to eventd * </p> *  * <p> * <strong>Note: </strong>Trapd is a PausableFiber so as to receive control * events. However, a 'pause' on Trapd has no impact on the receiving and * processing of traps * </p> *  * @author <A HREF="mailto:weave@oculan.com">Brian Weaver </A> * @author <A HREF="mailto:sowmya@opennms.org">Sowmya Nataraj </A> * @author <A HREF="mailto:larry@opennms.org">Lawrence Karnowski </A> * @author <A HREF="mailto:mike@opennms.org">Mike Davidson </A> * @author <A HREF="mailto:tarus@opennms.org">Tarus Balog </A> * @author <A HREF="http://www.opennms.org">OpenNMS.org </A> *  */public class Trapd implements SnmpTrapHandler, PausableFiber {    /**     * The name of the logging category for Trapd.     */    private static final String LOG4J_CATEGORY = "OpenNMS.Trapd";    /**     * SQL to get already kown IPs     */    private static final String GET_KNOWN_IPS = "SELECT ipAddr, nodeId FROM ipInterface";    /**     * The singlton instance.     */    private static final Trapd m_singleton = new Trapd();    /**     * The trap session used by Trapd to receive traps     */    private SnmpTrapSession m_trapSession;    /**     * The name of this service.     */    private String m_name;    /**     * The last status sent to the service control manager.     */    private int m_status = START_PENDING;    /**     * The communication queue     */    private FifoQueue m_backlogQ;    /**     * The list of known IPs     */    private Map m_knownIps;    /**     * The queue processing thread     */    private TrapQueueProcessor m_processor;    /**     * The class instance used to recieve new events from for the system.     */    private BroadcastEventProcessor m_eventReader;    /**     * V2 Trap information object for processing by the queue reader     */    static class V2TrapInformation {        /**         * The received PDU         */        private SnmpPduPacket m_pdu;        /**         * The internet address of the sending agent         */        private InetAddress m_agent;        /**         * The community string from the actual SNMP packet         */        private SnmpOctetString m_community;        /**         * Constructs a new trap information instance that contains the sending         * agent, the community string, and the Protocol Data Unit.         *          * @param agent         *            The sending agent's address         * @param community         *            The community string from the SNMP packet.         * @param pdu         *            The encapsulated Protocol Data Unit.         *          */        public V2TrapInformation(InetAddress agent, SnmpOctetString community, SnmpPduPacket pdu) {            m_pdu = pdu;            m_agent = agent;            m_community = community;        }        /**         * Returns the sending agent's internet address         */        public InetAddress getAgent() {            return m_agent;        }        /**         * Returns the Protocol Data Unit that was encapsulated within the SNMP         * Trap message         */        public SnmpPduPacket getPdu() {            return m_pdu;        }        /**         * Returns the SNMP community string from the received packet.         */        public SnmpOctetString getCommunity() {            return m_community;        }    }    /**     * V1 trap element for processing by the queue reader     */    static class V1TrapInformation {        /**         * The received PDU         */        private SnmpPduTrap m_pdu;        /**         * The internet address of the sending agent         */        private InetAddress m_agent;        /**         * The community string from the actual SNMP packet         */        private SnmpOctetString m_community;        /**         * Constructs a new trap information instance that contains the sending         * agent, the community string, and the Protocol Data Unit.         *          * @param agent         *            The sending agent's address         * @param community         *            The community string from the SNMP packet.         * @param pdu         *            The encapsulated Protocol Data Unit.         *          */        public V1TrapInformation(InetAddress agent, SnmpOctetString community, SnmpPduTrap pdu) {            m_pdu = pdu;            m_agent = agent;            m_community = community;        }        /**         * Returns the sending agent's internet address         */        public InetAddress getAgent() {            return m_agent;        }        /**         * Returns the Protocol Data Unit that was encapsulated within the SNMP         * Trap message         */        public SnmpPduTrap getPdu() {            return m_pdu;        }        /**         * Returns the SNMP community string from the received packet.         */        public SnmpOctetString getCommunity() {            return m_community;        }    }    /**     * <P>     * Constructs a new Trapd object that receives and forwards trap messages     * via JSDT. The session is initialized with the default client name of <EM>     * OpenNMS.trapd</EM>. The trap session is started on the default port, as     * defined by the SNMP libarary.     * </P>     *      * @see org.opennms.protocols.snmp.SnmpTrapSession     */    public Trapd() {        m_name = "OpenNMS.Trapd";    }    /**     * <P>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?