Search in sources :

Example 26 with CollectionSet

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

the class ThresholdingVisitorIT method runFileSystemDataTestWithCollectionSetBuilder.

private void runFileSystemDataTestWithCollectionSetBuilder(ThresholdingVisitor visitor, int resourceId, String fs, long value, long max) throws Exception {
    SnmpCollectionAgent agent = createCollectionAgent();
    NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
    // Creating Generic ResourceType
    org.opennms.netmgt.config.datacollection.ResourceType indexResourceType = createIndexResourceType(agent, "hrStorageIndex");
    GenericTypeResource genericResource = new GenericTypeResource(nodeResource, indexResourceType, Integer.toString(resourceId));
    // Creating strings.properties file
    ResourcePath path = ResourcePath.get("snmp", "1", "hrStorageIndex", Integer.toString(resourceId));
    m_resourceStorageDao.setStringAttribute(path, "hrStorageType", ".1.3.6.1.2.1.25.2.1.4");
    m_resourceStorageDao.setStringAttribute(path, "hrStorageDescr", fs);
    // Build the collection set
    CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(genericResource, "hd-usage", "hrStorageUsed", value, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageSize", max, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageAllocUnits", 1, AttributeType.GAUGE).build();
    // Run Visitor
    collectionSet.visit(visitor);
    EasyMock.verify(agent);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 27 with CollectionSet

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

the class SnmpCollectorIT method verifyPersistedStringProperties.

@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-brocade-no-ifaces-config.xml", datacollectionType = "snmp", anticipateRrds = { "1/brocadeFCPortIndex/1/swFCPortTxWords", "1/brocadeFCPortIndex/1/swFCPortRxWords", "1/brocadeFCPortIndex/2/swFCPortTxWords", "1/brocadeFCPortIndex/2/swFCPortRxWords", "1/brocadeFCPortIndex/3/swFCPortTxWords", "1/brocadeFCPortIndex/3/swFCPortRxWords", "1/brocadeFCPortIndex/4/swFCPortTxWords", "1/brocadeFCPortIndex/4/swFCPortRxWords", "1/brocadeFCPortIndex/5/swFCPortTxWords", "1/brocadeFCPortIndex/5/swFCPortRxWords", "1/brocadeFCPortIndex/6/swFCPortTxWords", "1/brocadeFCPortIndex/6/swFCPortRxWords", "1/brocadeFCPortIndex/7/swFCPortTxWords", "1/brocadeFCPortIndex/7/swFCPortRxWords", "1/brocadeFCPortIndex/8/swFCPortTxWords", "1/brocadeFCPortIndex/8/swFCPortRxWords" }, anticipateFiles = { "1", "1/brocadeFCPortIndex", "1/brocadeFCPortIndex/1/strings.properties", "1/brocadeFCPortIndex/1", "1/brocadeFCPortIndex/2/strings.properties", "1/brocadeFCPortIndex/2", "1/brocadeFCPortIndex/3/strings.properties", "1/brocadeFCPortIndex/3", "1/brocadeFCPortIndex/4/strings.properties", "1/brocadeFCPortIndex/4", "1/brocadeFCPortIndex/5/strings.properties", "1/brocadeFCPortIndex/5", "1/brocadeFCPortIndex/6/strings.properties", "1/brocadeFCPortIndex/6", "1/brocadeFCPortIndex/7/strings.properties", "1/brocadeFCPortIndex/7", "1/brocadeFCPortIndex/8/strings.properties", "1/brocadeFCPortIndex/8" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/brocadeTestData1.properties")
public void verifyPersistedStringProperties() throws Exception {
    // Perform the collection
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    // Persist
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    // Verify results on disk
    Map<String, String> properties = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "brocadeFCPortIndex", "1"));
    // "string" attributes should convert the octets directly to a string
    String value = properties.get("swFCPortName");
    assertTrue(value.startsWith("..3DUfw"));
    // "hexstring" attributes should convert the octets to a hex string
    // see http://issues.opennms.org/browse/NMS-7367
    value = properties.get("swFCPortWwn");
    assertEquals("1100334455667788", value);
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with CollectionSet

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

the class CollectorTestUtils method failToCollectNTimes.

public static void failToCollectNTimes(RrdStrategy<?, ?> rrdStrategy, ResourceStorageDao resourceStorageDao, CollectionSpecification spec, CollectionAgent agent, int numUpdates) throws InterruptedException, CollectionException {
    for (int i = 0; i < numUpdates; i++) {
        // now do the actual collection
        CollectionSet collectionSet = spec.collect(agent);
        assertEquals("collection status", CollectionStatus.FAILED, collectionSet.getStatus());
        persistCollectionSet(rrdStrategy, resourceStorageDao, spec, collectionSet);
        System.err.println("COLLECTION " + i + " FINISHED");
        //need a one second time elapse to update the RRD
        Thread.sleep(1010);
    }
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 29 with CollectionSet

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

the class AbstractPersistingAdapter method handleMessageLog.

@Override
public void handleMessageLog(TelemetryMessageLog messageLog) {
    for (TelemetryMessage message : messageLog.getMessageList()) {
        final Optional<CollectionSetWithAgent> result;
        try {
            result = handleMessage(message, messageLog);
        } catch (Exception e) {
            LOG.warn("Failed to build a collection set from message: {}. Dropping.", message, e);
            return;
        }
        if (!result.isPresent()) {
            LOG.debug("No collection set was returned when processing message: {}. Dropping.", message);
            return;
        }
        // Locate the matching package definition
        final Package pkg = getPackageFor(protocol, result.get().getAgent());
        if (pkg == null) {
            LOG.warn("No matching package found for message: {}. Dropping.", message);
            return;
        }
        // Build the repository from the package definition
        final RrdRepository repository = new RrdRepository();
        repository.setStep(pkg.getRrd().getStep());
        repository.setHeartBeat(repository.getStep() * 2);
        repository.setRraList(pkg.getRrd().getRras());
        repository.setRrdBaseDir(new File(pkg.getRrd().getBaseDir()));
        // Persist!
        final CollectionSet collectionSet = result.get().getCollectionSet();
        LOG.trace("Persisting collection set: {} for message: {}", collectionSet, message);
        final Persister persister = persisterFactory.createPersister(EMPTY_SERVICE_PARAMETERS, repository);
        collectionSet.visit(persister);
    }
}
Also used : Package(org.opennms.netmgt.telemetry.config.api.Package) Persister(org.opennms.netmgt.collection.api.Persister) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) File(java.io.File) TelemetryMessage(org.opennms.netmgt.telemetry.adapters.api.TelemetryMessage) ExecutionException(java.util.concurrent.ExecutionException) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 30 with CollectionSet

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

the class JtiGpbAdapter method handleMessage.

@Override
public Optional<CollectionSetWithAgent> handleMessage(TelemetryMessage message, TelemetryMessageLog messageLog) throws Exception {
    final TelemetryTop.TelemetryStream jtiMsg = TelemetryTop.TelemetryStream.parseFrom(message.getByteArray(), s_registry);
    CollectionAgent agent = null;
    try {
        // Attempt to resolve the systemId to an InetAddress
        final InetAddress inetAddress = InetAddress.getByName(jtiMsg.getSystemId());
        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: {}", jtiMsg.getSystemId());
    }
    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) {
                final OnmsNode node = Iterables.getFirst(nodeDao.findByLabel(jtiMsg.getSystemId()), 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 inteface for system id: {}", jtiMsg.getSystemId());
        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, jtiMsg);
    return Optional.of(new CollectionSetWithAgent(agent, collectionSet));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) UnknownHostException(java.net.UnknownHostException) TransactionStatus(org.springframework.transaction.TransactionStatus) 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) CollectionSetWithAgent(org.opennms.netmgt.telemetry.adapters.collection.CollectionSetWithAgent) TelemetryTop(org.opennms.netmgt.telemetry.adapters.jti.proto.TelemetryTop) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) InetAddress(java.net.InetAddress)

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