Search in sources :

Example 41 with OnmsOutage

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

the class TestUtils method createOutage.

public static OnmsOutage createOutage(OnmsMonitoredService service, OnmsEvent svcLostEvent) {
    OnmsOutage outage = new OnmsOutage();
    outage.setMonitoredService(service);
    outage.setIfLostService(new Date());
    outage.setServiceLostEvent(svcLostEvent);
    return outage;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date)

Example 42 with OnmsOutage

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

the class OutageStatusCalculatorIT method verifyCalculateStatus.

@Test
@Transactional
public void verifyCalculateStatus() {
    final OnmsNode node = databasePopulator.getNode1();
    final OnmsMonitoredService icmpService = node.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServiceByServiceType("ICMP");
    final OnmsMonitoredService snmpService = node.getIpInterfaceByIpAddress("192.168.1.1").getMonitoredServiceByServiceType("SNMP");
    final GeolocationQuery query = new GeolocationQueryBuilder().build();
    final StatusCalculator statusCalculator = new OutageStatusCalculator(genericPersistenceAccessor);
    final Set<Integer> nodeIds = Sets.newHashSet(node.getId());
    // No outage exist, status should be normal
    verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
    // Create an alarm and verify status
    final OnmsOutage outage = createOutage(icmpService, createEvent(node, OnmsSeverity.WARNING));
    saveOrUpdate(outage);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.WARNING), statusCalculator.calculateStatus(query, nodeIds));
    // Create another outage on same interface and verify
    final OnmsOutage outage2 = createOutage(snmpService, createEvent(node, OnmsSeverity.MINOR));
    saveOrUpdate(outage2);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MINOR), statusCalculator.calculateStatus(query, nodeIds));
    // Create another outage on another interface and verify
    final OnmsMonitoredService httpService = node.getIpInterfaceByIpAddress("192.168.1.2").getMonitoredServiceByServiceType("HTTP");
    saveOrUpdate(createOutage(httpService, createEvent(node, OnmsSeverity.MAJOR)));
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
    // Create another outage on another node and verify
    saveOrUpdate(createOutage(databasePopulator.getNode2().getPrimaryInterface().getMonitoredServiceByServiceType("ICMP"), createEvent(databasePopulator.getNode2(), OnmsSeverity.CRITICAL)));
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
    // calculate status for both
    verifyStatus(2, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR, databasePopulator.getNode2().getId(), OnmsSeverity.CRITICAL), statusCalculator.calculateStatus(query, Sets.newHashSet(node.getId(), databasePopulator.getNode2().getId())));
    // Resolve the Warning Outage
    outage.setServiceRegainedEvent(createEvent(node, OnmsSeverity.WARNING));
    outage.setIfRegainedService(new Date());
    saveOrUpdate(outage);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
    // Apply severity filter
    query.setSeverity(GeolocationSeverity.Warning);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
    query.setSeverity(GeolocationSeverity.Minor);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
    query.setSeverity(GeolocationSeverity.Major);
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
    query.setSeverity(GeolocationSeverity.Critical);
    verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
    // reset severity filter and apply location filter
    query.setSeverity(null);
    query.setLocation(distPollerDao.whoami().getLocation());
    verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(query, nodeIds));
    query.setLocation("XXX");
    verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(query, nodeIds));
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with OnmsOutage

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

the class OutageDaoIT method getOutage.

private OnmsOutage getOutage(OnmsMonitoredService monitoredService, OnmsEvent event) {
    OnmsOutage outage = new OnmsOutage(new Date(), monitoredService);
    outage.setServiceLostEvent(event);
    m_outageDao.save(outage);
    return outage;
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Date(java.util.Date)

Example 44 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage 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 45 with OnmsOutage

use of org.opennms.netmgt.model.OnmsOutage 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)

Aggregations

OnmsOutage (org.opennms.netmgt.model.OnmsOutage)47 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)26 Date (java.util.Date)23 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)16 OnmsNode (org.opennms.netmgt.model.OnmsNode)12 Test (org.junit.Test)8 Transactional (org.springframework.transaction.annotation.Transactional)8 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 Alias (org.opennms.core.criteria.Alias)5 Criteria (org.opennms.core.criteria.Criteria)5 EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)5 NullRestriction (org.opennms.core.criteria.restrictions.NullRestriction)5 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Before (org.junit.Before)3 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)3 Font (java.awt.Font)2