Package org.snmp4j.smi

Examples of org.snmp4j.smi.OID


        return trap;
    }

    private OID getOID(String oidString) {
        return new OID(oidString);
    }
View Full Code Here


    }
    return -1;
  }

  public static OID getTrapOID(OID enterprise, int genericID, int specificID) {
    OID oid;
    if (genericID != 6) {
      oid = new OID(snmpTraps);
      oid.append(genericID+1);
    }
    else {
      oid = new OID(enterprise);
      oid.append(0);
      oid.append(specificID);
    }
    return oid;
  }
View Full Code Here

   */
  public DefaultCounterListener() {
  }

  public synchronized void incrementCounter(CounterEvent event) {
    OID id = event.getOid();
    VariableBinding counter = (VariableBinding) counters.get(id);
    if (counter == null) {
      counter = new VariableBinding(id, new Counter32(1));
      counters.put(id, counter);
    }
View Full Code Here

    // Iterating over map
    for (Entry<Object, Object> entry : p.entrySet()) {
      oidValue = entry.getValue().toString();
      descr = entry.getKey().toString();
      PDU pdu = new PDU();
      pdu.add(new VariableBinding(new OID(oidValue)));
      pdu.setRequestID(new Integer32(1));
      pdu.setType(PDU.GET);

      try {
        response = snmp.get(pdu, comtarget);
View Full Code Here

          if (!provider.getAddress(itemName).equals(address)) {
            continue;
          }

          // Check the OID
          OID oid = provider.getOID(itemName);
          Variable variable = pdu.getVariable(oid);
          if (variable != null) {
            Class<? extends Item> itemType = provider.getItemType(itemName);

            // Do any transformations
            String value = variable.toString();
            try {
              value = provider.doTransformation(itemName, value);
            } catch (TransformationException e) {
              logger.error("Transformation error with item {}: {}", itemName, e);
            }

            // Change to a state
            State state = null;
            if (itemType.isAssignableFrom(StringItem.class)) {
              state = StringType.valueOf(value);
            } else if (itemType.isAssignableFrom(NumberItem.class)) {
              state = DecimalType.valueOf(value);
            } else if (itemType.isAssignableFrom(SwitchItem.class)) {
              state = OnOffType.valueOf(value);
            }

            if (state != null) {
              eventPublisher.postUpdate(itemName, state);
            } else {
              logger.debug(
                  "'{}' couldn't be parsed to a State. Valid State-Types are String and Number",
                  variable.toString());
            }
          } else {
            logger.trace("PDU doesn't contain a variable with OID ‘{}‘", oid.toString());
          }
        }
      }
    }
  }
View Full Code Here

    logger.debug("SNMP receive command {} from {}", itemName, command);
   
    SnmpBindingProvider providerCmd = null;
   
    for (SnmpBindingProvider provider : this.providers) {
      OID oid = provider.getOID(itemName, command);
      if (oid != null) {
        providerCmd = provider;
        break;
      }
    }

    if (providerCmd == null) {
      logger.warn("No match for binding provider [itemName={}, command={}]", itemName, command);
      return;
    }

    logger.debug("SNMP command for {} to {}", itemName, providerCmd.toString());

    // Set up the target
    CommunityTarget target = new CommunityTarget();
      target.setCommunity(providerCmd.getCommunity(itemName, command));
      target.setAddress(providerCmd.getAddress(itemName, command));
      target.setRetries(retries);
      target.setTimeout(timeout);
      target.setVersion(SnmpConstants.version1);

    Variable var = providerCmd.getValue(itemName, command);
    OID oid = providerCmd.getOID(itemName, command);
      VariableBinding varBind = new VariableBinding(oid,var);

    // Create the PDU
    PDU pdu = new PDU();
      pdu.add(varBind);
View Full Code Here

        SnmpBindingConfigElement newElement = new SnmpBindingConfigElement();
        if (outMatcher.matches()) {
          String commandAsString = outMatcher.group(1).toString();
          newElement.address = GenericAddress.parse("udp:" + outMatcher.group(2).toString() + "/161");
          newElement.community = new OctetString(outMatcher.group(3).toString());
          newElement.oid = new OID(outMatcher.group(4).toString());

          // Only Integer commands accepted at this time.
          newElement.value = new Integer32(Integer.parseInt(outMatcher.group(5).toString()));

          Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandAsString);
          if (command == null) {
            logger.error("SNMP can't resolve command {} for item {}", commandAsString, item);
          } else {
            config.put(command, newElement);
          }
        } else if (inMatcher.matches()) {
          newElement.address = GenericAddress.parse("udp:" + inMatcher.group(1).toString() + "/161");
          newElement.community = new OctetString(inMatcher.group(2).toString());
          newElement.oid = new OID(inMatcher.group(3).toString());
          newElement.refreshInterval = Integer.valueOf(inMatcher.group(4)).intValue();
          if(inMatcher.groupCount() == 5)
            newElement.setTransformationRule(inMatcher.group(5));

          config.put(IN_BINDING_KEY, newElement);
View Full Code Here

   * @{inheritDoc
   */
  @Override
  public OID getOID(String itemName) {
    SnmpBindingConfig config = (SnmpBindingConfig) bindingConfigs.get(itemName);
    return config != null ? config.get(IN_BINDING_KEY).oid : new OID("");
  }
View Full Code Here

   * @{inheritDoc
   */
  @Override
  public OID getOID(String itemName, Command command) {
    SnmpBindingConfig config = (SnmpBindingConfig) bindingConfigs.get(itemName);
    return config != null ? config.get(command).oid : new OID("");
  }
View Full Code Here

TOP

Related Classes of org.snmp4j.smi.OID

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.