use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class PollerIT method testNoDuplicateOutagesWithDownDownUp.
/**
* Verifies that outages are properly opened and resolved
* when events arrive out of order.
*
* See NMS-7394 for details.
*/
@Test
public void testNoDuplicateOutagesWithDownDownUp() {
MockInterface nodeIf = m_network.getInterface(1, "192.168.1.1");
MockService icmpService = m_network.getService(1, "192.168.1.1", "ICMP");
MockService smtpService = m_network.getService(1, "192.168.1.1", "SMTP");
// Start the poller
startDaemons();
// Kill the critical service on the interface and expect an interfaceDown:
// The node in question has multiple interfaces, so we don't expect a nodeDown.
resetAnticipated();
anticipateDown(nodeIf);
icmpService.bringDown();
verifyAnticipated(10000);
// There should now be a single outage for the SMTP service:
// The critical service on the interface is down, so all
// of the services on that interface are also marked as down.
List<OnmsOutage> smtpOutages = getOutages(smtpService);
assertEquals(1, smtpOutages.size());
assertEquals(null, smtpOutages.get(0).getIfRegainedService());
// Next, we will take the SMTP service offline and bring
// the ICMP service online in order to make
// the poller daemon generate a interfaceDown event
// followed by a nodeLostService event.
//
// The poller daemon will then wait to receive these event back
// from eventd, so that they are populated with the database ids.
//
// When the interfaceDown event is received, it will close
// the previous outages, and when the nodeLostService event is
// received it will create a new outage.
//
// If these events are received in a different order then which
// they were sent, we will end up with two outages in the table.
// This can happen, as observed in NMS-7394, if both events
// are sent shortly one after another.
//
// In order to test the behavior of pollerd, we manually
// manipulate the order of these events.
// Stops all other events until the nodeLostService has been processed
EventOrderAlteringHook hook = new EventOrderAlteringHook(EventConstants.NODE_LOST_SERVICE_EVENT_UEI);
m_eventMgr.setSendNowHook(hook);
anticipateUp(nodeIf);
anticipateDown(smtpService);
smtpService.bringDown();
icmpService.bringUp();
verifyAnticipated(10000);
// There should be two outages in the database:
// one closed with the event id populated and another one pending
smtpOutages = getOutages(smtpService);
assertEquals(2, smtpOutages.size());
assertNotNull(smtpOutages.get(0).getIfRegainedService());
assertNotNull(smtpOutages.get(0).getServiceRegainedEvent());
assertNull(smtpOutages.get(1).getIfRegainedService());
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class TimelineRestService method html.
@GET
@Produces("text/html")
@Transactional
@Path("html/{nodeId}/{ipAddress}/{serviceName}/{start}/{end}/{width}")
public Response html(@Context final UriInfo uriInfo, @PathParam("nodeId") final int nodeId, @PathParam("ipAddress") final String ipAddress, @PathParam("serviceName") final String serviceName, @PathParam("start") final long start, @PathParam("end") final long end, @PathParam("width") final int width) throws IOException {
long delta = end - start;
OnmsOutageCollection onmsOutageCollection = queryOutages(uriInfo, nodeId, ipAddress, serviceName, start, end);
BufferedImage bufferedImage = new BufferedImage(width, 20, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = (Graphics2D) bufferedImage.getGraphics();
graphics2D.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));
graphics2D.setColor(Color.BLACK);
int numLabels = TimescaleDescriptor.computeNumberOfLabels(graphics2D, delta, width);
final StringBuilder htmlBuffer = new StringBuilder();
htmlBuffer.append("<img src=\"/opennms/rest/timeline/image/");
htmlBuffer.append(nodeId);
htmlBuffer.append("/");
htmlBuffer.append(ipAddress);
htmlBuffer.append("/");
htmlBuffer.append(serviceName);
htmlBuffer.append("/");
htmlBuffer.append(start);
htmlBuffer.append("/");
htmlBuffer.append(end);
htmlBuffer.append("/");
htmlBuffer.append(width);
htmlBuffer.append("\" usemap=\"#");
htmlBuffer.append(nodeId);
htmlBuffer.append("-");
htmlBuffer.append(ipAddress);
htmlBuffer.append("-");
htmlBuffer.append(serviceName);
htmlBuffer.append("\"><map name=\"");
htmlBuffer.append(nodeId);
htmlBuffer.append("-");
htmlBuffer.append(ipAddress);
htmlBuffer.append("-");
htmlBuffer.append(serviceName);
htmlBuffer.append("\">");
for (TimescaleDescriptor desc : TIMESCALE_DESCRIPTORS) {
if (desc.match(delta, numLabels)) {
for (OnmsOutage onmsOutage : onmsOutageCollection) {
htmlBuffer.append(desc.getMapEntry(graphics2D, delta, start, width, onmsOutage));
}
break;
}
}
htmlBuffer.append("</map>");
return Response.ok(htmlBuffer.toString()).build();
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class AvailabilityServiceIT method canCalculateAvailability.
@Test
public void canCalculateAvailability() throws Exception {
final MockNetwork mockNetwork = new MockNetwork();
// This test depends on the specifics in the standard network definition
mockNetwork.createStandardNetwork();
m_mockDatabase.populate(mockNetwork);
final RTCCategory rtcCat = EasyMock.createNiceMock(RTCCategory.class);
EasyMock.expect(rtcCat.getLabel()).andReturn("NOC").anyTimes();
EasyMock.expect(rtcCat.getNodes()).andReturn(Lists.newArrayList(1, 2)).anyTimes();
EasyMock.replay(rtcCat);
// Verify the availability when no outages are present
EuiLevel euiLevel = m_availabilityService.getEuiLevel(rtcCat);
assertEquals(1, euiLevel.getCategory().size());
Category category = euiLevel.getCategory().get(0);
assertEquals(100.0, category.getCatvalue(), 0.001);
assertEquals(2, category.getNode().size());
// Assumes the nodes are sorted
assertEquals(4, category.getNode().get(0).getNodesvccount());
assertEquals(2, category.getNode().get(1).getNodesvccount());
// Create an outage that is both open and closed within the window
final Date now = new Date();
final Date oneHourAgo = new Date(now.getTime() - (60 * 60 * 1000));
final Date thirtyMinutesAgo = new Date(now.getTime() - (30 * 60 * 1000));
final OnmsMonitoredService icmpService = toMonitoredService(mockNetwork.getService(1, "192.168.1.1", "ICMP"));
OnmsOutage outage = new OnmsOutage();
outage.setMonitoredService(icmpService);
outage.setIfLostService(oneHourAgo);
outage.setIfRegainedService(thirtyMinutesAgo);
m_outageDao.save(outage);
m_outageDao.flush();
// Verify the availability when outages are present
euiLevel = m_availabilityService.getEuiLevel(rtcCat);
assertEquals(1, euiLevel.getCategory().size());
category = euiLevel.getCategory().get(0);
// This number should only need to be adjusted if the duration of the outage
// or the number of services in the category changes
assertEquals(RTCUtils.getOutagePercentage(1800000, 86400000, 6), category.getCatvalue(), 0.0001);
assertEquals(2, category.getNode().size());
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class DefaultRtcService method calculateServiceDownTime.
private static Map<OnmsMonitoredService, Long> calculateServiceDownTime(Date periodEnd, Date periodStart, List<OnmsOutage> outages) {
Map<OnmsMonitoredService, Long> map = new HashMap<OnmsMonitoredService, Long>();
for (OnmsOutage outage : outages) {
if (map.get(outage.getMonitoredService()) == null) {
map.put(outage.getMonitoredService(), 0L);
}
Date begin;
if (outage.getIfLostService().before(periodStart)) {
begin = periodStart;
} else if (outage.getIfLostService().after(periodEnd)) {
LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after period end {}, discarding outage: {}", periodEnd, outage.toString());
continue;
} else {
begin = outage.getIfLostService();
}
Date end;
if (outage.getIfRegainedService() == null) {
// If the outage hasn't ended yet, use the end of the period as the end time
end = periodEnd;
} else if (outage.getIfRegainedService().after(periodEnd)) {
// If the outage ended after the end of the period, use the end of the period as the end time
end = periodEnd;
} else {
end = outage.getIfRegainedService();
}
if (begin.after(end)) {
LoggerFactory.getLogger(DefaultRtcService.class).warn("Outage beginning is after outage end inside period {} to {}, discarding outage: {}", periodStart, periodEnd, outage.toString());
continue;
} else {
Long count = map.get(outage.getMonitoredService());
count += (end.getTime() - begin.getTime());
map.put(outage.getMonitoredService(), count);
}
}
return map;
}
use of org.opennms.netmgt.model.OnmsOutage 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;
}
}
Aggregations