@Override public SnmpInstId unmarshal(String instance) throws Exception { return new SnmpInstId(instance); } }
public static SnmpInstId[] convertToSnmpInstIds(String instances) { StringTokenizer tokenizer = new StringTokenizer(instances, ","); SnmpInstId[] insts = new SnmpInstId[tokenizer.countTokens()]; int index = 0; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); SnmpInstId inst = new SnmpInstId(token); insts[index] = inst; index++; } return insts; }
public static SnmpInstId[] convertToSnmpInstIds(String instances) { StringTokenizer tokenizer = new StringTokenizer(instances, ","); SnmpInstId[] insts = new SnmpInstId[tokenizer.countTokens()]; int index = 0; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); SnmpInstId inst = new SnmpInstId(token); insts[index] = inst; index++; } return insts; }
public static SnmpInstId getInstanceFromPhysAddr(String physAddr) { String[] elm; elm = physAddr.split(":"); if (elm.length != 6) { return null; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < 6; i++) { sb.append("."); sb.append(Integer.parseInt(elm[i], 16)); } return new SnmpInstId(sb.toString()); }
/** * <p>getEntry</p> * * @param inst a int. * @return a T object. */ public T getEntry(int inst) { return getEntry(new SnmpInstId(inst)); }
/** * <p>getEntry</p> * * @param inst a int. * @return a T object. */ public T getEntry(int inst) { return getEntry(new SnmpInstId(inst)); }
public static SnmpInstId getInstanceForAddress(final InetAddress address) { final int type; if (address instanceof Inet4Address) { type = INSTANCE_TYPE_IPV4; } else if (address instanceof Inet6Address) { type = INSTANCE_TYPE_IPV6; } else { return null; } return new SnmpInstId(type + "." + address.getAddress().length + "." + InetAddressUtils.toOid(address)); }
public SingleInstanceTracker(String baseOid, String instId) { this(SnmpObjId.get(baseOid), new SnmpInstId(instId)); }
public static SnmpInstId getInstanceForAddress(final InetAddress address) { final int type; if (address instanceof Inet4Address) { type = INSTANCE_TYPE_IPV4; } else if (address instanceof Inet6Address) { type = INSTANCE_TYPE_IPV6; } else { return null; } return new SnmpInstId(type + "." + address.getAddress().length + "." + InetAddressUtils.toOid(address)); }
public SingleInstanceTracker(String baseOid, String instId) { this(SnmpObjId.get(baseOid), new SnmpInstId(instId)); }
/** {@inheritDoc} */ @Override public SnmpInstId[] getCollectionInstances() { List<SnmpInstId> instances = new ArrayList<>(); for (IfInfo ifInfo : m_ifMap.values()) { if (ifInfo.isCollectionEnabled()) { instances.add(new SnmpInstId(ifInfo.getIndex())); } } return instances.toArray(new SnmpInstId[instances.size()]); }
/** * <p>getEntry</p> * * @param address a {@link java.net.InetAddress} object. * @return a {@link org.opennms.netmgt.provision.service.snmp.IpAddrTableEntry} object. */ public IpAddrTableEntry getEntry(InetAddress address) { return getEntry(new SnmpInstId(InetAddressUtils.str(address))); }
/** * <p>getEntry</p> * * @param address a {@link java.net.InetAddress} object. * @return a {@link org.opennms.netmgt.provision.service.snmp.IpAddrTableEntry} object. */ public IpAddrTableEntry getEntry(InetAddress address) { return getEntry(new SnmpInstId(InetAddressUtils.str(address))); }
public SnmpInstId getInstance(SnmpObjId base) { if (!base.isPrefixOf(this)) return null; int[] instanceIds = new int[length() - base.length()]; System.arraycopy(m_ids, base.length(), instanceIds, 0, instanceIds.length); return new SnmpInstId(instanceIds); }
public SnmpInstId getInstance(SnmpObjId base) { if (!base.isPrefixOf(this)) return null; int[] instanceIds = new int[length() - base.length()]; System.arraycopy(m_ids, base.length(), instanceIds, 0, instanceIds.length); return new SnmpInstId(instanceIds); }
@Test public void testBug3554_withMockFilterDao() throws Exception { initFactories("/threshd-configuration-bug3554.xml","/test-thresholds-bug3554.xml"); // Visitor with Mock FavoriteFilterDao ThresholdingVisitor visitor = createVisitor(); visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime())); // Do nothing, just to check visitor runInterfaceResource(visitor, "127.0.0.1", "eth0", 10000000l, 1, 10000, 46000); // real value = (46000 - 10000)/300 = 120 // Do nothing, just to check visitor runGaugeDataTest(visitor, 12000); // Do nothing, just to check visitor SnmpCollectionAgent agent = createCollectionAgent(); GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "ciscoEnvMonTemperatureStatusIndex"); SnmpCollectionResource resource = new GenericIndexResource(resourceType, "ciscoEnvMonTemperatureStatusIndex", new SnmpInstId(45)); resource.visit(visitor); EasyMock.verify(agent); }
private void runFileSystemDataTest(ThresholdingVisitor visitor, int resourceId, String fs, long value, long max) throws Exception { SnmpCollectionAgent agent = createCollectionAgent(); // Creating Generic ResourceType GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "hrStorageIndex"); // 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); // Creating Resource SnmpInstId inst = new SnmpInstId(resourceId); SnmpCollectionResource resource = new GenericIndexResource(resourceType, "hrStorageIndex", inst); addAttributeToCollectionResource(resource, resourceType, "hrStorageUsed", "gauge", "hrStorageIndex", value); addAttributeToCollectionResource(resource, resourceType, "hrStorageSize", "gauge", "hrStorageIndex", max); addAttributeToCollectionResource(resource, resourceType, "hrStorageAllocUnits", "gauge", "hrStorageIndex", 1); // Run Visitor resource.visit(visitor); EasyMock.verify(agent); }
public void testStoreResultWithValueThenEndOfMibView() { String baseOid = ".1.3.6.1.2.1.31.1.1.1.18"; String ifAliasName = "ifAlias"; String ifAliasValue = "Foo!"; SnmpStore store = new SnmpStore(new NamedSnmpVar[] { new NamedSnmpVar(NamedSnmpVar.SNMPOCTETSTRING, ifAliasName, baseOid, 18) }); SnmpObjId base = SnmpObjId.get(baseOid); SnmpInstId inst = new SnmpInstId("1"); store.storeResult(new SnmpResult(base, inst, SnmpUtils.getValueFactory().getOctetString(ifAliasValue.getBytes()))); store.storeResult(new SnmpResult(base, inst, SnmpUtils.getValueFactory().getValue(SnmpValue.SNMP_END_OF_MIB, null))); assertEquals("ifAlias value", ifAliasValue, store.getDisplayString(ifAliasName)); } }
@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(); }
@Test public void testBug3227() throws Exception { initFactories("/threshd-configuration.xml","/test-thresholds-bug3227.xml"); ThresholdingVisitor visitor = createVisitor(); SnmpCollectionAgent agent = createCollectionAgent(); GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "frCircuitIfIndex"); // Creating Resource SnmpInstId inst = new SnmpInstId(100); SnmpCollectionResource resource = new GenericIndexResource(resourceType, "frCircuitIfIndex", inst); addAttributeToCollectionResource(resource, resourceType, "frReceivedOctets", "counter", "frCircuitIfIndex", 1000); addAttributeToCollectionResource(resource, resourceType, "frSentOctets", "counter", "frCircuitIfIndex", 1000); /* * Run Visitor * I must receive 2 special info events because getEntityMap should be called 2 times. * One for each attribute and one for each resource. * Original code will throw a NullPointerException after call getEntityMap. * Original code expects WARNs, but this message is now an INFO. */ resource.visit(visitor); }