use of org.opennms.netmgt.xml.event.AlarmData in project opennms by OpenNMS.
the class AlarmLifecycleEventsIT method sendNodeDownEvent.
private void sendNodeDownEvent(long nodeId) {
EventBuilder builder = new EventBuilder(EventConstants.NODE_DOWN_EVENT_UEI, "test");
Date currentTime = new Date();
builder.setTime(currentTime);
builder.setNodeid(nodeId);
builder.setSeverity("Major");
AlarmData data = new AlarmData();
data.setAlarmType(1);
data.setReductionKey(String.format("%s:%d", EventConstants.NODE_DOWN_EVENT_UEI, nodeId));
builder.setAlarmData(data);
builder.setLogDest("logndisplay");
builder.setLogMessage("testing");
m_eventMgr.sendNow(builder.getEvent());
}
use of org.opennms.netmgt.xml.event.AlarmData 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.AlarmData in project opennms by OpenNMS.
the class EventdIT method sendServiceDownEvent.
/**
* @param reductionKey
*/
private void sendServiceDownEvent(String reductionKey, OnmsMonitoredService svc) {
final EventBuilder e = MockEventUtil.createEventBuilder("Test", EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, svc.getNodeId(), str(svc.getIpAddress()), svc.getServiceName(), "Not responding");
if (reductionKey != null) {
AlarmData data = new AlarmData();
data.setAlarmType(1);
data.setReductionKey(reductionKey);
e.setAlarmData(data);
} else {
e.setAlarmData(null);
}
e.setLogDest("logndisplay");
e.setLogMessage("testing");
m_eventdIpcMgr.sendNow(e.getEvent());
}
use of org.opennms.netmgt.xml.event.AlarmData 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 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.AlarmData in project opennms by OpenNMS.
the class AlarmdIT method testNoDbid.
@Test
public void testNoDbid() throws Exception {
EventBuilder bldr = new EventBuilder("testNoDbid", "AlarmdTest");
bldr.setLogMessage(null);
bldr.setAlarmData(new AlarmData());
ThrowableAnticipator ta = new ThrowableAnticipator();
ta.anticipate(new IllegalArgumentException("Incoming event has an illegal dbid (0), aborting"));
try {
m_alarmd.getPersister().persist(bldr.getEvent(), false);
} catch (Throwable t) {
ta.throwableReceived(t);
}
ta.verifyAnticipated();
}
Aggregations