Search in sources :

Example 11 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class CollectorComplianceTest method canCollectUsingOpenNMSWorkflow.

@Test
public void canCollectUsingOpenNMSWorkflow() throws CollectionInitializationException, CollectionException {
    // create the agent
    OnmsNode node = mock(OnmsNode.class);
    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 CollectionAgent agent = createAgent(1, ifaceDao, transMgr);
    // init() should execute without any exceptions
    final ServiceCollector opennmsCollector = getCollector();
    initialize(opennmsCollector);
    // getEffectiveLocation() should execute without any exceptions
    // in this context there are no requirements on its return value
    final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
    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));
    // collect() should return a valid collection set
    final Map<String, Object> allParms = new HashMap<>();
    allParms.putAll(requiredParams);
    allParms.putAll(runtimeAttrs);
    final CollectionSet collectionSet = opennmsCollector.collect(agent, Collections.unmodifiableMap(allParms));
    assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    // getRrdRepository() should return a valid repository
    assertNotNull(opennmsCollector.getRrdRepository(getCollectionName()));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) HashMap(java.util.HashMap) ServiceCollector(org.opennms.netmgt.collection.api.ServiceCollector) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) DefaultCollectionAgent(org.opennms.netmgt.collection.core.DefaultCollectionAgent) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

Example 12 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet 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 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 13 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class NxosGpbAdapter method handleMessage.

@Override
public Optional<CollectionSetWithAgent> handleMessage(TelemetryMessage message, TelemetryMessageLog messageLog) throws Exception {
    final TelemetryBis.Telemetry msg = tryParsingTelemetryMessage(message.getByteArray());
    CollectionAgent agent = null;
    try {
        LOG.debug(" Telemetry message content : {} ", msg);
        final InetAddress inetAddress = InetAddress.getByName(msg.getNodeIdStr());
        final Optional<Integer> nodeId = interfaceToNodeCache.getFirstNodeId(messageLog.getLocation(), inetAddress);
        if (nodeId.isPresent()) {
            // NOTE: This will throw a IllegalArgumentException if the nodeId/inetAddress pair does not exist in the database
            agent = collectionAgentFactory.createCollectionAgent(Integer.toString(nodeId.get()), inetAddress);
        }
    } catch (UnknownHostException e) {
        LOG.debug("Could not convert system id to address: {}", msg.getNodeIdStr());
    }
    if (agent == null) {
        // We were unable to build the agent by resolving the systemId, try finding
        // a node with a matching label
        agent = transactionTemplate.execute(new TransactionCallback<CollectionAgent>() {

            @Override
            public CollectionAgent doInTransaction(TransactionStatus status) {
                OnmsNode node = Iterables.getFirst(nodeDao.findByLabelForLocation(msg.getNodeIdStr(), messageLog.getLocation()), null);
                if (node == null) {
                    // If there is no matching label , Try matching with foreignId
                    node = Iterables.getFirst(nodeDao.findByForeignIdForLocation(msg.getNodeIdStr(), messageLog.getLocation()), null);
                }
                if (node != null) {
                    final OnmsIpInterface primaryInterface = node.getPrimaryInterface();
                    return collectionAgentFactory.createCollectionAgent(primaryInterface);
                }
                return null;
            }
        });
    }
    if (agent == null) {
        LOG.warn("Unable to find node and interface for system id: {}", msg.getNodeIdStr());
        return Optional.empty();
    }
    final ScriptedCollectionSetBuilder builder = scriptedCollectionSetBuilders.get();
    if (builder == null) {
        throw new Exception(String.format("Error compiling script '%s'. See logs for details.", script));
    }
    final CollectionSet collectionSet = builder.build(agent, msg);
    return Optional.of(new CollectionSetWithAgent(agent, collectionSet));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) UnknownHostException(java.net.UnknownHostException) TransactionStatus(org.springframework.transaction.TransactionStatus) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) UnknownHostException(java.net.UnknownHostException) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) TransactionCallback(org.springframework.transaction.support.TransactionCallback) ScriptedCollectionSetBuilder(org.opennms.netmgt.telemetry.adapters.collection.ScriptedCollectionSetBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) TelemetryBis(org.opennms.netmgt.telemetry.adapters.nxos.proto.TelemetryBis) CollectionSetWithAgent(org.opennms.netmgt.telemetry.adapters.collection.CollectionSetWithAgent) Telemetry(org.opennms.netmgt.telemetry.adapters.nxos.proto.TelemetryBis.Telemetry) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) InetAddress(java.net.InetAddress)

Example 14 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class AbstractVTDXmlCollectorTest method executeCollectorTest.

/**
 * Executes collector test.
 *
 * @param parameters the parameters
 * @param expectedFiles the expected amount of JRB files
 * @throws Exception the exception
 */
public void executeCollectorTest(Map<String, Object> parameters, int expectedFiles) throws Exception {
    XmlCollector collector = new XmlCollector();
    collector.setXmlCollectionDao(m_xmlCollectionDao);
    CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(collector, m_collectionAgent, parameters);
    Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
    CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String) parameters.get("collection")), false, false);
    collectionSet.visit(persister);
    Assert.assertEquals(expectedFiles, FileUtils.listFiles(getSnmpRoot(), new String[] { "jrb" }, true).size());
}
Also used : XmlCollector(org.opennms.protocols.xml.collector.XmlCollector) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 15 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class ThresholdingVisitorIT method testThresholdsFiltersOnNodeResourceWithCollectionSetBuilder.

/**
 * Similar to {@link #testThresholdsFiltersOnNodeResource()}, but
 * we generate the collection set using the CollectionSetBuilder instead
 * of using SnmpCollector specific types.
 */
@Test
public void testThresholdsFiltersOnNodeResourceWithCollectionSetBuilder() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-5.xml");
    ThresholdingVisitor visitor = createVisitor();
    // Adding Expected Thresholds
    addHighThresholdEvent(1, 30, 25, 50, "/home", "node", "(hda1_hrStorageUsed/hda1_hrStorageSize)*100", null, null);
    addHighThresholdEvent(1, 50, 45, 60, "/opt", "node", "(hda2_hrStorageUsed/hda2_hrStorageSize)*100", null, null);
    // Creating Node ResourceType
    SnmpCollectionAgent agent = createCollectionAgent();
    NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
    CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(nodeResource, "hd-usage", "hda1_hrStorageUsed", 50, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda1_hrStorageSize", 100, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda2_hrStorageUsed", 60, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda2_hrStorageSize", 100, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda3_hrStorageUsed", 70, AttributeType.GAUGE).withNumericAttribute(nodeResource, "hd-usage", "hda3_hrStorageSize", 100, AttributeType.GAUGE).build();
    // Creating strings.properties file
    ResourcePath path = ResourcePath.get("snmp", "1");
    m_resourceStorageDao.setStringAttribute(path, "hda1_hrStorageDescr", "/home");
    m_resourceStorageDao.setStringAttribute(path, "hda2_hrStorageDescr", "/opt");
    m_resourceStorageDao.setStringAttribute(path, "hda3_hrStorageDescr", "/usr");
    // Run Visitor and Verify Events
    collectionSet.visit(visitor);
    EasyMock.verify(agent);
    verifyEvents(0);
}
Also used : CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) ResourcePath(org.opennms.netmgt.model.ResourcePath) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

Aggregations

CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)52 Test (org.junit.Test)30 HashMap (java.util.HashMap)17 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)17 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)11 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)11 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)10 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)10 File (java.io.File)9 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)8 RrdDb (org.jrobin.core.RrdDb)7 JUnitCollector (org.opennms.core.collection.test.JUnitCollector)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)6 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)6 Map (java.util.Map)5 Datasource (org.jrobin.core.Datasource)5 Date (java.util.Date)4 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)4 ResourcePath (org.opennms.netmgt.model.ResourcePath)4