private static MibObject createMibObject(String type, String alias, String instance) { MibObject mibObject = new MibObject(); mibObject.setOid(".1.1.1.1"); mibObject.setAlias(alias); mibObject.setType(type); mibObject.setInstance(instance); mibObject.setMaxval(null); mibObject.setMinval(null); return mibObject; }
if (m_oid.equals(aMibObject.getOid())) { if (m_instance.equals(aMibObject.getInstance())) { if ((m_alias == null && aMibObject.getInstance() == null) || (m_alias != null && aMibObject != null && m_alias.equals(aMibObject.getAlias()))) { if ((m_type == null && aMibObject.getType() == null) || (m_type != null && aMibObject != null && m_type.equals(aMibObject.getType()))) { return true;
/** * <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); }
/** * <p>getCollectionTracker</p> * * @param instances a {@link org.opennms.netmgt.snmp.SnmpInstId} object. * @return a {@link org.opennms.netmgt.snmp.CollectionTracker} object. */ public CollectionTracker getCollectionTracker(SnmpInstId... instances) { if (INSTANCE_IFINDEX.equals(getInstance()) || getResourceType() != null) { return (CollectionTracker) new InstanceListTracker(SnmpObjId.get(getOid()), instances); } else { return (CollectionTracker) new InstanceListTracker(SnmpObjId.get(getOid()), getInstance()); } }
@Test public void testCommitWithDeclaredAttributeAndNullValue() throws Exception { 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("string"); mibObject.setInstance("0"); mibObject.setMaxval(null); mibObject.setMinval(null); SnmpCollectionSet collectionSet = new SnmpCollectionSet(agent, collection, m_locationAwareSnmpClient); SnmpAttributeType attributeType = new StringAttributeType(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.setAttributeValue(attributeType, null); builder.commit(); }
for (final MibObj mibObj : objectList) { final MibObject aMibObject = new MibObject(); aMibObject.setGroupName(groupName); aMibObject.setGroupIfType(groupIfType); aMibObject.setOid(mibObj.getOid()); aMibObject.setAlias(mibObj.getAlias()); aMibObject.setType(mibObj.getType()); aMibObject.setInstance(mibObj.getInstance()); aMibObject.setMaxval(mibObj.getMaxval()); aMibObject.setMinval(mibObj.getMinval()); aMibObject.setResourceType(resourceType);
private MibObject createMibObject(String alias, String oid, String instance, String type) { MibObject mibObj = new MibObject(); mibObj.setGroupName("test"); mibObj.setAlias(alias); mibObj.setOid(oid); mibObj.setType(type); mibObj.setInstance(instance); mibObj.setGroupName("ifIndex".equals(instance) ? "interface" : "node"); mibObj.setGroupIfType("ifIndex".equals(instance) ? AttributeGroupType.IF_TYPE_ALL : AttributeGroupType.IF_TYPE_IGNORE); return mibObj; } public MibObject createAttributeType(String alias, String oid, String instance, String type) {
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"); attributeType.storeResult(new SnmpCollectionSet(agent, snmpCollection, m_locationAwareSnmpClient), null, new SnmpResult(mibObject.getSnmpObjId(), new SnmpInstId(mibObject.getInstance()), snmpValue));
MibObject mibObject = new MibObject(); mibObject.setOid(".1.2.3.4.5.6.7.8.9.2.1"); mibObject.setInstance("1"); mibObject.setAlias("name"); mibObject.setType("string"); StringAttributeType attributeType = new StringAttributeType(resourceType, snmpCollection.getName(), mibObject, groupType); SnmpValue snmpValue = new Snmp4JValueFactory().getOctetString("agalue rules!".getBytes());
public MibObject defineAttributeType(String alias, String oid, String instance, String type) { MibObject mibObj = createAttributeType(alias, oid, instance, type); getAttrMap().put(mibObj.getAlias(), mibObj); getAttrMap().put(mibObj.getOid(), mibObj); return mibObj; } public void addInitialAttributeTypes() {
/** * <p>getOid</p> * * @return a {@link java.lang.String} object. */ public String getOid() { return m_mibObj.getOid(); }
/** * <p>getInstance</p> * * @return a {@link java.lang.String} object. */ public String getInstance() { return m_mibObj.getInstance(); }
/** * <p>getAlias</p> * * @return a {@link java.lang.String} object. */ public String getAlias() { return m_mibObj.getAlias(); }
@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(); }
/** * <p>getCollectionTracker</p> * * @return a {@link org.opennms.netmgt.snmp.CollectionTracker} object. */ @Override public CollectionTracker getCollectionTracker() { if (INSTANCE_IFINDEX.equals(getInstance()) || getResourceType() != null) { return (CollectionTracker) new ColumnTracker(SnmpObjId.get(getOid())); } else { return (CollectionTracker) new InstanceListTracker(SnmpObjId.get(getOid()), getInstance()); } }
/** * <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<>(); 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; }
@Test public void testCommitWithDeclaredAttributeAndValue() 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.setAttributeValue(attributeType, 6.022E23d); builder.commit(); }
private MibObject createMibObject(AttributeType type, String alias, String instance) { MibObject mibObject = new MibObject(); mibObject.setOid(".1.1.1.1"); mibObject.setAlias(alias); mibObject.setType(type.toString()); mibObject.setInstance(instance); mibObject.setMaxval(null); mibObject.setMinval(null); return mibObject; }
protected static void assertMibObjectPresent(SnmpAttribute attribute, List<MibObject> attrList) { for (Iterator<MibObject> it = attrList.iterator(); it.hasNext();) { MibObject mibObj = it.next(); if (mibObj.getOid().equals(((SnmpAttributeType)attribute.getAttributeType()).getOid())) return; } fail("Unable to find attribue "+attribute+" in attribute list"); }