use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class DefaultDistributedStatusServiceTest method expectResourceDaoCall.
private void expectResourceDaoCall(OnmsLocationMonitor monitor, Collection<OnmsMonitoredService> services) {
PrefabGraph httpGraph = new PrefabGraph("http", "title", new String[] { "http" }, "command", new String[0], new String[0], 0, new String[] { "distributedStatus" }, null, null, null, new String[0]);
PrefabGraph httpsGraph = new PrefabGraph("https", "title", new String[] { "https" }, "command", new String[0], new String[0], 0, new String[] { "distributedStatus" }, null, null, null, new String[0]);
for (OnmsMonitoredService service : services) {
OnmsResource resource = new OnmsResource("foo", "even more foo", new MockResourceType(), new HashSet<OnmsAttribute>(0), ResourcePath.get("foo"));
expect(m_resourceDao.getResourceForIpInterface(service.getIpInterface(), monitor)).andReturn(resource);
expect(m_graphDao.getPrefabGraphsForResource(resource)).andReturn(new PrefabGraph[] { httpGraph, httpsGraph });
}
expect(m_graphDao.getPrefabGraph(httpGraph.getName())).andReturn(httpGraph).anyTimes();
expect(m_graphDao.getPrefabGraph(httpsGraph.getName())).andReturn(httpsGraph).atLeastOnce();
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class RrdDashletConfigurationWindow method setRrdGraphEntryFromKscReportGraph.
private void setRrdGraphEntryFromKscReportGraph(RrdGraphEntry rrdGraphEntry, Graph graph) {
String graphLabel, graphId, graphUrl, nodeId, nodeLabel, resourceLabel, resourceTypeId, resourceTypeLabel;
String[] graphTypeArr = graph.getGraphtype().split("\\.");
String[] resourceIdArr = graph.getResourceId().orElse("").split("\\.");
nodeId = resourceIdArr[0].split("[\\[\\]]")[1];
String resourceTypeName = resourceIdArr[1].split("[\\[\\]]")[0];
OnmsNode onmsNode = m_nodeDao.get(nodeId);
nodeLabel = onmsNode.getLabel();
Map<OnmsResourceType, List<OnmsResource>> resourceTypeListMap = m_rrdGraphHelper.getResourceTypeMapForNodeId(nodeId);
for (Map.Entry<OnmsResourceType, List<OnmsResource>> entry : resourceTypeListMap.entrySet()) {
OnmsResourceType onmsResourceType = entry.getKey();
if (resourceTypeName.equals(onmsResourceType.getName())) {
resourceTypeId = "node[" + nodeId + "]." + resourceTypeName;
resourceTypeLabel = onmsResourceType.getLabel();
List<OnmsResource> onmsResourceList = entry.getValue();
for (OnmsResource onmsResource : onmsResourceList) {
String onmsResourceId = onmsResource.getId().toString();
if (onmsResourceId.equals(graph.getResourceId())) {
resourceLabel = onmsResource.getLabel();
Map<String, String> resultsMap = m_rrdGraphHelper.getGraphResultsForResourceId(onmsResource.getId());
Map<String, String> nameTitleMapping = m_rrdGraphHelper.getGraphNameTitleMappingForResourceId(onmsResource.getId());
graphId = onmsResourceId + "." + nameTitleMapping.get(graph.getGraphtype());
graphLabel = nameTitleMapping.get(graph.getGraphtype());
graphUrl = resultsMap.get(graph.getGraphtype());
rrdGraphEntry.setNodeId(nodeId);
rrdGraphEntry.setNodeLabel(nodeLabel);
rrdGraphEntry.setResourceTypeId(resourceTypeId);
rrdGraphEntry.setResourceTypeLabel(resourceTypeLabel);
rrdGraphEntry.setResourceId(onmsResourceId);
rrdGraphEntry.setResourceLabel(resourceLabel);
rrdGraphEntry.setGraphId(graphId);
rrdGraphEntry.setGraphLabel(graphLabel);
rrdGraphEntry.setGraphUrl(graphUrl);
break;
}
}
break;
}
}
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class TopNAttributeStatisticVisitorTest method testVisitGetResultsLimitedByCount.
public void testVisitGetResultsLimitedByCount() throws Exception {
BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
visitor.setCount(20);
visitor.afterPropertiesSet();
Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
for (int i = 0; i < 100; i++) {
attributes.put(new MockAttribute("foo"), 0.0 + i);
}
OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
resource.getAttributes();
for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
visitor.visit(entry.getKey(), entry.getValue());
}
SortedSet<AttributeStatistic> top = visitor.getResults();
assertNotNull("topN list should not be null", top);
assertEquals("topN list size", 20, top.size());
int i = 0;
for (AttributeStatistic stat : top) {
assertEquals("topN[" + i + "] value", 99.0 - i, stat.getStatistic());
i++;
}
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class RrdResourceAttributeUtilsTest method testLoadPropertiesNonEmpty.
@Test
public void testLoadPropertiesNonEmpty() throws Exception {
OnmsResource childResource = createResource();
createPropertiesFile(childResource, "foo=bar", false);
Properties p = RrdResourceAttributeUtils.getStringProperties(m_fileAnticipator.getTempDir(), "snmp/1/eth0");
assertNotNull("properties should not be null", p);
assertEquals("properties size", 1, p.size());
assertNotNull("property 'foo' should exist", p.get("foo"));
assertEquals("property 'foo' value", "bar", p.get("foo"));
}
use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.
the class RrdResourceAttributeUtilsTest method testLoadPropertiesDoesNotExist.
@Test
public void testLoadPropertiesDoesNotExist() throws Exception {
OnmsResource childResource = createResource();
createPropertiesFile(childResource, "", true);
Properties p = RrdResourceAttributeUtils.getStringProperties(m_fileAnticipator.getTempDir(), "snmp/1/eth0");
assertNull("no properties file was created, so the properties object should be null", p);
}
Aggregations