public SnmpValue[] generateRowStatusValues() { SnmpValueFactory vf = SnmpUtils.getValueFactory(); SnmpValue[] values = { vf.getInt32(m_ciscoPingEntryStatus) }; return values; }
protected void putIfIndex(int ifIndex) { putValue(IFINDEX, SnmpUtils.getValueFactory().getInt32(ifIndex)); }
protected void putIfIndex(int ifIndex) { putValue(IFINDEX, SnmpUtils.getValueFactory().getInt32(ifIndex)); }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { byte[] contents; if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) { contents = value.getBytes(); } else if (EventConstants.XML_ENCODING_BASE64.equals(encoding)) { contents = Base64.decodeBase64(value.toCharArray()); } else if (EventConstants.XML_ENCODING_MAC_ADDRESS.equals(encoding)) { contents = InetAddressUtils.macAddressStringToBytes(value); } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpOctetString"); } trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getOctetString(contents)); } }
@Override public SnmpValue unmarshal(JaxbSnmpValue value) throws Exception { final SnmpValueFactory valueFactory = SnmpUtils.getValueFactory(); return valueFactory.getValue(value.getType(), value.getBytes()); } }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getNull()); } }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { if (EventConstants.XML_ENCODING_BASE64.equals(encoding)) { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getOpaque(Base64.decodeBase64(value.toCharArray()))); } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpOpaque"); } } }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getObjectId(SnmpObjId.get(value))); } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpObjectId"); } } }
/** * Constructs a new SnmpVarBind with the specified name and value. The * value will be encoded as an SnmpNull.The value and encoding * parameters are ignored. * @param name * The name (a.k.a. "id") of the variable binding to be * created * @param encoding * This parameter value is ignored. * @param value * This parameter value is ignored. * * @return The newly-created variable binding */ @Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getNull()); } }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) { try { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getCounter64(new BigInteger(value))); } catch (IllegalArgumentException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpCounter64"); } catch (NullPointerException e) { throw new SnmpTrapException("Value is null for SnmpCounter64"); } } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpCounter64"); } } }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) { try { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getInt32(Integer.parseInt(value))); } catch (NumberFormatException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpInt32"); } catch (NullPointerException e) { throw new SnmpTrapException("Value is null for SnmpInt32"); } } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpInt32"); } } }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) { final InetAddress addr = InetAddressUtils.addr(value); if (addr == null) { throw new SnmpTrapException("Value " + value + "is invalid, or host unknown for SnmpIPAddress"); } trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getIpAddress(addr)); } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpIPAddress"); } } }
public SnmpValue[] generateCreateValues() { SnmpValueFactory vf = SnmpUtils.getValueFactory(); SnmpValue[] values = { vf.getInt32(m_ciscoPingProtocol), vf.getOctetString(m_ciscoPingAddress.getAddress()), vf.getInt32(m_ciscoPingPacketCount), vf.getInt32(m_ciscoPingPacketSize), vf.getInt32(m_ciscoPingPacketTimeout), vf.getInt32(m_ciscoPingPacketDelay), vf.getOctetString(m_ciscoPingEntryOwner.getBytes()), vf.getInt32(m_ciscoPingEntryStatus), vf.getOctetString(m_ciscoPingVrfName.getBytes()) }; return values; }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) { try { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getTimeTicks(Long.parseLong(value))); } catch (NumberFormatException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpTimeTicks"); } catch (IllegalArgumentException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpTimeTicks"); } catch (NullPointerException e) { throw new SnmpTrapException("Value is null for SnmpTimeTicks"); } } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpTimeTicks"); } } }
@Override public void addVarBind(SnmpTrapBuilder trap, String name, String encoding, String value) throws SnmpTrapException { if (EventConstants.XML_ENCODING_TEXT.equals(encoding)) { try { trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getCounter32(Long.parseLong(value))); } catch (NumberFormatException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpCounter32"); } catch (IllegalArgumentException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpCounter32"); } catch (NullPointerException e) { throw new SnmpTrapException("Value is null for SnmpCounter32"); } } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpCounter32"); } } }
private static void addAttributeToCollectionResource(SnmpCollectionResource resource, ResourceType type, String attributeName, String attributeType, String attributeInstance, long value) { MibObject object = createMibObject(attributeType, attributeName, attributeInstance); SnmpAttributeType objectType = new NumericAttributeType(type, "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); SnmpValue snmpValue = attributeType.equals("counter") ? SnmpUtils.getValueFactory().getCounter32(value) : SnmpUtils.getValueFactory().getGauge32(value); resource.setAttributeValue(objectType, snmpValue); }
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)); } }
/** * <p>sendV1Trap</p> * * @throws java.lang.Exception if any. */ public void sendV1Trap() throws Exception { SnmpV1TrapBuilder pdu = SnmpUtils.getV1TrapBuilder(); pdu.setEnterprise(SnmpObjId.get(getEnterpriseId())); pdu.setGeneric(getGenericId()); pdu.setSpecific(getSpecificId()); pdu.setTimeStamp(0); InetAddress agentAddress = getHostInetAddress(); pdu.setAgentAddress(agentAddress); pdu.addVarBind(SnmpObjId.get(".1.3.6.1.4.1.5813.20.1"), SnmpUtils.getValueFactory().getOctetString(getVarbind().getBytes())); pdu.send(InetAddressUtils.str(agentAddress), getPort(), getCommunity()); }
private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, BigInteger value) { MibObject object = createMibObject(attributeType, attributeName, attributeInstance); SnmpAttributeType objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); SnmpValue snmpValue = SnmpUtils.getValueFactory().getCounter64(value); resource.setAttributeValue(objectType, snmpValue); return new SnmpAttribute(resource, objectType, snmpValue); }
private SnmpAttribute buildStringAttribute() { EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes(); m_easyMockUtils.replayAll(); SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(m_intf.getId(), m_ifDao, m_transMgr); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); SnmpCollectionResource 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); SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); return new SnmpAttribute(resource, attributeType, SnmpUtils.getValueFactory().getOctetString("foo".getBytes())); }