Search in sources :

Example 1 with Parameter

use of org.opennms.netmgt.xml.eventconf.Parameter in project opennms by OpenNMS.

the class EventExpander method expandEvent.

/**
     * <p>
     * This method is invoked to check and configure a received event. The event
     * configuration manager is consulted to find the appropriate configuration
     * that is used to expand the event. In addition, the security parameters
     * from the configuration manager is consulted to ensure that secure files
     * are cleared out if necessary.
     * </p>
     *
     * <p>
     * Any secure fields that exists in the incoming event are cleared during
     * expansion.
     * </p>
     *
     * @param e
     *            The event to expand if necessary.
     */
public void expandEvent(Event e) {
    org.opennms.netmgt.xml.eventconf.Event econf = lookup(m_eventConfDao, e);
    if (econf != null) {
        if (m_eventConfDao.isSecureTag("mask")) {
            e.setMask(null);
        }
        if (e.getMask() == null && econf.getMask() != null) {
            e.setMask(transform(econf.getMask()));
        }
        //
        if (e.getUei() == null) {
            e.setUei(econf.getUei());
        }
        //
        if (e.getSnmp() == null && econf.getSnmp() != null) {
            e.setSnmp(transform(econf.getSnmp()));
        }
        //
        if (m_eventConfDao.isSecureTag("descr")) {
            e.setDescr(null);
        }
        if (e.getDescr() == null && econf.getDescr() != null) {
            e.setDescr(econf.getDescr());
        }
        //
        if (m_eventConfDao.isSecureTag("logmsg")) {
            e.setLogmsg(null);
        }
        if (e.getLogmsg() == null && econf.getLogmsg() != null) {
            e.setLogmsg(transform(econf.getLogmsg()));
        }
        //
        if (m_eventConfDao.isSecureTag("severity")) {
            e.setSeverity(null);
        }
        if (e.getSeverity() == null && econf.getSeverity() != null) {
            e.setSeverity(econf.getSeverity());
        }
        //
        if (m_eventConfDao.isSecureTag("correlation")) {
            e.setCorrelation(null);
        }
        if (e.getCorrelation() == null && econf.getCorrelation() != null) {
            e.setCorrelation(transform(econf.getCorrelation()));
        }
        //
        if (m_eventConfDao.isSecureTag("operinstruct")) {
            e.setOperinstruct(null);
        }
        if (e.getOperinstruct() == null && econf.getOperinstruct() != null) {
            e.setOperinstruct(econf.getOperinstruct());
        }
        //
        if (m_eventConfDao.isSecureTag("autoaction")) {
            e.removeAllAutoaction();
        }
        if (e.getAutoactionCount() == 0 && econf.getAutoactions().size() > 0) {
            econf.getAutoactions().forEach(aa -> {
                e.addAutoaction(transform(aa));
            });
        }
        //
        if (m_eventConfDao.isSecureTag("operaction")) {
            e.removeAllOperaction();
        }
        if (e.getOperactionCount() == 0 && econf.getOperactions().size() > 0) {
            econf.getOperactions().forEach(oa -> {
                e.addOperaction(transform(oa));
            });
        }
        //
        if (m_eventConfDao.isSecureTag("autoacknowledge")) {
            e.setAutoacknowledge(null);
        }
        if (e.getAutoacknowledge() == null && econf.getAutoacknowledge() != null) {
            e.setAutoacknowledge(transform(econf.getAutoacknowledge()));
        }
        //
        if (m_eventConfDao.isSecureTag("loggroup")) {
            e.removeAllLoggroup();
        }
        if (e.getLoggroupCount() == 0 && econf.getLoggroups().size() > 0) {
            e.setLoggroup(econf.getLoggroups());
        }
        //
        if (m_eventConfDao.isSecureTag("tticket")) {
            e.setTticket(null);
        }
        if (e.getTticket() == null && econf.getTticket() != null) {
            e.setTticket(transform(econf.getTticket()));
        }
        //
        if (m_eventConfDao.isSecureTag("forward")) {
            e.removeAllForward();
        }
        if (e.getForwardCount() == 0 && econf.getForwards().size() > 0) {
            econf.getForwards().forEach(fc -> {
                e.addForward(transform(fc));
            });
        }
        //
        if (m_eventConfDao.isSecureTag("script")) {
            e.removeAllScript();
        }
        if (e.getScriptCount() == 0 && econf.getScripts().size() > 0) {
            econf.getScripts().forEach(sc -> {
                e.addScript(transform(sc));
            });
        }
        //
        if (m_eventConfDao.isSecureTag("mouseovertext")) {
            e.setMouseovertext(null);
        }
        if (e.getMouseovertext() == null && econf.getMouseovertext() != null) {
            e.setMouseovertext(econf.getMouseovertext());
        }
        if (e.getAlarmData() == null && econf.getAlarmData() != null) {
            AlarmData alarmData = new AlarmData();
            final org.opennms.netmgt.xml.eventconf.AlarmData econfAlarmData = econf.getAlarmData();
            alarmData.setAlarmType(econfAlarmData.getAlarmType());
            alarmData.setReductionKey(econfAlarmData.getReductionKey());
            alarmData.setAutoClean(econfAlarmData.getAutoClean());
            alarmData.setX733AlarmType(econfAlarmData.getX733AlarmType());
            alarmData.setX733ProbableCause(econfAlarmData.getX733ProbableCause());
            alarmData.setClearKey(econfAlarmData.getClearKey());
            List<org.opennms.netmgt.xml.eventconf.UpdateField> updateFieldList = econfAlarmData.getUpdateFields();
            if (updateFieldList.size() > 0) {
                List<UpdateField> updateFields = new ArrayList<>(updateFieldList.size());
                for (org.opennms.netmgt.xml.eventconf.UpdateField econfUpdateField : updateFieldList) {
                    UpdateField eventField = new UpdateField();
                    eventField.setFieldName(econfUpdateField.getFieldName());
                    eventField.setUpdateOnReduction(econfUpdateField.getUpdateOnReduction());
                    updateFields.add(eventField);
                }
                alarmData.setUpdateField(updateFields);
            }
            e.setAlarmData(alarmData);
        }
        if (econf.getParameters() != null && econf.getParameters().size() > 0) {
            if (e.getParmCollection() == null) {
                e.setParmCollection(new ArrayList<>(econf.getParameters().size()));
            }
            for (Parameter p : econf.getParameters()) {
                if (EventUtils.getParm(e, p.getName()) == null) {
                    Parm parm = new Parm();
                    parm.setParmName(p.getName());
                    Value v = new Value();
                    v.setContent(p.getValue());
                    v.setType("string");
                    v.setEncoding("text");
                    v.setExpand(p.getExpand());
                    parm.setValue(v);
                    e.addParm(parm);
                } else {
                    LOG.warn("expandEvent: the event {} already has a parameter named {}, the original content will be preserved. Check the event definition and rename the optional parameter.", e.getUei(), p.getName());
                }
            }
        }
    }
    Map<String, Map<String, String>> decode = new HashMap<String, Map<String, String>>();
    if (econf != null && econf.getVarbindsdecodes().size() > 0) {
        for (final Varbindsdecode element : econf.getVarbindsdecodes()) {
            List<Decode> decodeArray = element.getDecodes();
            Map<String, String> valueMap = new HashMap<String, String>();
            for (final Decode element2 : decodeArray) {
                valueMap.put(element2.getVarbindvalue(), element2.getVarbinddecodedstring());
            }
            decode.put(element.getParmid(), valueMap);
        }
    }
    // end fill of event using econf
    // do the event parm expansion
    expandParms(e, decode);
}
Also used : HashMap(java.util.HashMap) Varbindsdecode(org.opennms.netmgt.xml.eventconf.Varbindsdecode) UpdateField(org.opennms.netmgt.xml.event.UpdateField) ArrayList(java.util.ArrayList) Decode(org.opennms.netmgt.xml.eventconf.Decode) Parm(org.opennms.netmgt.xml.event.Parm) Value(org.opennms.netmgt.xml.event.Value) Parameter(org.opennms.netmgt.xml.eventconf.Parameter) HashMap(java.util.HashMap) Map(java.util.Map) AlarmData(org.opennms.netmgt.xml.event.AlarmData)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AlarmData (org.opennms.netmgt.xml.event.AlarmData)1 Parm (org.opennms.netmgt.xml.event.Parm)1 UpdateField (org.opennms.netmgt.xml.event.UpdateField)1 Value (org.opennms.netmgt.xml.event.Value)1 Decode (org.opennms.netmgt.xml.eventconf.Decode)1 Parameter (org.opennms.netmgt.xml.eventconf.Parameter)1 Varbindsdecode (org.opennms.netmgt.xml.eventconf.Varbindsdecode)1