use of org.opennms.netmgt.collection.dto.CollectionAgentDTO in project opennms by OpenNMS.
the class CollectionAgentDTOTest method data.
@Parameters
public static Collection<Object[]> data() throws ParseException {
CollectionAgentDTO collectionAgentDTO = new CollectionAgentDTO();
collectionAgentDTO.setType(42);
collectionAgentDTO.setAddress(InetAddressUtils.getInetAddress("192.168.1.1"));
collectionAgentDTO.setAttribute("k1", "v1");
collectionAgentDTO.setStoreByForeignSource(true);
collectionAgentDTO.setNodeId(99);
collectionAgentDTO.setNodeLabel("switch");
collectionAgentDTO.setForeignSource("fs");
collectionAgentDTO.setForeignId("fid");
collectionAgentDTO.setLocationName("HQ");
collectionAgentDTO.setStorageResourcePath(ResourcePath.get("tmp", "foo"));
collectionAgentDTO.setSysObjectId(".1.3.6");
collectionAgentDTO.setSavedSysUpTime(149);
return Arrays.asList(new Object[][] { { collectionAgentDTO, "<agent type=\"42\" address=\"192.168.1.1\" store-by-fs=\"true\" node-id=\"99\" node-label=\"switch\" foreign-source=\"fs\" foreign-id=\"fid\" location=\"HQ\" storage-resource-path=\"tmp/foo\" sys-object-id=\".1.3.6\" sys-up-time=\"149\">\n" + " <attribute key=\"k1\"><![CDATA[v1]]></attribute>\n" + "</agent>" } });
}
use of org.opennms.netmgt.collection.dto.CollectionAgentDTO in project opennms by OpenNMS.
the class CollectorComplianceTest method canCollectUsingMinionWorkflow.
@Test
public void canCollectUsingMinionWorkflow() throws CollectionInitializationException, CollectionException {
Assume.assumeTrue(runsOnMinion);
// create the agent
OnmsNode node = mock(OnmsNode.class);
when(node.getId()).thenReturn(1);
OnmsIpInterface iface = mock(OnmsIpInterface.class);
when(iface.getNode()).thenReturn(node);
when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress());
IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class);
when(ifaceDao.load(1)).thenReturn(iface);
PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class);
final SnmpCollectionAgent agent = DefaultCollectionAgent.create(1, ifaceDao, transMgr);
// init() should execute without any exceptions
final ServiceCollector opennmsCollector = getCollector();
initialize(opennmsCollector);
// getEffectiveLocation() should return the original location
final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
assertEquals("Location cannot be altered.", targetLocation, opennmsCollector.getEffectiveLocation(targetLocation));
// getRuntimeAttributes() should return a valid map
final Map<String, Object> requiredParams = getRequiredParameters();
final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams));
// marshalParameters() should marshal all parameters to strings
final Map<String, Object> allParms = new HashMap<>();
allParms.putAll(requiredParams);
allParms.putAll(runtimeAttrs);
final Map<String, String> marshaledParms = opennmsCollector.marshalParameters(Collections.unmodifiableMap(allParms));
beforeMinion();
// create a separate instance of the collector
final ServiceCollector minionCollector = getNewCollector();
// unmarshalParameters() should unmarshal all parameters from strings
final Map<String, Object> unmarshaledParms = minionCollector.unmarshalParameters(Collections.unmodifiableMap(marshaledParms));
// collect() should return a valid collection set
final CollectionAgentDTO agentDTO = new CollectionAgentDTO(agent);
final CollectionSet collectionSet = minionCollector.collect(agentDTO, Collections.unmodifiableMap(unmarshaledParms));
assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
afterMinion();
// the collection set should be marshalable
JaxbUtils.marshal(collectionSet);
// getRrdRepository() should return a valid repository
assertNotNull(opennmsCollector.getRrdRepository(getCollectionName()));
}
use of org.opennms.netmgt.collection.dto.CollectionAgentDTO in project opennms by OpenNMS.
the class CollectorRequestDTOTest method data.
@Parameters
public static Collection<Object[]> data() throws Exception {
CollectionAgentDTO agent = new CollectionAgentDTO();
CollectorRequestDTO request = new CollectorRequestDTO();
request.setAgent(agent);
request.setLocation("HQ");
request.setClassName(ServiceCollector.class.getCanonicalName());
request.addAttribute("key", "value");
return Arrays.asList(new Object[][] { { request, "<collector-request location=\"HQ\" class-name=\"org.opennms.netmgt.collection.api.ServiceCollector\">\n" + " <agent type=\"0\" node-id=\"0\" sys-up-time=\"0\"/>\n" + " <attribute key=\"key\"><![CDATA[value]]></attribute>\n" + "</collector-request>" } });
}
use of org.opennms.netmgt.collection.dto.CollectionAgentDTO in project opennms by OpenNMS.
the class CollectorResponseDTOTest method data.
@Parameters
public static Collection<Object[]> data() throws Exception {
CollectionAgentDTO agent = new CollectionAgentDTO();
CollectionSet collectionSet = new CollectionSetBuilder(agent).withTimestamp(new Date(0)).build();
CollectorResponseDTO response = new CollectorResponseDTO(collectionSet);
return Arrays.asList(new Object[][] { { response, "<collector-response>\n" + " <collection-set status=\"SUCCEEDED\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + " <agent type=\"0\" node-id=\"0\" sys-up-time=\"0\"/>\n" + " </collection-set>\n" + "</collector-response>" } });
}
use of org.opennms.netmgt.collection.dto.CollectionAgentDTO in project opennms by OpenNMS.
the class CollectCommand method getCollectionAgent.
private CollectionAgent getCollectionAgent() {
final InetAddress hostAddr = InetAddrUtils.addr(host);
if (nodeCriteria != null) {
return collectionAgentFactory.createCollectionAgentAndOverrideLocation(nodeCriteria, hostAddr, location);
} else {
System.out.println("NOTE: Some collectors require a database node and IP interface.\n");
final CollectionAgentDTO agent = new CollectionAgentDTO();
agent.setLocationName(location);
agent.setAddress(hostAddr);
agent.setStorageResourcePath(ResourcePath.fromString(""));
return agent;
}
}
Aggregations