use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class PollerIT method testNoDuplicateOutagesWithUpDownDown.
/**
* Verifies that outages are properly opened and resolved
* when events arrive out of order.
*
* See NMS-7519 for details.
*/
@Test
public void testNoDuplicateOutagesWithUpDownDown() throws InterruptedException {
final MockService httpService = m_network.getService(2, "192.168.1.3", "HTTP");
final MockService smtpService = m_network.getService(2, "192.168.1.3", "SMTP");
// Start the poller
startDaemons();
// Starting with 0 outages
List<OnmsOutage> httpOutages = getOutages(httpService);
assertEquals(0, httpOutages.size());
// Halts all nodeLostService events until at least 2
// of them a queued.
//
// The event bus should receive the following sequence:
// nodeLostService
// nodeGainedService
// nodeLostService
//
// We're looking to reorder them as follows:
// nodeGainedService
// nodeLostService
// nodeLostService
QueueMultipleDownsHook hook = new QueueMultipleDownsHook(2);
m_eventMgr.setSendNowHook(hook);
// Verify that the initial latch count is 2
waitForHookCount(hook, 2);
// Take the HTTP service down
httpService.bringDown();
// Wait for the latch count to decrease
waitForHookCount(hook, 1);
m_eventMgr.getEventAnticipator().reset();
m_eventMgr.getEventAnticipator().anticipateEvent(httpService.createUpEvent());
// Bring the HTTP service back up even though the nodeLostService
// event is still pending
httpService.bringUp();
m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
// Take the HTTP service down again
httpService.bringDown();
// Wait for the latch count to decrease and send the queued events
waitForHookCount(hook, 0);
m_eventMgr.getEventAnticipator().reset();
m_eventMgr.getEventAnticipator().anticipateEvent(httpService.createUpEvent());
// Bring the HTTP service back online
httpService.bringUp();
m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
// We've succeeded in altering the order of events for the
// HTTP service. Now we make sure that outage processing
// continues to work as expeceted on a different service
m_eventMgr.setSendNowHook(null);
m_eventMgr.getEventAnticipator().reset();
m_eventMgr.getEventAnticipator().anticipateEvent(httpService.createUpEvent());
smtpService.bringDown();
m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
// Verifies that all of the outage fields are properly
// set for both outages affecting the HTTP service,
// even though the events we're send out of order
httpOutages = getOutages(httpService);
assertEquals(2, httpOutages.size());
assertNotNull(httpOutages.get(0).getIfRegainedService());
assertNotNull(httpOutages.get(0).getIfLostService());
assertNotNull(httpOutages.get(0).getIfRegainedService());
assertNotNull(httpOutages.get(0).getServiceRegainedEvent());
assertNotNull(httpOutages.get(1).getIfRegainedService());
assertNotNull(httpOutages.get(1).getIfLostService());
assertNotNull(httpOutages.get(1).getIfRegainedService());
assertNotNull(httpOutages.get(1).getServiceRegainedEvent());
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class PollerIT method closesOpenOutagesWithNoSvcLostEventIdOnRestart.
/**
* Test for NMS-7585
*/
@Test
public void closesOpenOutagesWithNoSvcLostEventIdOnRestart() {
MockNode node = m_network.getNode(2);
MockService criticalService = m_network.getService(2, "192.168.1.3", "ICMP");
// Bring the critical service down
anticipateDown(node);
criticalService.bringDown();
// Start the poller
startDaemons();
// Verify
verifyAnticipated(10000);
// Stop the poller
stopDaemons();
// Remove the reference to the lost service event from all of the outages,
// and let's pretend that they weren't even there in the first place
Set<Integer> outageIds = new HashSet<>();
for (OnmsOutage outage : m_outageDao.findAll()) {
outage.setServiceLostEvent(null);
m_outageDao.update(outage);
outageIds.add(outage.getId());
}
m_outageDao.flush();
// We should get another node down
m_eventMgr.getEventAnticipator().anticipateEvent(node.createDownEvent());
// (Re)start the poller
startDaemons();
// Verify
m_eventMgr.getEventAnticipator().waitForAnticipated(10000);
// Wait for the outages to be populated (this happen after
// the down event is sent)
sleep(1000);
for (OnmsOutage outage : m_outageDao.findAll()) {
if (outageIds.contains(outage.getId())) {
// Outages in our list should be closed with
// no svcRegainedEvent
assertNotNull(outage.getIfRegainedService());
assertNull(outage.getServiceRegainedEvent());
} else {
// Other outages should be open
assertNull(outage.getIfRegainedService());
}
}
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class DefaultRtcService method getNodeListForCriteria.
/**
* {@inheritDoc}
*/
@Override
public RtcNodeModel getNodeListForCriteria(OnmsCriteria serviceCriteria, OnmsCriteria outageCriteria) {
serviceCriteria.addOrder(Order.asc("node.label"));
serviceCriteria.addOrder(Order.asc("node.id"));
serviceCriteria.addOrder(Order.asc("ipInterface.ipAddress"));
serviceCriteria.addOrder(Order.asc("serviceType.name"));
Date periodEnd = new Date(System.currentTimeMillis());
Date periodStart = new Date(periodEnd.getTime() - (24 * 60 * 60 * 1000));
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.isNull("ifRegainedService"));
disjunction.add(Restrictions.ge("ifLostService", periodStart));
disjunction.add(Restrictions.ge("ifRegainedService", periodStart));
outageCriteria.add(disjunction);
outageCriteria.addOrder(Order.asc("monitoredService"));
outageCriteria.addOrder(Order.asc("ifLostService"));
List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(serviceCriteria);
List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
Map<OnmsMonitoredService, Long> serviceDownTime = calculateServiceDownTime(periodEnd, periodStart, outages);
RtcNodeModel model = new RtcNodeModel();
OnmsNode lastNode = null;
int serviceCount = 0;
int serviceDownCount = 0;
long downMillisCount = 0;
for (OnmsMonitoredService service : services) {
if (!service.getIpInterface().getNode().equals(lastNode) && lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount, periodEnd.getTime() - periodStart.getTime());
model.addNode(new RtcNode(lastNode, serviceCount, serviceDownCount, availability));
serviceCount = 0;
serviceDownCount = 0;
downMillisCount = 0;
}
serviceCount++;
if (service.isDown()) {
serviceDownCount++;
}
Long downMillis = serviceDownTime.get(service);
if (downMillis == null) {
// This service had 100% availability over the period, no downtime
} else {
downMillisCount += downMillis;
}
lastNode = service.getIpInterface().getNode();
}
if (lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount, periodEnd.getTime() - periodStart.getTime());
model.addNode(new RtcNode(lastNode, serviceCount, serviceDownCount, availability));
}
return model;
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class OutageDaoIT method testSave.
@Test
@Transactional
public void testSave() {
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
m_nodeDao.save(node);
OnmsIpInterface ipInterface = new OnmsIpInterface(addr("172.16.1.1"), node);
OnmsServiceType serviceType = m_serviceTypeDao.findByName("ICMP");
assertNotNull(serviceType);
OnmsMonitoredService monitoredService = new OnmsMonitoredService(ipInterface, serviceType);
OnmsEvent event = new OnmsEvent();
OnmsOutage outage = new OnmsOutage(new Date(), monitoredService);
outage.setServiceLostEvent(event);
m_outageDao.save(outage);
// it works we're so smart! hehe
outage = m_outageDao.load(outage.getId());
assertEquals("ICMP", outage.getMonitoredService().getServiceType().getName());
// outage.setEventBySvcRegainedEvent();
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class PathOutageManagerDaoImpl method getLabelAndStatus.
/**
* This method is responsible for determining the
* node label of a node, and the up/down status
* and status color
*
* @param nodeIDStr a {@link java.lang.String} object.
* @param conn a {@link java.sql.Connection} object.
* @return an array of {@link java.lang.String} objects.
* @throws java.sql.SQLException if any.
*/
@Override
public String[] getLabelAndStatus(String nodeIDStr, Connection conn) {
String[] result = new String[3];
result[1] = "Cleared";
result[2] = "Unmanaged";
int nodeID = WebSecurityUtils.safeParseInt(nodeIDStr);
OnmsNode node = nodeDao.get(nodeID);
if (node == null) {
// TODO Log that node could not be found in database
return result;
}
result[0] = node.getLabel();
final org.opennms.core.criteria.Criteria crit = new org.opennms.core.criteria.Criteria(OnmsMonitoredService.class).setAliases(Arrays.asList(new Alias[] { new Alias("ipInterface", "ipInterface", JoinType.INNER_JOIN) })).addRestriction(new EqRestriction("status", "A")).addRestriction(new EqRestriction("ipInterface.node", node));
// Get all active services on the node
List<OnmsMonitoredService> services = monitoredServiceDao.findMatching(crit);
int countManagedSvcs = services.size();
// Count how many of these services have open outages
int countOutages = 0;
for (OnmsMonitoredService service : services) {
OnmsOutage out = outageDao.currentOutageForService(service);
if (out != null) {
countOutages++;
}
}
if (countManagedSvcs == countOutages) {
result[1] = "Critical";
result[2] = "All Services Down";
} else if (countOutages == 0) {
result[1] = "Normal";
result[2] = "All Services Up";
} else {
result[1] = "Minor";
result[2] = "Some Services Down";
}
return result;
}
Aggregations