use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class AvailabilityServiceHibernateImpl method getOutageTimeInWindow.
private static double getOutageTimeInWindow(List<OnmsOutage> outages, Date start, Date end) {
if (outages == null || outages.size() == 0) {
return 0.0d;
}
final long windowStart = start.getTime();
final long windowEnd = end.getTime();
final long windowLength = windowEnd - windowStart;
Preconditions.checkArgument(0 <= windowStart && windowStart < windowEnd);
long downtimeInWindow = 0;
for (final OnmsOutage outage : outages) {
// When did the service go down?
// Use the start of the window if the service went down before this
final long lostAt = Math.max(windowStart, outage.getIfLostService().getTime());
// When did the service come back up?
long regainedAt;
if (outage.getIfRegainedService() == null) {
// It's still offline - use the end of the window
regainedAt = windowEnd;
} else {
// Use the end of the window if the service came back up after this
regainedAt = Math.min(windowEnd, outage.getIfRegainedService().getTime());
}
downtimeInWindow += (regainedAt - lostAt);
}
// Bound the downtime by the length of the window
return Math.min(downtimeInWindow, windowLength);
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class OutageRestServiceIT method setUp.
@Before
@Override
public void setUp() throws Throwable {
super.setUp();
Assert.assertNotNull(populator);
Assert.assertNotNull(applicationDao);
populator.addExtension(new DatabasePopulator.Extension<ApplicationDao>() {
private OnmsOutage unresolvedOutage;
private OnmsEvent outageEvent;
private OnmsApplication application;
@Override
public DatabasePopulator.DaoSupport<ApplicationDao> getDaoSupport() {
return new DatabasePopulator.DaoSupport<>(ApplicationDao.class, applicationDao);
}
@Override
public void onPopulate(DatabasePopulator populator, ApplicationDao dao) {
OnmsDistPoller distPoller = populator.getDistPollerDao().whoami();
outageEvent = populator.buildEvent(distPoller);
outageEvent.setEventSeverity(OnmsSeverity.MINOR.getId());
outageEvent.setEventCreateTime(new Date(1436881548292L));
outageEvent.setEventTime(new Date(1436881548292L));
populator.getEventDao().save(outageEvent);
populator.getEventDao().flush();
// create the application
application = new OnmsApplication();
application.setName("Awesome Application");
dao.save(application);
// get the SNMP service from node 1 and assign the application to it
final OnmsMonitoredService svc = populator.getMonitoredServiceDao().get(populator.getNode1().getId(), InetAddressUtils.addr("192.168.1.2"), "HTTP");
svc.addApplication(application);
application.addMonitoredService(svc);
populator.getMonitoredServiceDao().saveOrUpdate(svc);
populator.getMonitoredServiceDao().flush();
// create a unresolved outage
unresolvedOutage = new OnmsOutage(new Date(1436881548292L), outageEvent, svc);
populator.getOutageDao().save(unresolvedOutage);
populator.getOutageDao().flush();
}
@Override
public void onShutdown(DatabasePopulator populator, ApplicationDao dao) {
// Delete OnmsApplications
for (OnmsApplication application : dao.findAll()) {
dao.delete(application);
}
}
});
populator.populateDatabase();
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class DefaultNodeStatusCalculatorIT method verifyOutageStatusCalculation.
@Test
@Transactional
public void verifyOutageStatusCalculation() {
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 Set<Integer> nodeIds = Sets.newHashSet(node.getId());
final NodeStatusCalculatorConfig config = new NodeStatusCalculatorConfig();
config.setCalculationStrategy(NodeStatusCalculationStrategy.Outages);
// No nodeIds
verifyStatus(6, nodeDao.findAll().stream().collect(Collectors.toMap(n -> n.getId(), n -> OnmsSeverity.NORMAL)), statusCalculator.calculateStatus(config));
// No outage exist, status should be normal
config.setNodeIds(nodeIds);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.NORMAL), statusCalculator.calculateStatus(config));
// 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(config));
// 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(config));
// 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(config));
// 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(config));
// calculate status for both
config.setNodeIds(Sets.newHashSet(node.getId(), databasePopulator.getNode2().getId()));
verifyStatus(2, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR, databasePopulator.getNode2().getId(), OnmsSeverity.CRITICAL), statusCalculator.calculateStatus(config));
// Resolve the Warning Outage
config.setNodeIds(nodeIds);
outage.setServiceRegainedEvent(createEvent(node, OnmsSeverity.WARNING));
outage.setIfRegainedService(new Date());
saveOrUpdate(outage);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(config));
// Apply severity filter
config.setSeverity(OnmsSeverity.WARNING);
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(config));
config.setSeverity(OnmsSeverity.MINOR);
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(config));
config.setSeverity(OnmsSeverity.MAJOR);
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(config));
config.setSeverity(OnmsSeverity.CRITICAL);
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(config));
// reset severity filter and apply location filter
config.setSeverity(null);
config.setLocation(distPollerDao.whoami().getLocation());
verifyStatus(1, ImmutableMap.of(node.getId(), OnmsSeverity.MAJOR), statusCalculator.calculateStatus(config));
config.setLocation("XXX");
verifyStatus(0, new HashMap<>(), statusCalculator.calculateStatus(config));
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class TestUtils method createOutage.
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 OutageDaoHibernate method matchingCurrentOutages.
/**
* {@inheritDoc}
*/
@Override
public Collection<OnmsOutage> matchingCurrentOutages(final ServiceSelector selector) {
final Set<InetAddress> matchingAddrs = new HashSet<InetAddress>(m_filterDao.getIPAddressList(selector.getFilterRule()));
final Set<String> matchingSvcs = new HashSet<String>(selector.getServiceNames());
final List<OnmsOutage> matchingOutages = new LinkedList<>();
final Collection<OnmsOutage> outages = currentOutages();
for (final OnmsOutage outage : outages) {
final OnmsMonitoredService svc = outage.getMonitoredService();
if ((matchingSvcs.contains(svc.getServiceName()) || matchingSvcs.isEmpty()) && matchingAddrs.contains(svc.getIpAddress())) {
matchingOutages.add(outage);
}
}
return matchingOutages;
}
Aggregations