use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class MockEventDao method getUeiCounts.
@Override
public Set<CountedObject<String>> getUeiCounts(final Integer limit) {
final Map<String, Long> counts = new HashMap<String, Long>();
for (final OnmsEvent event : findAll()) {
final String eventUei = event.getEventUei();
if (!counts.containsKey(eventUei)) {
counts.put(eventUei, 0L);
}
counts.put(eventUei, counts.get(eventUei) + 1);
}
final Set<CountedObject<String>> countedObjects = new HashSet<CountedObject<String>>();
for (final String uei : counts.keySet()) {
countedObjects.add(new CountedObject<String>(uei, counts.get(uei)));
}
return countedObjects;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class MockEventWriter method process.
private void process(final Event event) throws EventProcessorException {
LOG.debug("Writing event: {}", event);
final OnmsEvent oe = new OnmsEvent();
oe.setEventAutoAction((event.getAutoactionCount() > 0) ? AutoAction.format(event.getAutoaction(), EVENT_AUTOACTION_FIELD_SIZE) : null);
oe.setEventCorrelation((event.getCorrelation() != null) ? org.opennms.netmgt.dao.util.Correlation.format(event.getCorrelation(), EVENT_CORRELATION_FIELD_SIZE) : null);
oe.setEventCreateTime(event.getCreationTime());
oe.setId(event.getDbid());
oe.setEventDescr(event.getDescr());
try {
oe.setDistPoller(m_distPollerDao.get(event.getDistPoller()));
} catch (final DataAccessException e) {
throw new EventProcessorException(e);
}
oe.setEventHost(event.getHost());
oe.setEventForward((event.getForwardCount() > 0) ? org.opennms.netmgt.dao.util.Forward.format(event.getForward(), EVENT_FORWARD_FIELD_SIZE) : null);
oe.setIfIndex(event.getIfIndex());
oe.setIpAddr(event.getInterfaceAddress());
if (event.getLogmsg() != null) {
// set log message
oe.setEventLogMsg(EventDatabaseConstants.format(event.getLogmsg().getContent(), 0));
final String logdest = event.getLogmsg().getDest();
if (logdest.equals("logndisplay")) {
// if 'logndisplay' set both log and display column to yes
oe.setEventLog("Y");
oe.setEventDisplay("Y");
} else if (logdest.equals("logonly")) {
// if 'logonly' set log column to true
oe.setEventLog("Y");
oe.setEventDisplay("N");
} else if (logdest.equals("displayonly")) {
// if 'displayonly' set display column to true
oe.setEventLog("N");
oe.setEventDisplay("Y");
} else if (logdest.equals("suppress")) {
// if 'suppress' set both log and display to false
oe.setEventLog("N");
oe.setEventDisplay("N");
}
}
oe.setEventMouseOverText(event.getMouseovertext());
try {
oe.setNode(m_nodeDao.get(event.getNodeid().intValue()));
} catch (final DataAccessException e) {
throw new EventProcessorException(e);
}
if (event.getOperactionCount() > 0) {
final List<Operaction> a = new ArrayList<>();
final List<String> b = new ArrayList<>();
for (final Operaction eoa : event.getOperactionCollection()) {
a.add(eoa);
b.add(eoa.getMenutext());
}
oe.setEventOperAction(OperatorAction.format(a, EVENT_OPERACTION_FIELD_SIZE));
oe.setEventOperActionMenuText(EventDatabaseConstants.format(b, EVENT_OPERACTION_MENU_FIELD_SIZE));
}
oe.setEventOperInstruct(event.getOperinstruct());
oe.setEventParametersFromEvent(event);
oe.setEventPathOutage(event.getPathoutage());
try {
oe.setServiceType(m_serviceTypeDao.findByName(event.getService()));
} catch (final DataAccessException e) {
throw new EventProcessorException(e);
}
oe.setSeverityLabel(event.getSeverity());
oe.setEventSnmp(SnmpInfo.format(event.getSnmp(), EVENT_SNMP_FIELD_SIZE));
oe.setEventSnmpHost(EventDatabaseConstants.format(event.getSnmphost(), EVENT_SNMPHOST_FIELD_SIZE));
oe.setEventSource(event.getSource());
oe.setEventTime(event.getTime());
if (event.getTticket() != null) {
oe.setEventTTicket(EventDatabaseConstants.format(event.getTticket().getContent(), EVENT_TTICKET_FIELD_SIZE));
oe.setEventTTicketState(event.getTticket().getState().equals("on") ? 1 : 0);
}
oe.setEventUei(event.getUei());
m_eventDao.saveOrUpdate(oe);
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class NCSNorthbounderIT method alarm.
private NorthboundAlarm alarm(int alarmId) {
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "componentType", "Service", "string"), new OnmsEventParameter(event, "componentName", "NAM" + alarmId, "string"), new OnmsEventParameter(event, "componentForeignSource", "FS", "string"), new OnmsEventParameter(event, "componentForeignId", "" + alarmId, "string"), new OnmsEventParameter(event, "cause", "17", "string")));
OnmsAlarm alarm = new OnmsAlarm();
alarm.setId(alarmId);
alarm.setUei("uei.opennms.org/test/httpNorthBounder");
alarm.setLastEvent(event);
alarm.setAlarmType((alarmId + 1) % 2 + 1);
return new NorthboundAlarm(alarm);
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class NCSComponentServiceImpl method deleteEvents.
private void deleteEvents(final String foreignSource, final String foreignId) {
final Map<String, String> eventParameters = new HashMap<>();
eventParameters.put("componentForeignSource", foreignSource);
eventParameters.put("componentForeignId", foreignId);
for (final OnmsEvent event : m_eventDao.getEventsForEventParameters(eventParameters)) {
m_eventDao.delete(event);
}
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class OnmsRestEventsClient method toEvent.
public Event toEvent(OnmsEvent onmsEvent) {
Event event = new Event();
if (onmsEvent.getId() != null)
event.setDbid(onmsEvent.getId());
if (onmsEvent.getEventUei() != null)
event.setUei(onmsEvent.getEventUei());
if (onmsEvent.getEventCreateTime() != null)
event.setCreationTime(onmsEvent.getEventCreateTime());
// event.setService()
if (onmsEvent.getSeverityLabel() != null)
event.setSeverity(onmsEvent.getSeverityLabel());
if (onmsEvent.getEventDescr() != null)
event.setDescr(onmsEvent.getEventDescr());
if (onmsEvent.getEventHost() != null)
event.setHost(onmsEvent.getEventHost());
List<Parm> parmColl = new ArrayList<>();
if (onmsEvent.getEventParameters() != null) {
List<OnmsEventParameter> params = onmsEvent.getEventParameters();
for (OnmsEventParameter onmsEventParameter : params) {
String parmName = onmsEventParameter.getName();
String type = onmsEventParameter.getType();
String value = onmsEventParameter.getValue();
Parm parm = new Parm();
parm.setParmName(parmName);
Value parmvalue = new Value();
parmvalue.setType(type);
parmvalue.setContent(value);
parm.setValue(parmvalue);
parmColl.add(parm);
}
}
// add node label as param
if (onmsEvent.getNodeLabel() != null) {
Parm parm = new Parm();
parm.setParmName(NODE_LABEL);
Value parmValue = new Value();
parm.setValue(parmValue);
parmValue.setType("string");
parmValue.setEncoding("text");
parmValue.setContent(onmsEvent.getNodeLabel());
parmColl.add(parm);
}
event.setParmCollection(parmColl);
if (onmsEvent.getEventLogMsg() != null) {
Logmsg logmsg = new Logmsg();
logmsg.setContent(onmsEvent.getEventLogMsg());
event.setLogmsg(logmsg);
}
if (onmsEvent.getNodeId() != null) {
Integer i = onmsEvent.getNodeId();
Long l = Long.valueOf(i.longValue());
event.setNodeid(l);
}
return event;
}
Aggregations