Search in sources :

Example 1 with CollectionAgentDTO

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>" } });
}
Also used : CollectionAgentDTO(org.opennms.netmgt.collection.dto.CollectionAgentDTO) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with CollectionAgentDTO

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()));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) CollectionAgentDTO(org.opennms.netmgt.collection.dto.CollectionAgentDTO) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) Test(org.junit.Test)

Example 3 with CollectionAgentDTO

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>" } });
}
Also used : ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) CollectionAgentDTO(org.opennms.netmgt.collection.dto.CollectionAgentDTO) Parameters(org.junit.runners.Parameterized.Parameters)

Example 4 with CollectionAgentDTO

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>" } });
}
Also used : CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) CollectionAgentDTO(org.opennms.netmgt.collection.dto.CollectionAgentDTO) Date(java.util.Date) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Parameters(org.junit.runners.Parameterized.Parameters)

Example 5 with CollectionAgentDTO

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;
    }
}
Also used : CollectionAgentDTO(org.opennms.netmgt.collection.dto.CollectionAgentDTO) InetAddress(java.net.InetAddress)

Aggregations

CollectionAgentDTO (org.opennms.netmgt.collection.dto.CollectionAgentDTO)6 Parameters (org.junit.runners.Parameterized.Parameters)3 HashMap (java.util.HashMap)2 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)2 ServiceCollector (org.opennms.netmgt.collection.api.ServiceCollector)2 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 Test (org.junit.Test)1 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)1 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)1 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)1