Search in sources :

Example 56 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.

the class SnmpGetter method get.

public List<SnmpValue> get(List<SnmpObjId> entryoids, Integer index) {
    SnmpObjId instance = SnmpObjId.get(new int[] { index });
    List<SnmpObjId> oids = new ArrayList<SnmpObjId>(entryoids.size());
    for (SnmpObjId entryoid : entryoids) oids.add(SnmpObjId.get(entryoid, instance));
    return get(oids);
}
Also used : ArrayList(java.util.ArrayList) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 57 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId 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 58 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.

the class TrapHandlerITCase method sendV2Trap.

public void sendV2Trap(String enterprise, int specific, LinkedHashMap<String, SnmpValue> varbinds) throws Exception {
    SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
    boolean isGeneric = false;
    SnmpObjId trapOID;
    if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
        isGeneric = true;
        trapOID = enterpriseId;
    } else {
        trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(specific));
    // XXX or should it be this
    // trap OID = enterprise + ".0." + specific;
    }
    SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
    if (isGeneric) {
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    }
    for (Map.Entry<String, SnmpValue> entry : varbinds.entrySet()) {
        pdu.addVarBind(SnmpObjId.get(entry.getKey()), entry.getValue());
    }
    pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 59 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.

the class TrapHandlerITCase method sendV2Trap.

public void sendV2Trap(String enterprise, int specific) throws Exception {
    SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
    boolean isGeneric = false;
    SnmpObjId trapOID;
    if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
        isGeneric = true;
        trapOID = enterpriseId;
    } else {
        trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(specific));
    // XXX or should it be this
    // trap OID = enterprise + ".0." + specific;
    }
    SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
    if (isGeneric) {
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    }
    pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
Also used : SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 60 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.

the class WalkCommand method doExecute.

@Override
protected Object doExecute() throws Exception {
    LOG.debug("snmp:walk {} {} {}", m_location != null ? "-l " + m_location : "", m_host, m_oids);
    final List<SnmpObjId> snmpObjIds = m_oids.stream().map(oid -> SnmpObjId.get(oid)).collect(Collectors.toList());
    final SnmpAgentConfig agent = snmpAgentConfigFactory.getAgentConfig(InetAddress.getByName(m_host), m_location);
    final CompletableFuture<List<SnmpResult>> future = locationAwareSnmpClient.walk(agent, snmpObjIds).withDescription("snmp:walk").withLocation(m_location).execute();
    while (true) {
        try {
            future.get(1, TimeUnit.SECONDS).stream().forEach(res -> {
                System.out.printf("[%s].[%s] = %s%n", res.getBase(), res.getInstance(), res.getValue());
            });
            break;
        } catch (TimeoutException e) {
        // pass
        }
        System.out.print(".");
    }
    return null;
}
Also used : Argument(org.apache.felix.gogo.commands.Argument) SnmpAgentConfigFactory(org.opennms.netmgt.config.api.SnmpAgentConfigFactory) Logger(org.slf4j.Logger) OsgiCommandSupport(org.apache.karaf.shell.console.OsgiCommandSupport) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) InetAddress(java.net.InetAddress) TimeUnit(java.util.concurrent.TimeUnit) SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) List(java.util.List) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Command(org.apache.felix.gogo.commands.Command) Option(org.apache.felix.gogo.commands.Option) LocationAwareSnmpClient(org.opennms.netmgt.snmp.proxy.LocationAwareSnmpClient) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) List(java.util.List) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)73 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)47 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)23 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)21 InetAddress (java.net.InetAddress)19 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 Map (java.util.Map)13 PollStatus (org.opennms.netmgt.poller.PollStatus)12 PDU (org.snmp4j.PDU)10 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)7 SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)6 List (java.util.List)5 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)4 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3