use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class PathOutageStatusProviderIT method createOutage.
/**
* This method creates an outage with a given parameters for the specified node
* @param uie Event UIE
* @param ipaddress IP-address (in dot-format)
* @param node Node
* @param severity Severity
* @return Resulting outage
* @throws UnknownHostException
*/
private OnmsOutage createOutage(String uie, String ipaddress, OnmsNode node, OnmsSeverity severity) throws UnknownHostException {
OnmsEvent event = createEvent(uie, ipaddress, node, severity);
eventDao.save(event);
OnmsMonitoredService service = createService(node);
monitoredServiceDao.save(service);
OnmsOutage outage = new OnmsOutage(new Date(), event, service);
return outage;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmStatsRestServiceIT method createAlarm.
private OnmsAlarm createAlarm(final OnmsSeverity severity, final String ackUser) {
final OnmsEvent event = createEvent();
final OnmsAlarm alarm = new OnmsAlarm();
alarm.setDistPoller(m_distPollerDao.whoami());
alarm.setUei(event.getEventUei());
alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
alarm.setNode(m_databasePopulator.getNode1());
alarm.setDescription("This is a test alarm");
alarm.setLogMsg("this is a test alarm log message");
alarm.setCounter(1);
alarm.setIpAddr(InetAddressUtils.UNPINGABLE_ADDRESS);
alarm.setSeverity(severity);
alarm.setFirstEventTime(event.getEventTime());
alarm.setLastEvent(event);
alarm.setServiceType(event.getServiceType());
if (ackUser != null) {
alarm.setAlarmAckTime(new Date(1282329200000L));
alarm.setAlarmAckUser(ackUser);
}
m_alarmDao.save(alarm);
m_alarmDao.flush();
LOG.debug("CreateAlarm: {}", alarm);
return alarm;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class QueryManagerDaoImpl method updateResolvedOutageWithEventId.
/**
* {@inheritDoc}
*/
@Override
public void updateResolvedOutageWithEventId(int outageId, int regainedEventId) {
LOG.info("updating resolved outage {} with event id {}", outageId, regainedEventId);
final OnmsEvent event = m_eventDao.get(regainedEventId);
final OnmsOutage outage = m_outageDao.get(outageId);
if (outage == null) {
LOG.warn("Failed to update outage {} with event id {}. The outage no longer exists.", outageId, regainedEventId);
return;
}
// Update the outage
outage.setServiceRegainedEvent(event);
m_outageDao.saveOrUpdate(outage);
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class InsSession method getXMLEvent.
private Event getXMLEvent(final OnmsEvent ev) {
final Integer id = ev.getId();
LOG.info("Working on XML Event for id: {}", id);
LOG.debug("Setting Event id: {}", id);
final Event e = new Event();
e.setDbid(id);
// UEI
final String uei = ev.getEventUei();
if (uei != null) {
LOG.debug("Setting Event uei: {}", uei);
e.setUei(uei);
} else {
LOG.warn("No Event uei found: skipping event....");
return null;
}
// Source
final String source = ev.getEventSource();
if (source != null) {
LOG.debug("Setting Event source: {}", source);
e.setSource(source);
} else {
LOG.info("No Event source found.");
}
// nodeid
final Integer nodeid = ev.getNode().getId();
if (ev.getNode() != null && nodeid != null) {
LOG.debug("Setting Event nodeid: {}", nodeid);
e.setNodeid(nodeid.longValue());
} else {
LOG.info("No Event node found.");
}
// timestamp
final Date time = ev.getEventTime();
if (time != null) {
LOG.debug("Setting event date timestamp to (GMT): {}", time);
e.setTime(time);
} else {
LOG.info("No Event time found.");
}
// host
final String host = ev.getEventHost();
if (host != null) {
LOG.debug("Setting Event Host: {}", host);
e.setHost(host);
} else {
LOG.info("No Event host found.");
}
// interface
final InetAddress ipAddr = ev.getIpAddr();
if (ipAddr != null) {
LOG.debug("Setting Event Interface/ipaddress: {}", ipAddr);
e.setInterfaceAddress(ipAddr);
} else {
LOG.info("No Event ip address found.");
}
// Service Name
if (ev.getServiceType() != null) {
final String serviceName = ev.getServiceType().getName();
LOG.debug("Setting Event Service Name: {}", serviceName);
e.setService(serviceName);
} else {
LOG.info("No Event service name found.");
}
// Description
final String descr = ev.getEventDescr();
if (descr != null) {
LOG.debug("Setting Event Description: {}", descr);
e.setDescr(descr);
} else {
LOG.info("No Event ip address found.");
}
// Log message
final String logmsg = ev.getEventLogMsg();
if (logmsg != null) {
final Logmsg msg = new Logmsg();
LOG.debug("Setting Event Log Message: {}", logmsg);
msg.setContent(logmsg);
e.setLogmsg(msg);
} else {
LOG.info("No Event log Message found.");
}
// severity
final Integer severity = ev.getEventSeverity();
if (severity != null) {
LOG.debug("Setting Event Severity: {}", severity);
e.setSeverity(OnmsSeverity.get(severity).getLabel());
} else {
LOG.info("No Event severity found.");
}
final Integer ifIndex = ev.getIfIndex();
if (ifIndex != null && ifIndex > 0) {
e.setIfIndex(ifIndex);
e.setIfAlias(getIfAlias(nodeid, ifIndex));
} else {
e.setIfIndex(-1);
e.setIfAlias("-1");
}
// operator Instruction
final String operInstruct = ev.getEventOperInstruct();
if (operInstruct != null) {
LOG.debug("Setting Event Operator Instruction: {}", operInstruct);
e.setOperinstruct(operInstruct);
} else {
LOG.info("No Event operator Instruction found.");
}
// parms
final String eventParms = ev.getEventParms();
if (eventParms != null) {
LOG.debug("Setting Event Parms: {}", eventParms);
final List<Parm> parms = EventParameterUtils.decode(eventParms);
if (parms != null)
e.setParmCollection(parms);
} else {
LOG.info("No Event parms found.");
}
final AlarmData ad = new AlarmData();
final OnmsAlarm onmsAlarm = ev.getAlarm();
try {
if (onmsAlarm != null) {
ad.setReductionKey(onmsAlarm.getReductionKey());
ad.setAlarmType(onmsAlarm.getAlarmType());
ad.setClearKey(onmsAlarm.getClearKey());
e.setAlarmData(ad);
}
} catch (final ObjectNotFoundException e1) {
LOG.warn("Correlated alarm data not found.", e1);
}
LOG.info("Returning event with id: {}", id);
return e;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class IPhoneRestServiceIT method testEventsForNodeId.
@Test
@JUnitTemporaryDatabase
public void testEventsForNodeId() throws Exception {
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation());
node.setId(1);
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventUei("uei.opennms.org/test");
event.setEventTime(new Date());
event.setEventSource("test");
event.setEventCreateTime(new Date());
event.setEventSeverity(OnmsSeverity.INDETERMINATE.getId());
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setNode(node);
m_eventDao.save(event);
m_eventDao.flush();
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("limit", "50");
parameters.put("node.id", "1");
String xml = sendRequest(GET, "/events", parameters, 200);
assertTrue(xml, xml.contains("totalCount=\"2\""));
assertTrue(xml, xml.contains("uei.opennms.org/test"));
}
Aggregations