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().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"); } } }
@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"); } } }
public SnmpValue[] generateRowStatusValues() { SnmpValueFactory vf = SnmpUtils.getValueFactory(); SnmpValue[] values = { vf.getInt32(m_ciscoPingEntryStatus) }; return values; }
SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.6.9.0"), SnmpUtils.getValueFactory().getInt32(456)); SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.2.2.1.10.6"), SnmpUtils.getValueFactory().getCounter32(7654321));
@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)); } }
private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, String value) { MibObject object = createMibObject(attributeType, attributeName, attributeInstance); SnmpAttributeType objectType = null; SnmpValue snmpValue = null; if (AttributeType.STRING.equals(attributeType)) { objectType = new SnmpAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)) { @Override public AttributeType getType() { return AttributeType.STRING; } @Override public void storeAttribute(CollectionAttribute attribute, Persister persister) { persister.persistStringAttribute(attribute); } }; snmpValue = SnmpUtils.getValueFactory().getOctetString(value.getBytes()); } else { objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); long v = Long.parseLong(value); snmpValue = AttributeType.COUNTER.equals(attributeType) ? SnmpUtils.getValueFactory().getCounter32(v) : SnmpUtils.getValueFactory().getGauge32(v); } resource.setAttributeValue(objectType, snmpValue); return new SnmpAttribute(resource, objectType, snmpValue); }
/** * <p>sendV2Trap</p> * * @throws java.lang.Exception if any. */ public void sendV2Trap() throws Exception { SnmpObjId enterpriseId = SnmpObjId.get(getEnterpriseId()); boolean isGeneric = false; SnmpObjId trapOID; if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) { isGeneric = true; trapOID = enterpriseId; } else { trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(getSpecificId())); // XXX or should it be this // trap OID = enterprise + ".0." + specific; } SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder(); pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0)); pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID)); if (isGeneric) { pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId)); } pdu.addVarBind(SnmpObjId.get(".1.3.6.1.4.1.5813.20.1"), SnmpUtils.getValueFactory().getOctetString(getVarbind().getBytes())); pdu.send(InetAddressUtils.str(getHostInetAddress()), getPort(), getCommunity()); }
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)); } }
@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().getGauge32(Long.parseLong(value))); } catch (NumberFormatException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpGauge32"); } catch (IllegalArgumentException e) { throw new SnmpTrapException("Value " + value + "is invalid for SnmpGauge32"); } catch (NullPointerException e) { throw new SnmpTrapException("Value is null for SnmpGauge32"); } } else { throw new SnmpTrapException("Encoding " + encoding + "is invalid for SnmpGauge32"); } } }
@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"); } } }
@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"); } } }
protected void putIfIndex(int ifIndex) { putValue(IFINDEX, SnmpUtils.getValueFactory().getInt32(ifIndex)); }
SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.6.9.0"), SnmpUtils.getValueFactory().getInt32(456)); SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.2.2.1.10.6"), SnmpUtils.getValueFactory().getCounter32(7654321)); SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.6.9.0"), SnmpUtils.getValueFactory().getInt32(456)); SnmpUtils.set(m_agentConfig, SnmpObjId.get(".1.3.6.1.2.1.2.2.1.10.6"), SnmpUtils.getValueFactory().getCounter32(1234567));
@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; }
trap.addVarBind(SnmpObjId.get(name), SnmpUtils.getValueFactory().getGauge32(Long.parseLong(value)));
/** * 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()); } }