use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class DiskUsageDetector method isServiceDetected.
/**
* {@inheritDoc}
*
* Returns true if the protocol defined by this plugin is supported. If the
* protocol is not supported then a false value is returned to the caller.
* The qualifier map passed to the method is used by the plugin to return
* additional information by key-name. These key-value pairs can be added to
* service events if needed.
*/
@Override
public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfig agentConfig) {
int matchType = MATCH_TYPE_EXACT;
try {
if (getPort() > 0) {
agentConfig.setPort(getPort());
}
if (getTimeout() > 0) {
agentConfig.setTimeout(getTimeout());
}
if (getRetries() > -1) {
agentConfig.setRetries(getRetries());
}
if (getForceVersion() != null) {
String version = getForceVersion();
// @see http://issues.opennms.org/browse/NMS-7518
if ("v1".equalsIgnoreCase(version) || "snmpv1".equalsIgnoreCase(version)) {
agentConfig.setVersion(SnmpAgentConfig.VERSION1);
} else if ("v2".equalsIgnoreCase(version) || "v2c".equalsIgnoreCase(version) || "snmpv2".equalsIgnoreCase(version) || "snmpv2c".equalsIgnoreCase(version)) {
agentConfig.setVersion(SnmpAgentConfig.VERSION2C);
} else if ("v3".equalsIgnoreCase(version) || "snmpv3".equalsIgnoreCase(version)) {
agentConfig.setVersion(SnmpAgentConfig.VERSION3);
}
}
//
if (!"".equals(getMatchType())) {
String matchTypeStr = getMatchType();
if (matchTypeStr.equalsIgnoreCase("exact")) {
matchType = MATCH_TYPE_EXACT;
} else if (matchTypeStr.equalsIgnoreCase("startswith")) {
matchType = MATCH_TYPE_STARTSWITH;
} else if (matchTypeStr.equalsIgnoreCase("endswith")) {
matchType = MATCH_TYPE_ENDSWITH;
} else if (matchTypeStr.equalsIgnoreCase("regex")) {
matchType = MATCH_TYPE_REGEX;
} else {
throw new RuntimeException("Unknown value '" + matchTypeStr + "' for parameter 'match-type'");
}
}
SnmpObjId hrStorageDescrSnmpObject = SnmpObjId.get(getHrStorageDescr());
Map<SnmpInstId, SnmpValue> descrResults = SnmpUtils.getOidValues(agentConfig, "DiskUsagePoller", hrStorageDescrSnmpObject);
if (descrResults.size() == 0) {
return false;
}
for (Map.Entry<SnmpInstId, SnmpValue> e : descrResults.entrySet()) {
LOG.debug("capsd: SNMPwalk succeeded, addr={} oid={} instance={} value={}", InetAddressUtils.str(agentConfig.getAddress()), hrStorageDescrSnmpObject, e.getKey(), e.getValue());
if (isMatch(e.getValue().toString(), getDisk(), matchType)) {
LOG.debug("Found disk '{}' (matching hrStorageDescr was '{}')", getDisk(), e.getValue());
return true;
}
}
return false;
} catch (Throwable t) {
throw new UndeclaredThrowableException(t);
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class IpAddressTableEntry method getIpAddressNetMask.
/**
* <p>getIpAdEntNetMask</p>
*
* @return a {@link java.net.InetAddress} object.
*/
public InetAddress getIpAddressNetMask() {
final SnmpValue value = getValue(IP_ADDR_ENT_NETMASK);
// LOG.debug("getIpAddressNetMask: value = {}", value.toDisplayString());
final SnmpObjId netmaskRef = value.toSnmpObjId().getInstance(IPAddressTableTracker.IP_ADDRESS_PREFIX_ORIGIN_INDEX);
if (netmaskRef == null) {
LOG.warn("Unable to get netmask reference from instance.");
return null;
}
final int[] rawIds = netmaskRef.getIds();
final int addressType = rawIds[1];
final int addressLength = rawIds[2];
final InetAddress address = getInetAddress(rawIds, 3, addressLength);
final int mask = rawIds[rawIds.length - 1];
if (addressType == IPAddressTableTracker.TYPE_IPV4) {
return InetAddressUtils.convertCidrToInetAddressV4(mask);
} else if (addressType == IPAddressTableTracker.TYPE_IPV6) {
return InetAddressUtils.convertCidrToInetAddressV6(mask);
} else if (addressType == IPAddressTableTracker.TYPE_IPV6Z) {
LOG.debug("Got an IPv6z address, returning {}", address);
} else {
LOG.warn("Unsure how to handle IP address type ({})", addressType);
}
return address;
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class MockSnmpStrategy method getNext.
@Override
public SnmpValue[] getNext(final SnmpAgentConfig agentConfig, final SnmpObjId[] oids) {
final PropertyOidContainer oidContainer = getOidContainer(agentConfig);
if (oidContainer == null)
return null;
final List<SnmpValue> values = new ArrayList<>();
for (final SnmpObjId oid : oids) {
values.add(oidContainer.findNextValueForOid(oid));
}
return values.toArray(EMPTY_SNMP_VALUE_ARRAY);
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class MockSnmpStrategy method get.
@Override
public SnmpValue[] get(final SnmpAgentConfig agentConfig, final SnmpObjId[] oids) {
final PropertyOidContainer container = getOidContainer(agentConfig);
if (container == null)
return new SnmpValue[oids.length];
final List<SnmpValue> values = new ArrayList<>();
for (final SnmpObjId oid : oids) {
values.add(container.findValueForOid(oid));
}
return values.toArray(EMPTY_SNMP_VALUE_ARRAY);
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class Snmp4JStrategy method buildPdu.
protected PDU buildPdu(Snmp4JAgentConfig agentConfig, int pduType, SnmpObjId[] oids, SnmpValue[] values) {
PDU pdu = agentConfig.createPdu(pduType);
if (values == null) {
for (SnmpObjId oid : oids) {
pdu.add(new VariableBinding(new OID(oid.toString())));
}
} else {
// TODO should this throw an exception? This situation is fairly bogus and probably signifies a coding error.
if (oids.length != values.length) {
Exception e = new SnmpException("PDU values do not match OIDs");
LOG.error("PDU to prepare has object values but not the same number as there are OIDs. There are {} OIDs and {} object values.", oids.length, values.length, e);
return null;
}
for (int i = 0; i < oids.length; i++) {
pdu.add(new VariableBinding(new OID(oids[i].toString()), new Snmp4JValue(values[i].getType(), values[i].getBytes()).getVariable()));
}
}
// TODO should this throw an exception? This situation is fairly bogus.
if (pdu.getVariableBindings().size() != oids.length) {
Exception e = new SnmpException("PDU bindings do not match OIDs");
LOG.error("Prepared PDU does not have as many variable bindings as there are OIDs. There are {} OIDs and {} variable bindings.", oids.length, pdu.getVariableBindings(), e);
return null;
}
return pdu;
}
Aggregations