/** * <p>toString</p> * * @return a {@link java.lang.String} object. */ @Override public String toString() { return getId().toString(); }
private static String[] getRrdNames(OnmsResource resource, String[] dsNames) { String[] rrds = new String[dsNames.length]; Map<String, RrdGraphAttribute> attributes = resource.getRrdGraphAttributes(); for (int i=0; i < dsNames.length; i++) { RrdGraphAttribute attribute = attributes.get(dsNames[i]); if (attribute == null) { throw new IllegalArgumentException("RRD attribute '" + dsNames[i] + "' is not available on resource '" + resource.getId() + "'. Available RRD attributes: " + StringUtils.collectionToDelimitedString(attributes.keySet(), ", ")); } rrds[i] = RrdFileConstants.escapeForGraphing(attribute.getRrdRelativePath()); } return rrds; }
private static String[] getRrdNames(OnmsResource resource, String[] dsNames) { String[] rrds = new String[dsNames.length]; Map<String, RrdGraphAttribute> attributes = resource.getRrdGraphAttributes(); for (int i=0; i < dsNames.length; i++) { RrdGraphAttribute attribute = attributes.get(dsNames[i]); if (attribute == null) { throw new IllegalArgumentException("RRD attribute '" + dsNames[i] + "' is not available on resource '" + resource.getId() + "'. Available RRD attributes: " + StringUtils.collectionToDelimitedString(attributes.keySet(), ", ")); } rrds[i] = RrdFileConstants.escapeForGraphing(attribute.getRrdRelativePath()); } return rrds; }
/** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @Override public int compare(AttributeStatistic o1, AttributeStatistic o2) { int diff; diff = getComparator().compare(o1.getStatistic(), o2.getStatistic()); if (diff != 0) { return diff; } diff = o1.getAttribute().getResource().getId().toString().compareToIgnoreCase(o2.getAttribute().getResource().getId().toString()); if (diff != 0) { return diff; } return Integer.valueOf(o1.getAttribute().hashCode()).compareTo(o2.getAttribute().hashCode()); } }
/** * <p>compareTo</p> * * @see java.lang.Comparable#compareTo(java.lang.Object) * @param o a {@link org.opennms.netmgt.model.AttributeStatistic} object. * @return a int. */ @Override public int compareTo(final AttributeStatistic o) { int diff; diff = getStatistic().compareTo(o.getStatistic()); if (diff != 0) { return diff; } diff = getAttribute().getResource().getId().toString().compareToIgnoreCase(o.getAttribute().getResource().getId().toString()); if (diff != 0) { return diff; } return Integer.valueOf(getAttribute().hashCode()).compareTo(o.getAttribute().hashCode()); } }
/** {@inheritDoc} */ @Override public void persist(ReportInstance report) { System.out.println("Top " + report.getCount() + " " + report.getAttributeMatch() + " data sources on resources of type " + report.getResourceTypeMatch() + " from " + new Date(report.getStartTime()) + " to " + new Date(report.getEndTime())); SortedSet<AttributeStatistic> top = report.getResults(); for (AttributeStatistic stat : top) { System.out.println(stat.getAttribute().getResource().getId() + "/" + stat.getAttribute().getName() + ": " + stat.getStatistic()); } System.out.println(""); } }
@Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { Integer onmsNodeId = (Integer) m_nodeSelect.getValue(); m_resourceSelect.removeAllItems(); if (onmsNodeId != null) { Map<OnmsResourceType, List<OnmsResource>> map = getSurveillanceViewService().getResourceTypeMapForNodeId(onmsNodeId); for (OnmsResourceType onmsResourceType : map.keySet()) { for (OnmsResource onmsResource : map.get(onmsResourceType)) { m_resourceSelect.addItem(onmsResource.getId().toString()); m_resourceSelect.setItemCaption(onmsResource.getId().toString(), onmsResourceType.getLabel() + ": " + onmsResource.getLabel()); } } Iterator<?> i = m_resourceSelect.getItemIds().iterator(); if (i.hasNext()) { m_resourceSelect.select(i.next()); } } } });
@Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { Integer onmsNodeId = (Integer) m_nodeSelect.getValue(); m_resourceSelect.removeAllItems(); if (onmsNodeId != null) { Map<OnmsResourceType, List<OnmsResource>> map = getSurveillanceViewService().getResourceTypeMapForNodeId(onmsNodeId); for (OnmsResourceType onmsResourceType : map.keySet()) { for (OnmsResource onmsResource : map.get(onmsResourceType)) { m_resourceSelect.addItem(onmsResource.getId().toString()); m_resourceSelect.setItemCaption(onmsResource.getId().toString(), onmsResourceType.getLabel() + ": " + onmsResource.getLabel()); } } Iterator<?> i = m_resourceSelect.getItemIds().iterator(); if (i.hasNext()) { m_resourceSelect.select(i.next()); } } } });
@Override public Map<String, String> doInTransaction(TransactionStatus transactionStatus) { Map<String, String> data = new HashMap<>(); ResourceId resourceId = ResourceId.fromString(resourceIdString); OnmsNode node; OnmsResource resource; if(nodeId == null){ resource = determineResourceByResourceId(resourceId); node = ResourceTypeUtils.getNodeFromResource(resource); } else { node = m_nodeDao.get(nodeId); resource = m_resourceDao.getResourceForNode(node); } data.put("nodeId", node.getNodeId()); data.put("nodeLabel", node.getLabel()); for (OnmsResource onmsResource : resource.getChildResources()) { if (resourceId.equals(onmsResource.getId())) { data.put("resourceLabel", onmsResource.getLabel()); data.put("resourceTypeLabel", onmsResource.getResourceType().getLabel()); break; } } return data; } });
@Override public Map<String, String> doInTransaction(TransactionStatus transactionStatus) { Map<String, String> data = new HashMap<>(); ResourceId resourceId = ResourceId.fromString(resourceIdString); OnmsNode node; OnmsResource resource; if(nodeId == null){ resource = determineResourceByResourceId(resourceId); node = ResourceTypeUtils.getNodeFromResource(resource); } else { node = m_nodeDao.get(nodeId); resource = m_resourceDao.getResourceForNode(node); } data.put("nodeId", node.getNodeId()); data.put("nodeLabel", node.getLabel()); for (OnmsResource onmsResource : resource.getChildResources()) { if (resourceId.equals(onmsResource.getId())) { data.put("resourceLabel", onmsResource.getLabel()); data.put("resourceTypeLabel", onmsResource.getResourceType().getLabel()); break; } } return data; } });
private static QueryResource getResourceInfo(final OnmsResource resource, final Source source) { if (resource == null) return null; OnmsNode node = null; try { node = ResourceTypeUtils.getNodeFromResourceRoot(resource); } catch (final ObjectRetrievalFailureException e) { LOG.warn("Failed to get node info from resource: {}", resource, e); } return new QueryResource( resource.getId().toString(), resource.getParent() == null? null : resource.getParent().getId().toString(), resource.getLabel(), resource.getName(), node == null? null : new QueryNode(node.getId(), node.getForeignSource(), node.getForeignId(), node.getLabel()) ); } }
private QueryResource getResourceInfo(final OnmsResource resource, final Source source) { if (resource == null) return null; final OnmsNode node = getNode(resource, source); return new QueryResource( resource.getId().toString(), resource.getParent() == null? null : resource.getParent().getId().toString(), resource.getLabel(), resource.getName(), node == null? null : new QueryNode(node.getId(), node.getForeignSource(), node.getForeignId(), node.getLabel()) ); } }
/** * <p>getId</p> * * @return a {@link java.lang.String} object. */ public ResourceId getId() { if (this.getParent() != null) { return getParent().getId().resolve(getResourceType().getName(), getName()); } else { return ResourceId.get(getResourceType().getName(), getName()); } }
/** {@inheritDoc} */ @Override public void persist(ReportInstance report) { StatisticsReport dbReport = new StatisticsReport(); dbReport.setName(report.getName()); dbReport.setDescription(report.getDescription()); dbReport.setStartDate(new Date(report.getStartTime())); dbReport.setEndDate(new Date(report.getEndTime())); dbReport.setJobStartedDate(report.getJobStartedDate()); dbReport.setJobCompletedDate(report.getJobCompletedDate()); dbReport.setPurgeDate(new Date(report.getJobCompletedDate().getTime() + report.getRetainInterval())); for (AttributeStatistic stat : report.getResults()) { ResourceReference resource = getResourceReference(stat.getAttribute().getResource().getId().toString()); StatisticsReportData data = new StatisticsReportData(); data.setResource(resource); data.setReport(dbReport); data.setValue(stat.getStatistic()); dbReport.addData(data); LOG.debug("Adding {}", data); } if (dbReport.getData().isEmpty()) { LOG.warn("Cannot store {} because it doesn't contain data. Probably all the metrics are NaN for the report period.", report); } else { m_statisticsReportDao.save(dbReport); } }
private ServiceGraph getServiceGraphForService(OnmsLocationMonitor locMon, OnmsMonitoredService service, long[] times) { OnmsResource resource; try { resource = m_resourceDao.getResourceForIpInterface(service.getIpInterface(), locMon); } catch (ObjectRetrievalFailureException e) { resource = null; } if (resource == null) { return new ServiceGraph(service, new String[] { "Resource could not be found. Has any response time data been collected for this service from this remote poller?" }); } String graphName = service.getServiceName().toLowerCase(); try { m_graphDao.getPrefabGraph(graphName); } catch (ObjectRetrievalFailureException e) { return new ServiceGraph(service, new String[] { "Graph definition could not be found for '" + graphName + "'. A graph definition needs to be created for this service." }); } PrefabGraph[] prefabGraphs = m_graphDao.getPrefabGraphsForResource(resource); for (PrefabGraph graph : prefabGraphs) { if (graph.getName().equals(graphName)) { String url = "graph/graph.png" + "?report=" + Util.encode(graph.getName()) + "&resourceId=" + Util.encode(resource.getId().toString()) + "&start=" + times[0] + "&end=" + times[1]; return new ServiceGraph(service, url); } } return new ServiceGraph(service, new String[] { "Graph could not be found for '" + graphName + "' on this resource. Has any response time data been collected for this service from this remote poller and is the graph definition correct?" }); }
private ServiceGraph getServiceGraphForService(OnmsLocationMonitor locMon, OnmsMonitoredService service, long[] times) { OnmsResource resource; try { resource = m_resourceDao.getResourceForIpInterface(service.getIpInterface(), locMon); } catch (ObjectRetrievalFailureException e) { resource = null; } if (resource == null) { return new ServiceGraph(service, new String[] { "Resource could not be found. Has any response time data been collected for this service from this remote poller?" }); } String graphName = service.getServiceName().toLowerCase(); try { m_graphDao.getPrefabGraph(graphName); } catch (ObjectRetrievalFailureException e) { return new ServiceGraph(service, new String[] { "Graph definition could not be found for '" + graphName + "'. A graph definition needs to be created for this service." }); } PrefabGraph[] prefabGraphs = m_graphDao.getPrefabGraphsForResource(resource); for (PrefabGraph graph : prefabGraphs) { if (graph.getName().equals(graphName)) { String url = "graph/graph.png" + "?report=" + Util.encode(graph.getName()) + "&resourceId=" + Util.encode(resource.getId().toString()) + "&start=" + times[0] + "&end=" + times[1]; return new ServiceGraph(service, url); } } return new ServiceGraph(service, new String[] { "Graph could not be found for '" + graphName + "' on this resource. Has any response time data been collected for this service from this remote poller and is the graph definition correct?" }); }
public static ResourceDTO fromResource(final OnmsResource resource, final int depth) { final ResourceDTO dto = new ResourceDTO(); dto.setId(resource.getId().toString()); dto.setLabel(resource.getLabel()); dto.setName(resource.getName()); dto.setLink(resource.getLink()); dto.setTypeLabel(resource.getResourceType().getLabel()); dto.setParentId(resource.getParent() == null ? null : resource.getParent().getId().toString()); dto.setStringPropertyAttributes(resource.getStringPropertyAttributes()); dto.setExternalValueAttributes(resource.getExternalValueAttributes()); dto.setRrdGraphAttributes(resource.getRrdGraphAttributes()); dto.setResource(resource); if (depth == 0) { dto.setChildren(null); } else { List<ResourceDTO> children = new LinkedList<>(); for (final OnmsResource child : resource.getChildResources()) { children.add(ResourceDTO.fromResource(child, depth - 1)); } dto.setChildren(new ResourceDTOCollection(children)); } return dto; } }
private static Report buildResourceReport(ResourceService service, OnmsResource parentResource, String title) { Report report = new Report(); report.setTitle(title); report.setShowTimespanButton(true); report.setShowGraphtypeButton(true); List<OnmsResource> resources = service.findChildResources(parentResource, "interfaceSnmp"); for (OnmsResource resource : resources) { PrefabGraph[] graphs = service.findPrefabGraphsForResource(resource); if (graphs.length == 0) { continue; } Graph graph = new Graph(); graph.setTitle(""); graph.setResourceId(resource.getId().toString()); graph.setTimespan("7_day"); graph.setGraphtype(graphs[0].getName()); report.addGraph(graph); } return report; }
private static Report buildResourceReport(ResourceService service, OnmsResource parentResource, String title) { Report report = new Report(); report.setTitle(title); report.setShowTimespanButton(true); report.setShowGraphtypeButton(true); List<OnmsResource> resources = service.findChildResources(parentResource, "interfaceSnmp"); for (OnmsResource resource : resources) { PrefabGraph[] graphs = service.findPrefabGraphsForResource(resource); if (graphs.length == 0) { continue; } Graph graph = new Graph(); graph.setTitle(""); graph.setResourceId(resource.getId().toString()); graph.setTimespan("7_day"); graph.setGraphtype(graphs[0].getName()); report.addGraph(graph); } return report; }