Search in sources :

Example 1 with SnmpMinimalPollInterface

use of org.opennms.netmgt.snmpinterfacepoller.pollable.PollableSnmpInterface.SnmpMinimalPollInterface 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)

Aggregations

SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)1 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)1 SnmpMinimalPollInterface (org.opennms.netmgt.snmpinterfacepoller.pollable.PollableSnmpInterface.SnmpMinimalPollInterface)1