use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class Snmp4jTrapReceiverIT method sendTraps.
private void sendTraps(final Snmp4JStrategy strategy, final int v3Level) throws Exception {
final String hostAddress = str(getAgentAddress());
LOG.debug("Sending V2 Trap");
SnmpObjId enterpriseId = SnmpObjId.get(".0.0");
SnmpObjId trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(1));
SnmpTrapBuilder pdu = strategy.getV2TrapBuilder();
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
pdu.send(hostAddress, 9162, "public");
LOG.debug("Sending V3 Trap");
SnmpV3TrapBuilder pduv3 = strategy.getV3TrapBuilder();
pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
switch(v3Level) {
case SnmpConfiguration.NOAUTH_NOPRIV:
pduv3.send(hostAddress, 9162, SnmpConfiguration.NOAUTH_NOPRIV, "noAuthUser", null, null, null, null);
break;
case SnmpConfiguration.AUTH_PRIV:
pduv3.send(hostAddress, 9162, SnmpConfiguration.AUTH_PRIV, "opennmsUser", "0p3nNMSv3", SnmpConfiguration.DEFAULT_AUTH_PROTOCOL, "0p3nNMSv3", SnmpConfiguration.DEFAULT_PRIV_PROTOCOL);
break;
default:
}
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class SnmpMultiResponseDTOTest method getSnmpMultiResponse.
private static SnmpMultiResponseDTO getSnmpMultiResponse() {
final SnmpValueFactory snmpValueFactory = new Snmp4JValueFactory();
final SnmpResult result = new SnmpResult(SnmpObjId.get(".1.3.6.1.2"), new SnmpInstId(".1.3.6.1.2.1.4.34.1.3.1.2.3.4"), snmpValueFactory.getCounter64(BigInteger.TEN));
final SnmpResponseDTO responseDTO = new SnmpResponseDTO();
responseDTO.setCorrelationId("42");
responseDTO.getResults().add(result);
final SnmpMultiResponseDTO multiResponseDTO = new SnmpMultiResponseDTO();
multiResponseDTO.getResponses().add(responseDTO);
return multiResponseDTO;
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class InstanceStrategy 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 = getAgentConfig(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.");
}
String operator = ParameterMap.getKeyedString(m_parameters, "operator", null);
String operand = ParameterMap.getKeyedString(m_parameters, "operand", null);
String matchstr = ParameterMap.getKeyedString(m_parameters, "match", "true");
LOG.debug("InstanceStrategy.poll: SnmpAgentConfig address= {}", agentConfig);
// Establish SNMP session with interface
try {
SnmpObjId snmpObjectId = SnmpObjId.get(oid);
Map<SnmpInstId, SnmpValue> map = SnmpUtils.getOidValues(agentConfig, "AccessPointMonitor::InstanceStrategy", snmpObjectId);
if (map.size() <= 0) {
throw new IOException("No entries found in table (possible timeout).");
}
for (Map.Entry<SnmpInstId, SnmpValue> entry : map.entrySet()) {
boolean isUp = false;
SnmpInstId instance = entry.getKey();
SnmpValue value = entry.getValue();
// Check the value against the configured criteria
if (meetsCriteria(value, operator, operand)) {
if ("true".equals(matchstr)) {
isUp = true;
}
} else if ("false".equals(matchstr)) {
isUp = true;
}
// of online APs
if (isUp) {
String physAddr = getPhysAddrFromInstance(instance);
LOG.debug("AP at instance '{}' with MAC '{}' is considered to be ONLINE on controller '{}'", instance, 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 instance '{}'.", instance);
}
}
}
} catch (NumberFormatException e) {
LOG.error("Number operator used on a non-number ", e);
} catch (IllegalArgumentException e) {
LOG.error("Invalid SNMP Criteria ", e);
} 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 SnmpDetector method isServiceDetected.
@Override
public boolean isServiceDetected(InetAddress address, SnmpAgentConfig agentConfig) {
try {
configureAgentPTR(agentConfig);
configureAgentVersion(agentConfig);
final String expectedValue = getVbvalue();
if (this.m_isTable) {
LOG.debug(getServiceName() + ": table detect enabled");
final SnmpObjId snmpObjId = SnmpObjId.get(getOid());
final Map<SnmpInstId, SnmpValue> table = SnmpUtils.getOidValues(agentConfig, DEFAULT_SERVICE_NAME, snmpObjId);
final List<String> retrievedValues = table.values().stream().map(snmpValue -> m_hex ? snmpValue.toHexString() : snmpValue.toString()).collect(Collectors.toList());
return isServiceDetected(this.matchType, retrievedValues, expectedValue);
} else {
final String retrievedValue = getValue(agentConfig, getOid(), m_hex);
// we have to ensure that if expectedValue is defined, we use ANY, this is due to backwards compatibility
MatchType matchType = this.matchType;
if (matchType == null && expectedValue != null) {
matchType = MatchType.Any;
}
return isServiceDetected(matchType, Lists.newArrayList(retrievedValue), expectedValue);
}
} catch (Throwable t) {
throw new UndeclaredThrowableException(t);
}
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testBug3554_withMockFilterDao.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration-bug3554.xml
* - test-thresholds-bug3554.xml
*/
@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
// real value = (46000 - 10000)/300 = 120
runInterfaceResource(visitor, "127.0.0.1", "eth0", 10000000l, 1, 10000, 46000);
// 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);
}
Aggregations