Search in sources :

Example 76 with SnmpValue

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;
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 77 with SnmpValue

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;
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpMinimalPollInterface(org.opennms.netmgt.snmpinterfacepoller.pollable.PollableSnmpInterface.SnmpMinimalPollInterface) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 78 with SnmpValue

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();
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 79 with SnmpValue

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);
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) ArrayList(java.util.ArrayList) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 80 with SnmpValue

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);
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) AttributeType(org.opennms.netmgt.collection.api.AttributeType) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType) NumericAttributeType(org.opennms.netmgt.collectd.NumericAttributeType) AttributeGroupType(org.opennms.netmgt.collection.api.AttributeGroupType) Persister(org.opennms.netmgt.collection.api.Persister) MibObject(org.opennms.netmgt.config.datacollection.MibObject) SnmpAttributeType(org.opennms.netmgt.collectd.SnmpAttributeType)

Aggregations

SnmpValue (org.opennms.netmgt.snmp.SnmpValue)112 Test (org.junit.Test)57 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)47 SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)24 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)20 InetAddress (java.net.InetAddress)19 Map (java.util.Map)15 PollStatus (org.opennms.netmgt.poller.PollStatus)14 JoeSnmpValueFactory (org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory)12 ArrayList (java.util.ArrayList)11 ParameterMap (org.opennms.core.utils.ParameterMap)9 Parm (org.opennms.netmgt.xml.event.Parm)9 PDU (org.snmp4j.PDU)9 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)8 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)8 LinkedHashMap (java.util.LinkedHashMap)7 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)5 HashMap (java.util.HashMap)4 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)4