Search in sources :

Example 86 with OnmsEvent

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;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date)

Example 87 with OnmsEvent

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;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Date(java.util.Date)

Example 88 with OnmsEvent

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();
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 89 with OnmsEvent

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();
    }
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 90 with OnmsEvent

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();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Date(java.util.Date)

Aggregations

OnmsEvent (org.opennms.netmgt.model.OnmsEvent)94 Date (java.util.Date)49 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)41 OnmsNode (org.opennms.netmgt.model.OnmsNode)37 Test (org.junit.Test)36 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)22 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)21 Transactional (org.springframework.transaction.annotation.Transactional)19 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)16 InetAddress (java.net.InetAddress)13 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)13 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)13 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)9 ArrayList (java.util.ArrayList)7 Before (org.junit.Before)6 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)6 Event (org.opennms.netmgt.xml.event.Event)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)5