Search in sources :

Example 16 with AttributeGroupType

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

the class SnmpAttributeTest method testPersisting.

@Ignore
@SuppressWarnings("unchecked")
private void testPersisting(String matchValue, SnmpValue snmpValue) throws Exception {
    OnmsNode node = new OnmsNode();
    node.setId(3);
    OnmsIpInterface ipInterface = new OnmsIpInterface();
    ipInterface.setId(1);
    ipInterface.setNode(node);
    ipInterface.setIpAddress(InetAddressUtils.addr("192.168.1.1"));
    // It used to be 3, but I think it is more correct to use getStoreDir from DefaultCollectionAgentService on DefaultCollectionAgent (NMS-7516)
    expect(m_ipInterfaceDao.load(1)).andReturn(ipInterface).times(7);
    expect(m_rrdStrategy.getDefaultFileExtension()).andReturn(".myLittleEasyMockedStrategyAndMe").anyTimes();
    expect(m_rrdStrategy.createDefinition(isA(String.class), isA(String.class), isA(String.class), anyInt(), isAList(RrdDataSource.class), isAList(String.class))).andReturn(new Object());
    m_rrdStrategy.createFile(isA(Object.class));
    expect(m_rrdStrategy.openFile(isA(String.class))).andReturn(new Object());
    m_rrdStrategy.updateFile(isA(Object.class), isA(String.class), matches(".*:" + matchValue));
    m_rrdStrategy.closeFile(isA(Object.class));
    m_mocks.replayAll();
    SnmpCollectionAgent agent = DefaultCollectionAgent.create(ipInterface.getId(), m_ipInterfaceDao, new MockPlatformTransactionManager());
    OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), new MockDataCollectionConfig(), m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, snmpCollection);
    NodeInfo nodeInfo = resourceType.getNodeInfo();
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.3.6.1.4.1.12238.55.9997.4.1.2.9.116.101.109.112.95.117.108.107.111");
    mibObject.setInstance("1");
    mibObject.setAlias("temp_ulko");
    mibObject.setType("gauge");
    NumericAttributeType attributeType = new NumericAttributeType(resourceType, snmpCollection.getName(), mibObject, new AttributeGroupType("foo", AttributeGroupType.IF_TYPE_IGNORE));
    attributeType.storeResult(new SnmpCollectionSet(agent, snmpCollection, m_locationAwareSnmpClient), null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), snmpValue));
    RrdRepository repository = createRrdRepository();
    repository.setRraList(Collections.singletonList("RRA:AVERAGE:0.5:1:2016"));
    RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
    persisterFactory.setRrdStrategy(m_rrdStrategy);
    persisterFactory.setResourceStorageDao(m_resourceStorageDao);
    CollectionSetVisitor persister = persisterFactory.createPersister(new ServiceParameters(Collections.emptyMap()), repository);
    final AtomicInteger count = new AtomicInteger(0);
    nodeInfo.visit(new CollectionSetVisitorWrapper(persister) {

        @Override
        public void visitAttribute(CollectionAttribute attribute) {
            super.visitAttribute(attribute);
            count.incrementAndGet();
        }
    });
    assertEquals(1, count.get());
}
Also used : HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager) CollectionSetVisitorWrapper(org.opennms.netmgt.collection.support.CollectionSetVisitorWrapper) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) OnmsNode(org.opennms.netmgt.model.OnmsNode) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) MibObject(org.opennms.netmgt.config.datacollection.MibObject) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) MibObject(org.opennms.netmgt.config.datacollection.MibObject) Ignore(org.junit.Ignore)

Example 17 with AttributeGroupType

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

the class RrdPersistOperationBuilderTest method testCommitWithDeclaredAttribute.

@Test
public void testCommitWithDeclaredAttribute() throws Exception {
    File nodeDir = m_fileAnticipator.expecting(getSnmpRrdDirectory(), m_node.getId().toString());
    m_fileAnticipator.expecting(nodeDir, "rrdName" + m_rrdStrategy.getDefaultFileExtension());
    m_fileAnticipator.expecting(nodeDir, "rrdName" + ".meta");
    RrdRepository repository = createRrdRepository();
    SnmpCollectionAgent agent = getCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    NodeResourceType resourceType = new NodeResourceType(agent, collection);
    CollectionResource resource = new NodeInfo(resourceType, agent);
    MibObject mibObject = new MibObject();
    mibObject.setOid(".1.1.1.1");
    mibObject.setAlias("mibObjectAlias");
    mibObject.setType("counter");
    mibObject.setInstance("0");
    mibObject.setMaxval(null);
    mibObject.setMinval(null);
    SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient);
    SnmpAttributeType attributeType = new NumericAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
    attributeType.storeResult(collectionSet, null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), SnmpUtils.getValueFactory().getOctetString("hello".getBytes())));
    RrdPersistOperationBuilder builder = new RrdPersistOperationBuilder(m_rrdStrategy, repository, resource, "rrdName", false);
    builder.declareAttribute(attributeType);
    builder.commit();
}
Also used : CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) RrdPersistOperationBuilder(org.opennms.netmgt.collection.persistence.rrd.RrdPersistOperationBuilder) HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) MibObject(org.opennms.netmgt.config.datacollection.MibObject) File(java.io.File) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Example 18 with AttributeGroupType

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

the class IndexSplitPropertyExtender method getTargetAttribute.

/* (non-Javadoc)
     * @see org.opennms.netmgt.collectd.SnmpPropertyExtender#getTargetAttribute(java.util.List, org.opennms.netmgt.collectd.SnmpCollectionResource, org.opennms.netmgt.config.datacollection.MibObjProperty)
     */
@Override
public SnmpAttribute getTargetAttribute(List<CollectionAttribute> sourceAttributes, SnmpCollectionResource targetResource, MibObjProperty property) {
    final String indexPattern = property.getParameterValue(INDEX_PATTERN);
    if (StringUtils.isBlank(indexPattern)) {
        LOG.warn("Cannot execute the Index Split property extender because: missing parameter {}", INDEX_PATTERN);
        return null;
    }
    Pattern p = Pattern.compile(indexPattern);
    Matcher m = p.matcher(targetResource.getInstance());
    if (m.find()) {
        final String index = m.group(1);
        AttributeGroupType groupType = targetResource.getGroupType(property.getGroupName());
        if (groupType != null) {
            MibPropertyAttributeType type = new MibPropertyAttributeType(targetResource.getResourceType(), property, groupType);
            SnmpValue value = SnmpUtils.getValueFactory().getOctetString(index.getBytes());
            return new SnmpAttribute(targetResource, type, value);
        }
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Matcher(java.util.regex.Matcher) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType)

Example 19 with AttributeGroupType

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

the class OnmsSnmpCollection method loadAttributeTypes.

/**
     * <p>loadAttributeTypes</p>
     *
     * @param agent a {@link org.opennms.netmgt.collection.api.CollectionAgent} object.
     * @param ifType a int.
     * @return a {@link java.util.List} object.
     */
public List<SnmpAttributeType> loadAttributeTypes(SnmpCollectionAgent agent, int ifType) {
    String sysObjectId = agent.getSysObjectId();
    String hostAddress = agent.getHostAddress();
    List<MibObject> oidList = getDataCollectionConfigDao().getMibObjectList(getName(), sysObjectId, hostAddress, ifType);
    Map<String, AttributeGroupType> groupTypes = new HashMap<String, AttributeGroupType>();
    List<SnmpAttributeType> typeList = new LinkedList<SnmpAttributeType>();
    for (MibObject mibObject : oidList) {
        String instanceName = mibObject.getInstance();
        AttributeGroupType groupType = findGroup(groupTypes, mibObject);
        SnmpAttributeType attrType = SnmpAttributeType.create(getResourceType(agent, instanceName), getName(), mibObject, groupType);
        groupType.addAttributeType(attrType);
        typeList.add(attrType);
    }
    LOG.debug("getAttributeTypes({}, {}): {}", agent, ifType, typeList);
    return typeList;
}
Also used : HashMap(java.util.HashMap) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) MibObject(org.opennms.netmgt.config.datacollection.MibObject) LinkedList(java.util.LinkedList)

Example 20 with AttributeGroupType

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

the class OnmsSnmpCollection method loadAliasAttributeTypes.

/**
     * <p>loadAliasAttributeTypes</p>
     *
     * @param agent a {@link org.opennms.netmgt.collection.api.CollectionAgent} object.
     * @return a {@link java.util.List} object.
     */
public List<SnmpAttributeType> loadAliasAttributeTypes(SnmpCollectionAgent agent) {
    IfAliasResourceType resType = getIfAliasResourceType(agent);
    MibObject ifAliasMibObject = new MibObject();
    ifAliasMibObject.setOid(".1.3.6.1.2.1.31.1.1.1.18");
    ifAliasMibObject.setAlias("ifAlias");
    ifAliasMibObject.setType("string");
    ifAliasMibObject.setInstance("ifIndex");
    ifAliasMibObject.setGroupName("aliasedResource");
    ifAliasMibObject.setGroupIfType(AttributeGroupType.IF_TYPE_ALL);
    AttributeGroupType groupType = new AttributeGroupType(ifAliasMibObject.getGroupName(), ifAliasMibObject.getGroupIfType());
    SnmpAttributeType type = SnmpAttributeType.create(resType, resType.getCollectionName(), ifAliasMibObject, groupType);
    return Collections.singletonList(type);
}
Also used : AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) MibObject(org.opennms.netmgt.config.datacollection.MibObject)

Aggregations

AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)21 MibObject (org.opennms.netmgt.config.datacollection.MibObject)16 SnmpAttributeType (org.opennms.netmgt.collectd.SnmpAttributeType)9 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)8 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)8 Test (org.junit.Test)7 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)7 HashMap (java.util.HashMap)6 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)6 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)6 NodeInfo (org.opennms.netmgt.collectd.NodeInfo)5 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)5 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)5 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)5 Date (java.util.Date)4 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)4 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)4 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)4 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)4 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)3