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;
}
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));
}
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;
}
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();
}
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);
}
Aggregations