📄 eventexpander.java
字号:
//// 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 Aug 21: Changes made to support ScriptD.// 2002 Nov 10: Removed "http://" from UEIs as well as references to bluebird.// 2002 Oct 22: Added threshold rearm events.// 2002 Oct 21: Default SNMP events no longer hard coded, and event order now functional.//// 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.eventd;import java.util.Enumeration;import org.opennms.netmgt.xml.event.Autoaction;import org.opennms.netmgt.xml.event.Event;import org.opennms.netmgt.xml.event.Logmsg;import org.opennms.netmgt.xml.event.Operaction;import org.opennms.netmgt.xml.event.Snmp;import org.opennms.netmgt.xml.event.Tticket;/** * <P> * This class is responsible for looking up the matching evenconf entry for an * event and loading info from the eventconf match to the event. This class is * also responsible for the event parm expansion * </P> * * <P> * Notes on event parm expansion: * </P> * <P> * The list of elements that can have a %element% or %parms[*]% in their value * are : descr, logmsg, operinstr, autoaction, operaction(/menu), tticket * </P> * * <P> * The list of elements that can occur as a %element% are : uei, source, nodeid, * time, host, interface, snmphost, service, snmp, id, idtext, version, * specific, generic, community, severity, operinstr, mouseovertext, * parm[values-all], parm[names-all], parm[all], parm[ <name>], parm[##], parm[# * <num>] * </P> * * <pre> * * Expansions are made so that * - %element% is replaced by the value of the element * -i.e a 'xxx %uei%' would expand to 'xxx <eventuei>' * - %parm[values-all]% is replaced by a space-separated list of all parm values * -i.e a 'xxx %parm[values-all]%' would expand to 'xxx parmVal1 parmVal2 ..' * - %parm[names-all]% is replaced by a space-separated list of all parm names * -i.e a 'xxx %parm[names-all]%' would expand to 'xxx parmName1 parmName2 ..' * - %parm[all]% is replaced by a space-separated list of all parmName="parmValue" * -i.e a 'xxx %parm[all]%' would expand to 'xxx parmName1="parmVal1" parmName2="parmVal2" ..' * - %parm[<name>]% is replaced by the value of the parameter named 'name', if present * - %parm[#<num>]% is replaced by the value of the parameter number 'num', if present * - %parm[##]% is replaced by the number of parameters * * </pre> * * @author <a href="mailto:weave@oculan.com">Brian Weaver </a> * @author <a href="mailto:sowmya@opennms.org">Sowmya Nataraj </a> * @author <a href="http://www.opennms.org/">OpenNMS </a> */public final class EventExpander { /** * The enterprise ID prefix - incoming events and the events in event.conf * can have EIDs that have the partial EIDs as in '18.1.1.6' instead of * '.1.3.6.1.4.1.18.1.1.6'. When a event lookup is done based on the EID, a * lookup with both the partial and the full EID is done */ private final static String ENTERPRISE_PRE = ".1.3.6.1.4.1"; /** * The default event UEI - if the event lookup into the 'event.conf' fails, * the event is loaded with information from this default UEI */ private final static String DEFAULT_EVENT_UEI = "uei.opennms.org/default/event"; /** * The default trap UEI - if the trap lookup into the 'event.conf' fails, * the trap event is loaded with information from this default UEI */ private final static String DEFAULT_TRAP_UEI = "uei.opennms.org/default/trap"; /** * This is the list of Universal Event Identifiers (UEIs) that map to the * generic types in a SNMPv1 trap. These are not relevant to a SNMPv2c trap. */ private final static String GENERIC_SNMP_UEIS[] = { "uei.opennms.org/mib2/generic/coldStart", // generic // = 0, // Cold // Start "uei.opennms.org/mib2/generic/warmStart", // generic = 1, Warm // Start "uei.opennms.org/mib2/generic/linkDown", // generic = 2, Link // Down "uei.opennms.org/mib2/generic/linkUp", // generic = 3, Link Up "uei.opennms.org/mib2/generic/authenticationFailure", // generic = // 4, // Authentication // Failure "uei.opennms.org/mib2/generic/egpNeighborLoss", // generic = 5, EGP // Neighbor Loss DEFAULT_TRAP_UEI // generic = 6, Enterprise Specific Trap }; /** * private constructor */ private EventExpander() { } /** * This method is used to transform an event configuration mask instance * into an event mask instance. This is used when the incomming event does * not have a mask and the information from the configuration object is * copied. * * @param src * The configuration source to transform. * * @return The transformed mask information. * */ private static org.opennms.netmgt.xml.event.Mask transform(org.opennms.netmgt.xml.eventconf.Mask src) { org.opennms.netmgt.xml.event.Mask dest = new org.opennms.netmgt.xml.event.Mask(); Enumeration en = src.enumerateMaskelement(); while (en.hasMoreElements()) { org.opennms.netmgt.xml.eventconf.Maskelement confme = (org.opennms.netmgt.xml.eventconf.Maskelement) en.nextElement(); // create new mask element org.opennms.netmgt.xml.event.Maskelement me = new org.opennms.netmgt.xml.event.Maskelement(); // set name me.setMename(confme.getMename()); // set values String[] confmevalues = confme.getMevalue(); for (int index = 0; index < confmevalues.length; index++) { me.addMevalue(confmevalues[index]); } dest.addMaskelement(me); } return dest; } /** * This method is used to transform an SNMP event configuration instance * into an SNMP event instance. This is used when the incomming event does * not have any SNMP information and the information from the configuration * object is copied. * * @param src * The configuration source to transform. * * @return The transformed SNMP information. * */ private static org.opennms.netmgt.xml.event.Snmp transform(org.opennms.netmgt.xml.eventconf.Snmp src) { org.opennms.netmgt.xml.event.Snmp dest = new org.opennms.netmgt.xml.event.Snmp(); dest.setId(src.getId()); dest.setIdtext(src.getIdtext()); dest.setVersion(src.getVersion()); dest.setCommunity(src.getCommunity()); if (src.hasGeneric()) dest.setGeneric(src.getGeneric()); if (src.hasSpecific()) dest.setSpecific(src.getSpecific()); return dest; } /** * This method is used to transform a log message event configuration * instance into a log message event instance. This is used when the * incomming event does not have any log message information and the * information from the configuration object is copied. * * @param src * The configuration source to transform. * * @return The transformed log message information. * */ private static org.opennms.netmgt.xml.event.Logmsg transform(org.opennms.netmgt.xml.eventconf.Logmsg src) { org.opennms.netmgt.xml.event.Logmsg dest = new org.opennms.netmgt.xml.event.Logmsg(); dest.setContent(src.getContent()); dest.setDest(src.getDest()); return dest; } /** * This method is used to transform a correlation event configuration * instance into a correlation event instance. This is used when the * incomming event does not have any correlation information and the * information from the configuration object is copied. * * @param src * The configuration source to transform. * * @return The transformed correlation information. * */ private static org.opennms.netmgt.xml.event.Correlation transform(org.opennms.netmgt.xml.eventconf.Correlation src) { org.opennms.netmgt.xml.event.Correlation dest = new org.opennms.netmgt.xml.event.Correlation(); dest.setCuei(src.getCuei()); dest.setCmin(src.getCmin()); dest.setCmax(src.getCmax()); dest.setCtime(src.getCtime()); dest.setState(src.getState()); dest.setPath(src.getPath()); return dest; } /** * This method is used to transform an auto action event configuration * instance into an auto action event instance. This is used when the * incomming event does not have any auto action information and the * information from the configuration object is copied. * * @param src * The configuration source to transform. * * @return The transformed auto action information. * */ private static org.opennms.netmgt.xml.event.Autoaction transform(org.opennms.netmgt.xml.eventconf.Autoaction src) { org.opennms.netmgt.xml.event.Autoaction dest = new org.opennms.netmgt.xml.event.Autoaction(); dest.setContent(src.getContent()); dest.setState(src.getState());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -