use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class SnmpMonitorStrategyTest method testMeetsCriteriaWithSnmpNull.
@Test
public void testMeetsCriteriaWithSnmpNull() {
SnmpValue result = nullValue();
testSyntaxEquals(result, "", "1");
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class PercDetector 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) {
try {
configureAgentPTR(agentConfig);
configureAgentVersion(agentConfig);
SnmpObjId snmpObjectId = SnmpObjId.get(LOGICAL_BASE_OID + '.' + m_arrayNumber);
SnmpValue value = SnmpUtils.get(agentConfig, snmpObjectId);
if (value.toInt() != 2) {
LOG.debug("PercMonitor.poll: Bad Disk Found. Log vol({}) degraded", m_arrayNumber);
return false;
}
} catch (Throwable t) {
throw new UndeclaredThrowableException(t);
}
return true;
}
use of org.opennms.netmgt.snmp.SnmpValue 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.SnmpValue in project opennms by OpenNMS.
the class OmsaStorageDetector 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) {
try {
configureAgentPTR(agentConfig);
configureAgentVersion(agentConfig);
SnmpObjId virtualDiskRollUpStatusSnmpObject = SnmpObjId.get(virtualDiskRollUpStatus + '.' + m_virtualDiskNumber);
SnmpValue virtualDiskRollUpStatus = SnmpUtils.get(agentConfig, virtualDiskRollUpStatusSnmpObject);
if (virtualDiskRollUpStatus == null || virtualDiskRollUpStatus.isNull()) {
LOG.debug("SNMP poll failed: no results, addr={} oid={}", agentConfig.getAddress(), virtualDiskRollUpStatusSnmpObject);
return false;
}
if (virtualDiskRollUpStatus.toInt() != 3) {
// 3 means Online
LOG.debug("OMSAStorageMonitor.poll: Bad Disk Found. Log vol({}) degraded", m_virtualDiskNumber);
return false;
}
} catch (Throwable t) {
throw new UndeclaredThrowableException(t);
}
return true;
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runCounterWrapTest.
/*
* Parameter expectedValue should be around 200:
* Initial counter value is 20000 below limit.
* Next value is 40000, so the difference will be 60000.
* Counters are treated as rates so 60000/300 is 200.
*/
private void runCounterWrapTest(double bits, double expectedValue) throws Exception {
Integer ifIndex = 1;
Long ifSpeed = 10000000l;
String ifName = "wlan0";
initFactories("/threshd-configuration.xml", "/test-thresholds-bug3194.xml");
addHighThresholdEvent(1, 100, 90, expectedValue, ifName, "1", "ifOutOctets", ifName, ifIndex.toString());
ThresholdingVisitor visitor = createVisitor();
// Creating Interface Resource Type
SnmpIfData ifData = createSnmpIfData("127.0.0.1", ifName, ifSpeed, ifIndex, true);
SnmpCollectionAgent agent = createCollectionAgent();
IfResourceType resourceType = createInterfaceResourceType(agent);
// Creating Data Source
MibObject object = createMibObject("counter", "ifOutOctets", "ifIndex");
SnmpAttributeType objectType = new NumericAttributeType(resourceType, "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
long timestamp = new Date().getTime();
// Step 1 - Initialize Counter
visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp));
BigDecimal n = new BigDecimal(Math.pow(2, bits) - 20000);
SnmpValue snmpValue1 = SnmpUtils.getValueFactory().getCounter64(n.toBigInteger());
SnmpCollectionResource resource1 = new IfInfo(resourceType, agent, ifData);
resource1.setAttributeValue(objectType, snmpValue1);
resource1.visit(visitor);
// Step 2 - Wrap Counter
visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp + 300000));
SnmpValue snmpValue2 = SnmpUtils.getValueFactory().getCounter64(new BigInteger("40000"));
SnmpCollectionResource resource2 = new IfInfo(resourceType, agent, ifData);
resource2.setAttributeValue(objectType, snmpValue2);
resource2.visit(visitor);
// Verify Events
EasyMock.verify(agent);
verifyEvents(0);
}
Aggregations