use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runFileSystemDataTest.
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);
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class InstanceStrategyTest method testPhysdAddrToAndFromInstance.
public void testPhysdAddrToAndFromInstance() {
SnmpInstId instanceId = new SnmpInstId(".0.0.0.0.0.0");
assertEquals("00:00:00:00:00:00", InstanceStrategy.getPhysAddrFromInstance(instanceId));
assertEquals(instanceId, InstanceStrategy.getInstanceFromPhysAddr("00:00:00:00:00:00"));
instanceId = new SnmpInstId(".11.22.33.44.255.66");
assertEquals("0B:16:21:2C:FF:42", InstanceStrategy.getPhysAddrFromInstance(instanceId));
assertEquals(instanceId, InstanceStrategy.getInstanceFromPhysAddr("0B:16:21:2C:FF:42"));
instanceId = new SnmpInstId(".11.22.33.44.55");
assertEquals(null, InstanceStrategy.getPhysAddrFromInstance(instanceId));
assertEquals(null, InstanceStrategy.getInstanceFromPhysAddr("0B:16:21:2C:37"));
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class TableStrategy method call.
@Override
public OnmsAccessPointCollection call() throws IOException {
OnmsAccessPointCollection apsUp = new OnmsAccessPointCollection();
InetAddress ipaddr = m_iface.getIpAddress();
// Retrieve this interface's SNMP peer object
SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr);
if (agentConfig == null) {
throw new IllegalStateException("SnmpAgentConfig object not available for interface " + ipaddr);
}
final String hostAddress = InetAddressUtils.str(ipaddr);
LOG.debug("poll: setting SNMP peer attribute for interface {}", hostAddress);
// Get configuration parameters
String oid = ParameterMap.getKeyedString(m_parameters, "oid", null);
if (oid == null) {
throw new IllegalStateException("oid parameter is not set.");
}
agentConfig.hashCode();
// Set timeout and retries on SNMP peer object
agentConfig.setTimeout(ParameterMap.getKeyedInteger(m_parameters, "timeout", agentConfig.getTimeout()));
agentConfig.setRetries(ParameterMap.getKeyedInteger(m_parameters, "retry", ParameterMap.getKeyedInteger(m_parameters, "retries", agentConfig.getRetries())));
agentConfig.setPort(ParameterMap.getKeyedInteger(m_parameters, "port", agentConfig.getPort()));
LOG.debug("TableStrategy.poll: SnmpAgentConfig address={}", agentConfig);
// Establish SNMP session with interface
try {
SnmpObjId snmpObjectId = SnmpObjId.get(oid);
Map<SnmpInstId, SnmpValue> map = SnmpUtils.getOidValues(agentConfig, "AccessPointMonitor::TableStrategy", snmpObjectId);
if (map.size() <= 0) {
throw new IOException("No entries found in table (possible timeout).");
}
for (Map.Entry<SnmpInstId, SnmpValue> entry : map.entrySet()) {
SnmpValue value = entry.getValue();
String physAddr = getPhysAddrFromValue(value);
LOG.debug("AP at value '{}' with MAC '{}' is considered to be ONLINE on controller '{}'", value.toHexString(), physAddr, m_iface.getIpAddress());
OnmsAccessPoint ap = m_accessPointDao.get(physAddr);
if (ap != null) {
if (ap.getPollingPackage().compareToIgnoreCase(getPackage().getName()) == 0) {
// Save the controller's IP address
ap.setControllerIpAddress(ipaddr);
apsUp.add(ap);
} else {
LOG.info("AP with MAC '{}' is in a different package.", physAddr);
}
} else {
LOG.info("No matching AP in database for value '{}'.", value.toHexString());
}
}
} catch (InterruptedException e) {
LOG.error("Interrupted while polling {}", hostAddress, e);
}
return apsUp;
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class TrapdIT method testSnmpV2cTrapSend.
@Test
public void testSnmpV2cTrapSend() throws Exception {
String localhost = "127.0.0.1";
InetAddress localAddr = InetAddressUtils.addr(localhost);
SnmpObjId enterpriseId = SnmpObjId.get(".1.3.6.1.4.1.5813");
SnmpObjId trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(1));
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));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
EventBuilder defaultTrapBuilder = new EventBuilder("uei.opennms.org/default/trap", "trapd");
defaultTrapBuilder.setInterface(localAddr);
defaultTrapBuilder.setSnmpVersion("v2c");
m_mockEventIpcManager.getEventAnticipator().anticipateEvent(defaultTrapBuilder.getEvent());
EventBuilder newSuspectBuilder = new EventBuilder(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI, "trapd");
newSuspectBuilder.setInterface(localAddr);
m_mockEventIpcManager.getEventAnticipator().anticipateEvent(newSuspectBuilder.getEvent());
pdu.send(localhost, m_trapdConfig.getSnmpTrapPort(), "public");
// Allow time for Trapd and Eventd to do their magic
Thread.sleep(5000);
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class RrdPersistOperationBuilderTest method testCommitWithDeclaredAttributeAndNullValue.
@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();
}
Aggregations