use of org.opennms.netmgt.xml.event.UpdateField 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);
}
use of org.opennms.netmgt.xml.event.UpdateField in project opennms by OpenNMS.
the class AlarmdIT method sendNodeDownEventWithUpdateFieldSeverity.
private void sendNodeDownEventWithUpdateFieldSeverity(String reductionKey, MockNode node, OnmsSeverity severity) throws SQLException {
EventBuilder event = MockEventUtil.createNodeDownEventBuilder("Test", node);
if (reductionKey != null) {
AlarmData data = new AlarmData();
data.setAlarmType(1);
data.setReductionKey(reductionKey);
List<UpdateField> fields = new ArrayList<UpdateField>();
UpdateField field = new UpdateField();
field.setFieldName("Severity");
field.setUpdateOnReduction(Boolean.TRUE);
fields.add(field);
data.setUpdateField(fields);
event.setAlarmData(data);
} else {
event.setAlarmData(null);
}
event.setLogDest("logndisplay");
event.setLogMessage("testing");
event.setSeverity(severity.getLabel());
m_eventdIpcMgr.sendNow(event.getEvent());
}
use of org.opennms.netmgt.xml.event.UpdateField in project opennms by OpenNMS.
the class AlarmdIT method sendNodeDownEventDontChangeLogMsg.
//Supporting method for test
private void sendNodeDownEventDontChangeLogMsg(String reductionKey, MockNode node, String logMsg) {
EventBuilder event = MockEventUtil.createNodeDownEventBuilder("Test", node);
if (reductionKey != null) {
AlarmData data = new AlarmData();
data.setAlarmType(1);
data.setReductionKey(reductionKey);
List<UpdateField> fields = new ArrayList<UpdateField>();
UpdateField field = new UpdateField();
field.setFieldName("logMsg");
field.setUpdateOnReduction(Boolean.FALSE);
fields.add(field);
data.setUpdateField(fields);
event.setAlarmData(data);
} else {
event.setAlarmData(null);
}
event.setLogDest("logndisplay");
event.setLogMessage(logMsg);
m_eventdIpcMgr.sendNow(event.getEvent());
}
use of org.opennms.netmgt.xml.event.UpdateField in project opennms by OpenNMS.
the class AlarmPersisterImpl method reduceEvent.
private static void reduceEvent(OnmsEvent e, OnmsAlarm alarm, Event event) {
//Always set these
alarm.setLastEvent(e);
alarm.setLastEventTime(e.getEventTime());
alarm.setCounter(alarm.getCounter() + 1);
if (!event.getAlarmData().hasUpdateFields()) {
//We always set these even if there are not update fields specified
alarm.setLogMsg(e.getEventLogMsg());
alarm.setEventParms(e.getEventParms());
} else {
for (UpdateField field : event.getAlarmData().getUpdateFieldList()) {
String fieldName = field.getFieldName();
//Always set these, unless specified not to, in order to maintain current behavior
if (fieldName.equalsIgnoreCase("LogMsg") && field.isUpdateOnReduction() == false) {
continue;
} else {
alarm.setLogMsg(e.getEventLogMsg());
}
if (fieldName.equalsIgnoreCase("Parms") && field.isUpdateOnReduction() == false) {
continue;
} else {
alarm.setEventParms(e.getEventParms());
}
//Set these others
if (field.isUpdateOnReduction()) {
if (fieldName.toLowerCase().startsWith("distpoller")) {
alarm.setDistPoller(e.getDistPoller());
} else if (fieldName.toLowerCase().startsWith("ipaddr")) {
alarm.setIpAddr(e.getIpAddr());
} else if (fieldName.toLowerCase().startsWith("mouseover")) {
alarm.setMouseOverText(e.getEventMouseOverText());
} else if (fieldName.toLowerCase().startsWith("operinstruct")) {
alarm.setOperInstruct(e.getEventOperInstruct());
} else if (fieldName.equalsIgnoreCase("severity")) {
alarm.setSeverity(OnmsSeverity.valueOf(e.getSeverityLabel()));
} else if (fieldName.toLowerCase().contains("descr")) {
alarm.setDescription(e.getEventDescr());
alarm.setSeverity(OnmsSeverity.valueOf(e.getSeverityLabel()));
} else {
LOG.warn("reduceEvent: The specified field: {}, is not supported.", fieldName);
}
/* This doesn't work because the properties are not consistent from OnmsEvent to OnmsAlarm
try {
final BeanWrapper ew = PropertyAccessorFactory.forBeanPropertyAccess(e);
final BeanWrapper aw = PropertyAccessorFactory.forBeanPropertyAccess(alarm);
aw.setPropertyValue(fieldName, ew.getPropertyValue(fieldName));
} catch (BeansException be) {
LOG.error("reduceEvent", be);
continue;
}
*/
}
}
}
e.setAlarm(alarm);
}
use of org.opennms.netmgt.xml.event.UpdateField in project opennms by OpenNMS.
the class AlarmdIT method sendNodeDownEventChangeLogMsg.
private void sendNodeDownEventChangeLogMsg(String reductionKey, MockNode node, String logMsg) {
EventBuilder event = MockEventUtil.createNodeDownEventBuilder("Test", node);
if (reductionKey != null) {
AlarmData data = new AlarmData();
data.setAlarmType(1);
data.setReductionKey(reductionKey);
List<UpdateField> fields = new ArrayList<UpdateField>();
UpdateField field = new UpdateField();
field.setFieldName("logMsg");
field.setUpdateOnReduction(Boolean.TRUE);
fields.add(field);
data.setUpdateField(fields);
event.setAlarmData(data);
} else {
event.setAlarmData(null);
}
event.setLogDest("logndisplay");
event.setLogMessage(logMsg);
m_eventdIpcMgr.sendNow(event.getEvent());
}
Aggregations