Search in sources :

Example 36 with OnmsEvent

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

Example 37 with OnmsEvent

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

Example 38 with OnmsEvent

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

Example 39 with OnmsEvent

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;
}
Also used : Logmsg(org.opennms.netmgt.xml.event.Logmsg) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Event(org.opennms.netmgt.xml.event.Event) Parm(org.opennms.netmgt.xml.event.Parm) InetAddress(java.net.InetAddress) Date(java.util.Date) AlarmData(org.opennms.netmgt.xml.event.AlarmData)

Example 40 with OnmsEvent

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"));
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) Date(java.util.Date) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

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