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 SnmpPollInterfaceMonitor method poll.
/**
* <p>poll</p>
*
* @param agentConfig a {@link org.opennms.netmgt.snmp.SnmpAgentConfig} object.
* @param mifaces a {@link java.util.List} object.
* @return a {@link java.util.List} object.
*/
public List<SnmpMinimalPollInterface> poll(SnmpAgentConfig agentConfig, List<SnmpMinimalPollInterface> mifaces) {
if (mifaces == null) {
LOG.error("Null Interfaces passed to Monitor, exiting");
return null;
}
LOG.debug("Got {} interfaces to poll", mifaces.size());
//
if (agentConfig == null)
throw new RuntimeException("SnmpAgentConfig object not available");
SnmpObjId[] adminoids = new SnmpObjId[mifaces.size()];
SnmpObjId[] operooids = new SnmpObjId[mifaces.size()];
for (int i = 0; i < mifaces.size(); i++) {
SnmpMinimalPollInterface miface = mifaces.get(i);
miface.setStatus(PollStatus.unavailable());
adminoids[i] = SnmpObjId.get(IF_ADMIN_STATUS_OID + miface.getIfindex());
operooids[i] = SnmpObjId.get(IF_OPER_STATUS_OID + miface.getIfindex());
LOG.debug("Adding Admin/Oper oids: {}/{}", adminoids[i], operooids[i]);
}
SnmpValue[] adminresults = new SnmpValue[mifaces.size()];
SnmpValue[] operoresults = new SnmpValue[mifaces.size()];
LOG.debug("try to get admin statuses");
adminresults = SnmpUtils.get(agentConfig, adminoids);
LOG.debug("got admin status {} SnmpValues", adminresults.length);
if (adminresults.length != mifaces.size()) {
LOG.warn("Snmp Interface Admin statuses collection failed");
return mifaces;
}
LOG.debug("try to get operational statuses");
operoresults = SnmpUtils.get(agentConfig, operooids);
LOG.debug("got operational status {} SnmpValues", operoresults.length);
if (operoresults.length != mifaces.size()) {
LOG.warn("Snmp Interface Operational statuses collection failed");
return mifaces;
}
for (int i = 0; i < mifaces.size(); i++) {
SnmpMinimalPollInterface miface = mifaces.get(i);
if (adminresults[i] != null && operoresults[i] != null) {
try {
miface.setAdminstatus(adminresults[i].toInt());
miface.setOperstatus(operoresults[i].toInt());
miface.setStatus(PollStatus.up());
LOG.debug("SNMP Value is {} for oid: {}", adminresults[i].toInt(), adminoids[i]);
LOG.debug("SNMP Value is {} for oid: {}", operoresults[i].toInt(), operooids[i]);
} catch (Exception e) {
LOG.warn("SNMP Value is {} for oid: {}", adminresults[i].toDisplayString(), adminoids[i]);
LOG.warn("SNMP Value is {} for oid: {}", operoresults[i].toDisplayString(), operooids[i]);
}
} else {
LOG.info("SNMP Value is null for oid: {}/{}", adminoids[i], operooids[i]);
}
}
return mifaces;
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class SnmpIfAdmin method getIfAdminStatus.
/**
* <p>
* Get desired admin interface status.
* </p>
*
* @param ifindex
* interface index to get
* @return The status of interface
* @throws SnmpBadConversionException
* Throw if returned code is not an integer
*/
public int getIfAdminStatus(int ifindex) {
SnmpObjId oid = SnmpObjId.get(snmpObjectId + "." + ifindex);
SnmpValue status = SnmpUtils.get(m_agent, oid);
return status.toInt();
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class SnmpGetter method get.
public SnmpValue get(SnmpObjId entryoid, Integer index) {
SnmpObjId instance = SnmpObjId.get(new int[] { index });
List<SnmpObjId> oids = new ArrayList<SnmpObjId>(1);
oids.add(SnmpObjId.get(entryoid, instance));
List<SnmpValue> val = get(oids);
if (val == null || val.size() != 1 || val.get(0) == null || val.get(0).isError())
return null;
return val.get(0);
}
use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method addAttributeToCollectionResource.
private SnmpAttribute addAttributeToCollectionResource(SnmpCollectionResource resource, String attributeName, AttributeType attributeType, String attributeInstance, String value) {
MibObject object = createMibObject(attributeType, attributeName, attributeInstance);
SnmpAttributeType objectType = null;
SnmpValue snmpValue = null;
if (AttributeType.STRING.equals(attributeType)) {
objectType = new SnmpAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)) {
@Override
public AttributeType getType() {
return AttributeType.STRING;
}
@Override
public void storeAttribute(CollectionAttribute attribute, Persister persister) {
persister.persistStringAttribute(attribute);
}
};
snmpValue = SnmpUtils.getValueFactory().getOctetString(value.getBytes());
} else {
objectType = new NumericAttributeType(resource.getResourceType(), "default", object, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE));
long v = Long.parseLong(value);
snmpValue = AttributeType.COUNTER.equals(attributeType) ? SnmpUtils.getValueFactory().getCounter32(v) : SnmpUtils.getValueFactory().getGauge32(v);
}
resource.setAttributeValue(objectType, snmpValue);
return new SnmpAttribute(resource, objectType, snmpValue);
}
Aggregations