use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class SnmpTrapNotificationStrategy method sendV2Trap.
/**
* <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());
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class InstanceStrategy method getInstanceFromPhysAddr.
public static SnmpInstId getInstanceFromPhysAddr(String physAddr) {
String[] elm;
elm = physAddr.split(":");
if (elm.length != 6) {
return null;
}
final 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());
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method testGenericResource.
@Test
public void testGenericResource() throws Exception {
SnmpCollectionAgent agent = createCollectionAgent();
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
ResourceType rt = new ResourceType();
rt.setName("hrStorageIndex");
rt.setLabel("host-resources storage");
StorageStrategy strategy = new StorageStrategy();
strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
strategy.addParameter(new Parameter("sibling-column-name", "hrStorageLabel"));
strategy.addParameter(new Parameter("replace-all", "s/^-//"));
rt.setStorageStrategy(strategy);
PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
pstrategy.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
rt.setPersistenceSelectorStrategy(pstrategy);
GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, collection, rt);
SnmpCollectionResource resource = new GenericIndexResource(resourceType, resourceType.getName(), new SnmpInstId(100));
SnmpAttribute used = addAttributeToCollectionResource(resource, "hrStorageUsed", AttributeType.GAUGE, "hrStorageIndex", "5000");
SnmpAttribute label = addAttributeToCollectionResource(resource, "hrStorageLabel", AttributeType.STRING, "hrStorageIndex", "/opt");
Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
attributes.put(used.getName(), used);
attributes.put(label.getName(), label);
CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
Assert.assertEquals("opt", wrapper.getInstanceLabel());
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class TrapHandlerITCase method sendV2Trap.
public void sendV2Trap(String enterprise, int specific, LinkedHashMap<String, SnmpValue> varbinds) throws Exception {
SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
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(specific));
// 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));
}
for (Map.Entry<String, SnmpValue> entry : varbinds.entrySet()) {
pdu.addVarBind(SnmpObjId.get(entry.getKey()), entry.getValue());
}
pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class TrapHandlerITCase method sendV2Trap.
public void sendV2Trap(String enterprise, int specific) throws Exception {
SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
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(specific));
// 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.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
Aggregations