Search in sources :

Example 46 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.

the class DaoWebOutageRepository method mapOnmsOutageToOutage.

private Outage mapOnmsOutageToOutage(OnmsOutage onmsOutage) {
    if (onmsOutage != null) {
        Outage outage = new Outage();
        final String outageAddress = str(onmsOutage.getIpAddress());
        outage.outageId = onmsOutage.getId();
        outage.ipAddress = outageAddress;
        outage.hostname = outageAddress;
        outage.lostServiceTime = onmsOutage.getIfLostService();
        outage.regainedServiceTime = onmsOutage.getIfRegainedService();
        outage.serviceId = onmsOutage.getServiceId();
        outage.serviceName = onmsOutage.getMonitoredService() != null ? onmsOutage.getMonitoredService().getServiceName() : "";
        outage.suppressedBy = onmsOutage.getSuppressedBy();
        outage.suppressTime = onmsOutage.getSuppressTime();
        // Node-related fields
        outage.nodeId = onmsOutage.getNodeId();
        outage.location = "";
        final OnmsNode node = onmsOutage.getNode();
        if (node != null) {
            outage.nodeLabel = node.getLabel();
            if (node.getLocation() != null) {
                outage.location = node.getLocation().getLocationName();
            }
        }
        // Event-related fields
        final OnmsEvent event = onmsOutage.getServiceLostEvent();
        outage.lostServiceEventId = 0;
        outage.regainedServiceEventId = 0;
        if (event != null) {
            outage.lostServiceEventId = onmsOutage.getServiceLostEvent().getId();
            if (event.getDistPoller() != null) {
                outage.eventLocation = event.getDistPoller().getLocation();
            }
        }
        if (onmsOutage.getServiceRegainedEvent() != null) {
            outage.regainedServiceEventId = onmsOutage.getServiceRegainedEvent().getId();
        }
        return outage;
    } else {
        return null;
    }
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsOutage(org.opennms.netmgt.model.OnmsOutage)

Example 47 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.

the class TestUtils method createEvent.

public static OnmsEvent createEvent(OnmsNode node, OnmsSeverity severity, OnmsDistPoller distPoller) {
    OnmsEvent event = new OnmsEvent();
    event.setEventUei(EventConstants.NODE_DOWN_EVENT_UEI);
    event.setEventTime(new Date());
    event.setEventCreateTime(new Date());
    event.setEventSource(OutageStatusCalculatorIT.class.getName());
    event.setDistPoller(distPoller);
    event.setEventSeverity(severity.getId());
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventLogMsg("Dummy Log Message");
    event.setNode(node);
    return event;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OutageStatusCalculatorIT(org.opennms.features.geolocation.services.status.OutageStatusCalculatorIT) Date(java.util.Date)

Example 48 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.

the class DaoWebOutageRepositoryIT method setUp.

@Before
public void setUp() {
    m_dbPopulator.populateDatabase();
    OnmsMonitoredService svc2 = m_dbPopulator.getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.2.1"), "ICMP");
    OnmsEvent event = m_dbPopulator.getEventDao().get(1);
    OnmsOutage unresolved2 = new OnmsOutage(new Date(), event, svc2);
    m_dbPopulator.getOutageDao().save(unresolved2);
    m_dbPopulator.getOutageDao().flush();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Before(org.junit.Before)

Example 49 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.

the class WebOutageRepositoryFilterIT method testRegainedServiceDateAfterFilter.

@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testRegainedServiceDateAfterFilter() {
    OnmsMonitoredService svc2 = m_dbPopulator.getMonitoredServiceDao().get(m_dbPopulator.getNode2().getId(), InetAddressUtils.addr("192.168.2.1"), "ICMP");
    // This requires every test method to have a new database instance :/
    OnmsEvent event = m_dbPopulator.getEventDao().get(1);
    // Put a resolved outage into the database so that one will match the
    // filter below
    OnmsOutage resolvedToday = new OnmsOutage(new Date(), new Date(), event, event, svc2, null, null);
    m_dbPopulator.getOutageDao().save(resolvedToday);
    m_dbPopulator.getOutageDao().flush();
    RegainedServiceDateAfterFilter filter = new RegainedServiceDateAfterFilter(yesterday());
    OutageCriteria criteria = new OutageCriteria(filter);
    Outage[] outages = m_daoOutageRepo.getMatchingOutages(criteria);
    assertEquals(1, outages.length);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Outage(org.opennms.web.outage.Outage) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 50 with OnmsEvent

use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.

the class WebOutageRepositoryFilterIT method setUp.

@Before
public void setUp() {
    m_dbPopulator.populateDatabase();
    OnmsMonitoredService svc2 = m_dbPopulator.getMonitoredServiceDao().get(m_dbPopulator.getNode2().getId(), InetAddressUtils.addr("192.168.2.1"), "ICMP");
    // This requires every test method to have a new database instance :/
    OnmsEvent event = m_dbPopulator.getEventDao().get(1);
    OnmsOutage unresolved2 = new OnmsOutage(new Date(), event, svc2);
    m_dbPopulator.getOutageDao().save(unresolved2);
    m_dbPopulator.getOutageDao().flush();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Before(org.junit.Before)

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