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<OnmsOutage>();
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;
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class DaoWebOutageRepositoryIT method createNodeEventAndOutage.
protected void createNodeEventAndOutage(String location, String label, String ip, String svc) {
OnmsMonitoringLocation onmsMonitoringLocation = m_dbPopulator.getMonitoringLocationDao().get(location);
if (onmsMonitoringLocation == null) {
onmsMonitoringLocation = new OnmsMonitoringLocation();
onmsMonitoringLocation.setLocationName(location);
onmsMonitoringLocation.setLatitude(1.0f);
onmsMonitoringLocation.setLongitude(1.0f);
onmsMonitoringLocation.setMonitoringArea(location);
onmsMonitoringLocation.setPriority(1L);
m_dbPopulator.getMonitoringLocationDao().save(onmsMonitoringLocation);
}
List<OnmsNode> nodes = m_dbPopulator.getNodeDao().findByLabel(label);
OnmsNode node = (nodes.size() == 1 ? nodes.get(0) : null);
if (node == null) {
node = new OnmsNode(m_dbPopulator.getMonitoringLocationDao().get(location), label);
node.setForeignSource(location);
node.setForeignId(label);
m_dbPopulator.getNodeDao().save(node);
}
int nodeId = m_dbPopulator.getNodeDao().findByForeignId(location, label).getId();
OnmsIpInterface ipInterface = m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip);
if (ipInterface == null) {
ipInterface = new OnmsIpInterface(addr(ip), node);
}
OnmsMonitoredService monitoredService = ipInterface.getMonitoredServiceByServiceType(svc);
if (monitoredService == null) {
monitoredService = new OnmsMonitoredService(m_dbPopulator.getIpInterfaceDao().findByNodeIdAndIpAddress(nodeId, ip), m_dbPopulator.getServiceTypeDao().findByName(svc));
m_dbPopulator.getMonitoredServiceDao().save(monitoredService);
}
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_dbPopulator.getDistPollerDao().whoami());
event.setEventUei("uei.opennms.org/" + location + "/" + label);
event.setEventTime(new Date());
event.setEventSource(location + "/" + label);
event.setEventCreateTime(new Date());
event.setEventSeverity(OnmsSeverity.CLEARED.getId());
event.setEventLog("Y");
event.setEventDisplay("N");
m_dbPopulator.getEventDao().save(event);
m_dbPopulator.getEventDao().flush();
OnmsOutage outage = new OnmsOutage(new Date(), event, monitoredService);
outage.setServiceLostEvent(event);
m_dbPopulator.getOutageDao().save(outage);
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class TimelineRestService method image.
@GET
@Produces("image/png")
@Transactional
@Path("image/{nodeId}/{ipAddress}/{serviceName}/{start}/{end}/{width}")
public Response image(@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);
for (TimescaleDescriptor desc : TIMESCALE_DESCRIPTORS) {
if (desc.match(delta, numLabels)) {
desc.drawGreen(graphics2D, width);
for (OnmsOutage onmsOutage : onmsOutageCollection) {
desc.drawEvent(graphics2D, delta, start, width, onmsOutage);
}
desc.drawLine(graphics2D, delta, start, width);
break;
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", baos);
byte[] imageData = baos.toByteArray();
return Response.ok(imageData).build();
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class OutageRestService method getOutage.
/**
* <p>getOutage</p>
*
* @param outageId a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.model.OnmsOutage} object.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Path("{outageId}")
@Transactional
public Response getOutage(@Context final UriInfo uriInfo, @PathParam("outageId") final String outageId) {
if ("summaries".equals(outageId)) {
final MultivaluedMap<String, String> parms = uriInfo.getQueryParameters(true);
int limit = 10;
if (parms.containsKey("limit")) {
limit = Integer.parseInt(parms.getFirst("limit"));
}
final List<OutageSummary> collection = m_outageDao.getNodeOutageSummaries(limit);
return collection == null ? Response.status(Status.NOT_FOUND).build() : Response.ok(new OutageSummaryCollection(collection)).build();
} else {
final OnmsOutage outage = m_outageDao.get(Integer.valueOf(outageId));
return outage == null ? Response.status(Status.NOT_FOUND).build() : Response.ok(outage).build();
}
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class DefaultCategoryStatusServiceTest method testGetCategoriesStatus.
public void testGetCategoriesStatus() {
View view = new View();
Section section = new Section();
section.setSectionName("Section One");
section.addCategory("Category One");
OnmsOutage outage = new OnmsOutage();
Collection<OnmsOutage> outages = new ArrayList<OnmsOutage>();
outage.setId(300);
OnmsServiceType svcType = new OnmsServiceType();
svcType.setId(3);
svcType.setName("HTTP");
OnmsNode node = new OnmsNode();
node.setId(1);
node.setLabel("superLabel");
OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
iface.setSnmpInterface(snmpIface);
//iface.setId(9);
OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
outage.setMonitoredService(monSvc);
outages.add(outage);
view.addSection(section);
List<String> services = new ArrayList<String>();
services.add("HTTP");
// ServiceSelector selector = new ServiceSelector("isHTTP",(List<String>) services);
expect(viewDisplayDao.getView()).andReturn(view);
expect(categoryDao.getCategoryByLabel("Category One")).andReturn(createCategoryFromLabel("Category One"));
expect(outageDao.matchingCurrentOutages(isA(ServiceSelector.class))).andReturn(outages);
replay(categoryDao);
replay(viewDisplayDao);
replay(outageDao);
Collection<StatusSection> statusSections = categoryStatusService.getCategoriesStatus();
verify(viewDisplayDao);
verify(categoryDao);
verify(outageDao);
assertEquals("Wrong Number of StatusSections", view.getSections().size(), statusSections.size());
for (StatusSection statusSection : statusSections) {
assertEquals("StatusSection Name Does Not Match", "Section One", statusSection.getName());
Collection<StatusCategory> statusCategorys = statusSection.getCategories();
for (StatusCategory statusCategory : statusCategorys) {
assertEquals("StatusCategoryName does not match", "Category One", statusCategory.getLabel());
//assertEquals("Category Comment Does not match","Category One Comment",statusCategory.getComment());
assertTrue("Nodes >= 1", statusCategory.getNodes().size() >= 1);
for (StatusNode statusNode : statusCategory.getNodes()) {
assertEquals("Label does not match", "superLabel", statusNode.getLabel());
}
}
}
}
Aggregations