use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmRestServiceIT method createAlarm.
private OnmsAlarm createAlarm(final OnmsSeverity severity) {
final OnmsEvent event = getEventDao().findAll().get(0);
final OnmsAlarm alarm = new OnmsAlarm();
alarm.setDistPoller(getDistPollerDao().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.getInetAddress("192.168.1.1"));
alarm.setSeverity(severity);
alarm.setFirstEventTime(event.getEventTime());
alarm.setLastEvent(event);
alarm.setAlarmAckTime(new Date());
alarm.setAlarmAckUser("admin");
getAlarmDao().save(alarm);
getAlarmDao().flush();
return alarm;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmStatsRestServiceIT method createEvent.
protected OnmsEvent createEvent() {
final Calendar c = new GregorianCalendar();
c.set(2010, Calendar.JANUARY, 1, 0, 0, 0);
// test data assumes hours starting at midnight EST (not GMT)
c.setTimeZone(TimeZone.getTimeZone("EST"));
c.set(Calendar.MILLISECOND, 0);
// no matter how big m_eventCount gets, this will still work
c.add(Calendar.HOUR_OF_DAY, m_eventCount);
final Date date = c.getTime();
final OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventUei("uei.opennms.org/test/" + m_eventCount);
event.setEventCreateTime(date);
event.setEventTime(date);
event.setEventDescr("Test event " + m_eventCount);
event.setEventDisplay("Y");
event.setEventLog("Y");
event.setEventHost("es-with-the-most-es");
event.setEventLogMsg("Test event " + m_eventCount + " (log)");
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "test", "parm", "string")));
event.setEventSeverity(OnmsSeverity.MAJOR.getId());
event.setEventSource("AlarmStatsRestServiceTest");
event.setIpAddr(InetAddressUtils.UNPINGABLE_ADDRESS);
event.setNode(m_databasePopulator.getNode1());
event.setServiceType(m_databasePopulator.getServiceTypeDao().findByName("ICMP"));
m_eventDao.save(event);
m_eventDao.flush();
m_eventCount++;
return event;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class EventRestService method updateEvents.
/**
* Updates all the events that match any filter/query supplied in the
* form. If the "ack" parameter is "true", then acks the events as the
* current logged in user, otherwise unacks the events
*
* @param formProperties
* Map of the parameters passed in by form encoding
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateEvents(@Context final SecurityContext securityContext, final MultivaluedMapImpl formProperties) {
writeLock();
try {
Boolean ack = false;
if (formProperties.containsKey("ack")) {
ack = "true".equals(formProperties.getFirst("ack"));
formProperties.remove("ack");
}
final CriteriaBuilder builder = getCriteriaBuilder(formProperties);
builder.orderBy("eventTime").desc();
for (final OnmsEvent event : m_eventDao.findMatching(builder.toCriteria())) {
processEventAck(securityContext, event, ack);
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class EventRestService method updateEvent.
/**
* Updates the event with id "eventid" If the "ack" parameter is "true",
* then acks the events as the current logged in user, otherwise unacks
* the events
*
* @param eventId
* a {@link java.lang.Integer} object.
* @param ack
* a {@link java.lang.Boolean} object.
*/
@PUT
@Path("{eventId}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateEvent(@Context final SecurityContext securityContext, @PathParam("eventId") final Integer eventId, @FormParam("ack") final Boolean ack) {
writeLock();
try {
final OnmsEvent event = getEvent(eventId);
if (ack == null) {
throw getException(Status.BAD_REQUEST, "Must supply the 'ack' parameter, set to either 'true' or 'false'");
}
processEventAck(securityContext, event, ack);
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmRestServiceIT method createAlarm.
private void createAlarm(final OnmsNode node, final String eventUei, final OnmsSeverity severity, final long epoch) {
final OnmsIpInterface alarmNode = node.getIpInterfaces().iterator().next();
final OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_databasePopulator.getDistPollerDao().whoami());
event.setEventCreateTime(new Date(epoch));
event.setEventDisplay("Y");
event.setEventHost("127.0.0.1");
event.setEventLog("Y");
event.setEventSeverity(OnmsSeverity.INDETERMINATE.getId());
event.setEventSource("JUnit");
event.setEventTime(new Date(epoch));
event.setEventUei(eventUei);
if (ALARM_COUNTER.getAndIncrement() % 2 == 0) {
event.addEventParameter(new OnmsEventParameter(event, "testParm1", "This is an awesome parm!", "string"));
} else {
event.addEventParameter(new OnmsEventParameter(event, "testParm2", "This is a weird parm", "string"));
}
event.addEventParameter(new OnmsEventParameter(event, "testParm3", "Here's another parm", "string"));
event.setIpAddr(alarmNode.getIpAddress());
event.setNode(node);
event.setServiceType(m_databasePopulator.getServiceTypeDao().findByName("ICMP"));
event.setEventSeverity(severity.getId());
event.setIfIndex(alarmNode.getIfIndex());
m_databasePopulator.getEventDao().save(event);
m_databasePopulator.getEventDao().flush();
final OnmsAlarm alarm = new OnmsAlarm();
alarm.setDistPoller(m_databasePopulator.getDistPollerDao().whoami());
alarm.setUei(event.getEventUei());
alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
alarm.setNode(node);
alarm.setDescription("This is a test alarm");
alarm.setLogMsg("this is a test alarm log message");
alarm.setCounter(1);
alarm.setIpAddr(alarmNode.getIpAddress());
alarm.setSeverity(severity);
alarm.setFirstEventTime(event.getEventTime());
alarm.setLastEventTime(event.getEventTime());
alarm.setLastEvent(event);
alarm.setServiceType(m_databasePopulator.getServiceTypeDao().findByName("ICMP"));
alarm.setIfIndex(alarmNode.getIfIndex());
m_databasePopulator.getAlarmDao().save(alarm);
m_databasePopulator.getAlarmDao().flush();
}
Aggregations