Search in sources :

Example 1 with GenericTypeResource

use of org.opennms.netmgt.collection.support.builder.GenericTypeResource in project opennms by OpenNMS.

the class CollectionSetDTOTest method data.

@Parameters
public static Collection<Object[]> data() throws ParseException {
    CollectionAgent collectionAgent = mock(CollectionAgent.class);
    NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
    InterfaceLevelResource interfaceLevelResource = new InterfaceLevelResource(nodeLevelResource, "eth0");
    ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
    when(rt.getName()).thenReturn("Charles");
    when(rt.getStorageStrategy().getClazz()).thenReturn(MockStorageStrategy.class.getCanonicalName());
    when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(MockPersistenceSelectorStrategy.class.getCanonicalName());
    DeferredGenericTypeResource deferredGenericTypeResource = new DeferredGenericTypeResource(nodeLevelResource, "Charles", "id");
    GenericTypeResource genericTypeResource = new GenericTypeResource(nodeLevelResource, rt, "idx");
    genericTypeResource.setTimestamp(new Date(0));
    ResourceTypeMapper.getInstance().setResourceTypeMapper((name) -> rt);
    // For complete coverage make sure that there is at least one attribute
    // for every different resource type, and that every different type
    // of attribute is represented at least once
    CollectionSet collectionSet = new CollectionSetBuilder(collectionAgent).withTimestamp(new Date(0)).withNumericAttribute(nodeLevelResource, "ucd-sysstat", "CpuRawIdle", 99, AttributeType.GAUGE).withNumericAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifHCInOctets", 1001, AttributeType.COUNTER).withStringAttribute(interfaceLevelResource, "mib2-X-interfaces", "ifDescr", "LAN").withIdentifiedNumericAttribute(deferredGenericTypeResource, "net-snmp-disk", "ns-dsk1", 1024, AttributeType.GAUGE, "some-oid").withIdentifiedNumericAttribute(genericTypeResource, "net-snmp-disk", "ns-dskTotal", 1024, AttributeType.GAUGE, "some-oid").build();
    return Arrays.asList(new Object[][] { { collectionSet, "<collection-set status=\"SUCCEEDED\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + "   <agent type=\"0\" store-by-fs=\"false\" node-id=\"0\" sys-up-time=\"0\"/>\n" + "   <collection-resource>\n" + "      <node-level-resource node-id=\"1\"/>\n" + "      <numeric-attribute group=\"ucd-sysstat\" name=\"CpuRawIdle\" type=\"gauge\" value=\"99\"/>\n" + "   </collection-resource>\n" + "   <collection-resource>\n" + "      <interface-level-resource if-name=\"eth0\">\n" + "         <node-level-resource node-id=\"1\"/>\n" + "      </interface-level-resource>\n" + "      <numeric-attribute group=\"mib2-X-interfaces\" name=\"ifHCInOctets\" type=\"counter\" value=\"1001\"/>\n" + "      <string-attribute group=\"mib2-X-interfaces\" name=\"ifDescr\" type=\"string\" value=\"LAN\"/>\n" + "   </collection-resource>\n" + "   <collection-resource>\n" + "      <generic-type-resource name=\"Charles\" instance=\"id\">\n" + "         <node-level-resource node-id=\"1\"/>\n" + "      </generic-type-resource>\n" + "      <numeric-attribute group=\"net-snmp-disk\" name=\"ns-dsk1\" type=\"gauge\" identifier=\"some-oid\" value=\"1024\"/>\n" + "   </collection-resource>\n" + "   <collection-resource>\n" + "      <generic-type-resource name=\"Charles\" instance=\"idx\" timestamp=\"" + StringUtils.iso8601OffsetString(new Date(0), ZoneId.systemDefault(), ChronoUnit.SECONDS) + "\">\n" + "         <node-level-resource node-id=\"1\"/>\n" + "      </generic-type-resource>\n" + "      <numeric-attribute group=\"net-snmp-disk\" name=\"ns-dskTotal\" type=\"gauge\" identifier=\"some-oid\" value=\"1024\"/>\n" + "   </collection-resource>\n" + "</collection-set>" } });
}
Also used : DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) ResourceType(org.opennms.netmgt.collection.api.ResourceType) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Date(java.util.Date) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with GenericTypeResource

use of org.opennms.netmgt.collection.support.builder.GenericTypeResource in project opennms by OpenNMS.

the class GenericTypeResourceTest method getInstanceInResourcePath.

private String getInstanceInResourcePath(String instance) {
    // Mock the ResourceType
    ResourceType rt = mock(ResourceType.class, RETURNS_DEEP_STUBS);
    when(rt.getName()).thenReturn("type");
    when(rt.getStorageStrategy().getClazz()).thenReturn(IndexStorageStrategy.class.getCanonicalName());
    when(rt.getStorageStrategy().getParameters()).thenReturn(Collections.emptyList());
    when(rt.getPersistenceSelectorStrategy().getClazz()).thenReturn(PersistAllSelectorStrategy.class.getCanonicalName());
    when(rt.getPersistenceSelectorStrategy().getParameters()).thenReturn(Collections.emptyList());
    // Create the GenericTypeResource
    NodeLevelResource nlr = new NodeLevelResource(1);
    GenericTypeResource gtr = new GenericTypeResource(nlr, rt, instance);
    // Mock the CollectionResource
    CollectionResource resource = mock(CollectionResource.class);
    when(resource.getInstance()).thenReturn(gtr.getInstance());
    // Build the resource path, and extract the instance (the last element of the path)
    ResourcePath path = gtr.getPath(resource);
    String[] elements = path.elements();
    return elements[elements.length - 1];
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) ResourceType(org.opennms.netmgt.collection.api.ResourceType) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource)

Example 3 with GenericTypeResource

use of org.opennms.netmgt.collection.support.builder.GenericTypeResource in project opennms by OpenNMS.

the class WmiCollector method getWmiResource.

private Resource getWmiResource(CollectionAgent agent, String resourceType, NodeLevelResource nodeResource, String instance) {
    ResourceType rt = DataCollectionConfigFactory.getInstance().getConfiguredResourceTypes().get(resourceType);
    if (rt == null) {
        LOG.debug("getWmiResourceType: using default WMI resource type strategy - index / all");
        rt = new ResourceType();
        rt.setName(resourceType);
        rt.setStorageStrategy(new StorageStrategy());
        rt.getStorageStrategy().setClazz(IndexStorageStrategy.class.getName());
        rt.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy());
        rt.getPersistenceSelectorStrategy().setClazz(PersistAllSelectorStrategy.class.getName());
    }
    return new GenericTypeResource(nodeResource, rt, instance);
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 4 with GenericTypeResource

use of org.opennms.netmgt.collection.support.builder.GenericTypeResource in project opennms by OpenNMS.

the class TcaCollectionHandler method process.

/**
	 * Process.
	 * 
	 * <p>A sample TCA Data looks like the following:</p>
	 * <ul>
	 * <li>OID=.1.3.6.1.4.1.27091.3.1.6.1.1.172.19.37.60.1, Type=OctetString, Value=172.19.37.60 </li>
	 * <li>OID=.1.3.6.1.4.1.27091.3.1.6.1.2.172.19.37.60.1, Type=OctetString, Value=
	 * |25|1327451762,11,0,11,0,1|1327451763,11,0,11,0,1|1327451764,11,0,11,0,1|1327451765,11,0,11,0,1|1327451766,11,0,11,0,1|
	 * 1327451767,11,0,11,0,1|1327451768,11,0,11,0,1|1327451769,11,0,11,0,1|1327451770,11,0,11,0,1|1327451771,11,0,11,0,1|
	 * 1327451772,11,0,11,0,1|1327451773,11,0,11,0,1|1327451774,11,0,11,0,1|1327451775,11,0,11,0,1|1327451776,11,0,11,0,1|
	 * 1327451777,11,0,11,0,1|1327451778,11,0,11,0,1|1327451779,11,0,11,0,1|1327451780,11,0,11,0,1|1327451781,11,0,11,0,1|
	 * 1327451782,11,0,11,0,1|1327451783,11,0,11,0,1|1327451784,11,0,11,0,1|1327451785,11,0,11,0,1|1327451786,11,0,11,0,1|</li>
	 * </ul>
	 * 
	 * <ul>
	 * <li>timestamp (epoch)</li>
	 * <li>delay local-remote ~ current inbound-delay</li>
	 * <li>jitter local-remote ~ current inbound-jitter</li>
	 * <li>delay remote-local ~ current outbound-delay</li>
	 * <li>jitter remote-local ~ current outbound-jitter-</li>
	 * <li>timesync status (1 = good, time is synced, 0 = bad, out-of sync)</li>
	 * </ul>
	 *
	 * @param tracker the tracker
	 * @throws Exception the exception
	 */
private void process(TcaData tracker, CollectionSetBuilder builder) {
    LOG.debug("process: processing raw TCA data for {} peers.", tracker.size());
    final NodeLevelResource nodeResource = new NodeLevelResource(m_agent.getNodeId());
    long timestamp = 0;
    for (TcaDataEntry entry : tracker.getEntries()) {
        GenericTypeResource resource = new GenericTypeResource(nodeResource, m_resourceType, entry.getPeerAddress());
        CollectionResource collectionResource = CollectionSetBuilder.toCollectionResource(resource, m_agent);
        long lastTimestamp = getLastTimestamp(collectionResource);
        String[] rawData = entry.getRawData().split("\\|");
        int samples = Integer.parseInt(rawData[1]);
        SnmpObjId entryObjId = SnmpObjId.get(".1.3.6.1.4.1.27091.3.1.6.1.2", entry.getInstance().toString());
        String identifierPrefix = String.format("TCA_%s_", entryObjId);
        for (int i = 0; i < samples; i++) {
            LOG.debug("process: processing row {}: {}", i, rawData[2 + i]);
            String[] rawEntry = rawData[2 + i].split(",");
            timestamp = Long.parseLong(rawEntry[0]);
            if (timestamp > lastTimestamp) {
                resource = new GenericTypeResource(nodeResource, m_resourceType, entry.getPeerAddress());
                resource.setTimestamp(new Date(timestamp * 1000));
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, INBOUND_DELAY, Double.parseDouble(rawEntry[1]), AttributeType.GAUGE, identifierPrefix + INBOUND_DELAY);
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, INBOUND_JITTER, Double.parseDouble(rawEntry[2]), AttributeType.GAUGE, identifierPrefix + INBOUND_JITTER);
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, OUTBOUND_DELAY, Double.parseDouble(rawEntry[3]), AttributeType.GAUGE, identifierPrefix + OUTBOUND_DELAY);
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, OUTBOUND_JITTER, Double.parseDouble(rawEntry[4]), AttributeType.GAUGE, identifierPrefix + OUTBOUND_JITTER);
                builder.withIdentifiedNumericAttribute(resource, RESOURCE_TYPE_NAME, TIMESYNC_STATUS, Double.parseDouble(rawEntry[5]), AttributeType.GAUGE, identifierPrefix + TIMESYNC_STATUS);
            } else {
                LOG.debug("process: skipping row {} {} because it was already processed.", i, rawData[2 + i]);
            }
        }
        setLastTimestamp(collectionResource, timestamp);
    }
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Date(java.util.Date)

Example 5 with GenericTypeResource

use of org.opennms.netmgt.collection.support.builder.GenericTypeResource in project opennms by OpenNMS.

the class GenericTypeResourceDTO method toResource.

public GenericTypeResource toResource() {
    final ResourceType resourceType = ResourceTypeMapper.getInstance().getResourceTypeWithFallback(name, fallback);
    if (resourceType == null) {
        throw new IllegalArgumentException(String.format("No resource type found with name '%s'!", name));
    }
    final GenericTypeResource resource = new GenericTypeResource(parent.toResource(), resourceType, instance);
    resource.setTimestamp(timestamp);
    return resource;
}
Also used : GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) ResourceType(org.opennms.netmgt.collection.api.ResourceType)

Aggregations

GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)8 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)5 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)3 ResourceType (org.opennms.netmgt.collection.api.ResourceType)3 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)3 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)3 ResourcePath (org.opennms.netmgt.model.ResourcePath)3 Date (java.util.Date)2 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)2 CollectionException (org.opennms.netmgt.collection.api.CollectionException)2 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)2 PersistAllSelectorStrategy (org.opennms.netmgt.collection.support.PersistAllSelectorStrategy)2 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)2 InterfaceLevelResource (org.opennms.netmgt.collection.support.builder.InterfaceLevelResource)2 PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)2 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)2 Maps (com.google.common.collect.Maps)1 XMLDoc (com.mycila.xmltool.XMLDoc)1 XMLTag (com.mycila.xmltool.XMLTag)1 Arrays (java.util.Arrays)1