eventutils.java
来自「opennms得相关源码 请大家看看」· Java 代码 · 共 1,175 行 · 第 1/3 页
JAVA
1,175 行
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2005 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://// 2004 Oct 07: Added code to support RTC rescan on asset update// Aug 24, 2004: Created this file.//// 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.capsd;import java.net.InetAddress;import java.util.Enumeration;import java.util.List;import org.apache.log4j.Category;import org.opennms.core.utils.ThreadCategory;import org.opennms.netmgt.EventConstants;import org.opennms.netmgt.eventd.EventIpcManagerFactory;import org.opennms.netmgt.eventd.EventListener;import org.opennms.netmgt.utils.XmlrpcUtil;import org.opennms.netmgt.xml.event.Event;import org.opennms.netmgt.xml.event.Parm;import org.opennms.netmgt.xml.event.Parms;import org.opennms.netmgt.xml.event.Value;/** * Provides a collection of utility methods used by the DeleteEvent Processor * for dealing with Events * * @author brozow * */public class EventUtils { /** * Make the given listener object a listener for the list of events * referenced in the ueiList. * * @param listener * the lister to add * @param ueiList * the list of events the listener is interested */ public static void addEventListener(EventListener listener, List ueiList) { EventIpcManagerFactory.init(); EventIpcManagerFactory.getInstance().getManager().addEventListener(listener, ueiList); } /** * Ensures that the event has a database eventId * * @param e * the event * @throws InsufficientInformationException * if an event id is not evailable */ static public void checkEventId(Event e) throws InsufficientInformationException { if (e == null) throw new NullPointerException("e is null"); if (!e.hasDbid()) throw new InsufficientInformationException("eventID is unavailable"); } /** * Ensures the given event has an interface * * @param e * the event * @throws InsufficientInformationException * if an interface is not available */ static public void checkInterface(Event e) throws InsufficientInformationException { if (e == null) throw new NullPointerException("e is null"); if (e.getInterface() == null || e.getInterface().length() == 0) throw new InsufficientInformationException("ipaddr for event is unavailable"); } /** * Ensures the given event has a host * * @param e * the event * @throws InsufficientInformationException * if an interface is not available */ static public void checkHost(Event e) throws InsufficientInformationException { if (e == null) throw new NullPointerException("e is null"); if (e.getHost() == null || e.getHost().length() == 0) throw new InsufficientInformationException("host for event is unavailable"); } /** * Ensures that the given Event has a node id * * @param e * the event * @throws InsufficientInformationException * if a node id is not available */ static public void checkNodeId(Event e) throws InsufficientInformationException { if (e == null) throw new NullPointerException("e is null"); if (!e.hasNodeid()) throw new InsufficientInformationException("nodeid for event is unavailable"); } /** * Ensures that the given event has a service parameter * * @param e * the event to check * @throws InsufficientInformationException * if the event does not have a service */ public static void checkService(Event e) throws InsufficientInformationException { if (e == null) throw new NullPointerException("e is null"); if (e.getService() == null || e.getService().length() == 0) throw new InsufficientInformationException("service for event is unavailable"); } /** * Constructs a deleteInterface event for the given nodeId, ipAddress pair. * * @param source * the source for the event * @param nodeId * the nodeId of the node that owns the interface * @param ipAddr * the ipAddress of the interface being deleted * @param txNo * the transaction number to use for processing this event * @return an Event representing a deleteInterface event for the given * nodeId, ipaddr */ public static Event createDeleteInterfaceEvent(String source, long nodeId, String ipAddr, long txNo) { Event newEvent = new Event(); newEvent.setUei(EventConstants.DELETE_INTERFACE_EVENT_UEI); newEvent.setSource(source); newEvent.setInterface(ipAddr); newEvent.setNodeid(nodeId); newEvent.setTime(EventConstants.formatToString(new java.util.Date())); // Add appropriate parms Parms eventParms = new Parms(); Parm eventParm = null; Value parmValue = null; eventParm = new Parm(); eventParm.setParmName(EventConstants.PARM_TRANSACTION_NO); parmValue = new Value(); parmValue.setContent(String.valueOf(txNo)); eventParm.setValue(parmValue); eventParms.addParm(eventParm); // Add Parms to the event newEvent.setParms(eventParms); return newEvent; } /** * Construct a deleteNode event for the given nodeId. * * @param source * the source for the vent * @param nodeId * the node to be deleted. * @param txNo * the transaction number associated with deleting the node * @return an Event object representing a delete node event. */ public static Event createDeleteNodeEvent(String source, long nodeId, long txNo) { Event newEvent = new Event(); newEvent.setUei(EventConstants.DELETE_NODE_EVENT_UEI); newEvent.setSource(source); newEvent.setNodeid(nodeId); newEvent.setTime(EventConstants.formatToString(new java.util.Date())); // Add appropriate parms Parms eventParms = new Parms(); Parm eventParm = null; Value parmValue = null; eventParm = new Parm(); eventParm.setParmName(EventConstants.PARM_TRANSACTION_NO); parmValue = new Value(); parmValue.setContent(String.valueOf(txNo)); eventParm.setValue(parmValue); eventParms.addParm(eventParm); // Add Parms to the event newEvent.setParms(eventParms); return newEvent; } /** * Construct a deleteNode event for the given nodeId. * * @param source * the source for the vent * @param nodeId * the node to be deleted. * @param txNo * the transaction number associated with deleting the node * @return an Event object representing a delete node event. */ public static Event createAssetInfoChangedEvent(String source, long nodeId, long txNo) { Event newEvent = new Event(); newEvent.setUei(EventConstants.ASSET_INFO_CHANGED_EVENT_UEI); newEvent.setSource(source); newEvent.setNodeid(nodeId); newEvent.setTime(EventConstants.formatToString(new java.util.Date())); // Add appropriate parms Parms eventParms = new Parms(); Parm eventParm = null; Value parmValue = null; eventParm = new Parm(); eventParm.setParmName(EventConstants.PARM_TRANSACTION_NO); parmValue = new Value(); parmValue.setContent(String.valueOf(txNo)); eventParm.setValue(parmValue); eventParms.addParm(eventParm); // Add Parms to the event newEvent.setParms(eventParms); return newEvent; } /** * Construct an interfaceDeleted event for an interface. * * @param source * the source of the event * @param nodeId * the nodeId of the node the interface resides in * @param ipAddr * the ipAdddr of the event * @param txNo * a transaction number associated with the event * @return an Event represent an interfaceDeleted event for the given * interface */ public static Event createInterfaceDeletedEvent(String source, long nodeId, String ipAddr, long txNo) { Event newEvent = new Event(); newEvent.setUei(EventConstants.INTERFACE_DELETED_EVENT_UEI); newEvent.setSource(source); newEvent.setNodeid(nodeId); newEvent.setInterface(ipAddr); newEvent.setTime(EventConstants.formatToString(new java.util.Date())); // Add appropriate parms Parms eventParms = new Parms(); Parm eventParm = null; Value parmValue = null; eventParm = new Parm(); eventParm.setParmName(EventConstants.PARM_TRANSACTION_NO); parmValue = new Value(); parmValue.setContent(String.valueOf(txNo)); eventParm.setValue(parmValue); eventParms.addParm(eventParm); // Add Parms to the event newEvent.setParms(eventParms); return newEvent; } /** * Construct a nodeDeleteed event for the given nodeId * * @param source * the source for the evnet * @param nodeId * the id of the node being deleted * @param txNo * a transaction number associated with the event * @return an Event representing a nodeDeleted event for the given node */ public static Event createNodeDeletedEvent(String source, long nodeId, long txNo) { Event newEvent = new Event(); newEvent.setUei(EventConstants.NODE_DELETED_EVENT_UEI); newEvent.setSource(source); newEvent.setNodeid(nodeId); newEvent.setTime(EventConstants.formatToString(new java.util.Date())); // Add appropriate parms Parms eventParms = new Parms(); Parm eventParm = null; Value parmValue = null; eventParm = new Parm(); eventParm.setParmName(EventConstants.PARM_TRANSACTION_NO); parmValue = new Value(); parmValue.setContent(String.valueOf(txNo)); eventParm.setValue(parmValue); eventParms.addParm(eventParm); // Add Parms to the event newEvent.setParms(eventParms); return newEvent; } /** * Constructs a serviceDeleted Event for the nodeId, ipAddr, serviceName * triple * * @param source * the source of the event * @param nodeId * the nodeId that the service resides on * @param ipAddr * the interface that the service resides on * @param service * the name of the service that was deleted * @param txNo * a transaction number associated with the event * @return an Event that represents the serviceDeleted event for the give * triple */ public static Event createServiceDeletedEvent(String source, long nodeId, String ipAddr, String service, long txNo) { Event newEvent = new Event(); newEvent.setUei(EventConstants.SERVICE_DELETED_EVENT_UEI); newEvent.setSource(source); newEvent.setNodeid(nodeId); newEvent.setInterface(ipAddr); newEvent.setService(service); newEvent.setTime(EventConstants.formatToString(new java.util.Date())); // Add appropriate parms Parms eventParms = new Parms(); Parm eventParm = null; Value parmValue = null; eventParm = new Parm(); eventParm.setParmName(EventConstants.PARM_TRANSACTION_NO); parmValue = new Value(); parmValue.setContent(String.valueOf(txNo)); eventParm.setValue(parmValue); eventParms.addParm(eventParm); // Add Parms to the event newEvent.setParms(eventParms); return newEvent; } /**
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?