示例#1
0
  public void report() {

    final Map<String, Bean> mibMapping = jmxMib.getMapping();

    final Set<String> attributesInMib = new HashSet<String>();
    final Set<String> attributesInIndex = new HashSet<String>(jmxIndex.getAttributePaths());
    for (Map.Entry<String, Bean> entry : mibMapping.entrySet()) {
      String oid = entry.getKey();
      Bean bean = entry.getValue();
      if (attributesInIndex.contains(bean.absolutePath)) {
        if (attributesInMib.contains(bean.absolutePath)) {
          System.err.println(
              "jmx2snmp: attribute mapping for [" + bean.absolutePath + "] found more than once");
        }
        attributesInMib.add(bean.absolutePath);
      } else {
        if (bean.leaf) {
          System.err.println(
              "jmx2snmp: attribute ["
                  + bean.absolutePath
                  + "] no longer exists at OID ["
                  + oid
                  + "]");
        }
      }
    }

    attributesInIndex.removeAll(attributesInMib);

    for (String attribute : attributesInIndex) {
      System.err.println("jmx2snmp: attribute not mapped yet: " + attribute);
    }
  }
示例#2
0
  public void processPdu(CommandResponderEvent pRequest) {

    final PDU requestPdu = pRequest.getPDU();

    if (requestPdu == null) {
      return;
    }

    try {

      final PDU responsePdu = new PDU(requestPdu);
      responsePdu.setType(PDU.RESPONSE);

      if (requestPdu.getType() == PDU.GET) {

        for (VariableBinding binding : responsePdu.toArray()) {
          final OID oid = binding.getOid();
          final String path = jmxMib.getPathFromOid(oid.toString());

          if (path == null) {
            binding.setVariable(Null.noSuchObject);
            continue;
          }

          final JmxAttribute attribute = jmxIndex.getAttributeAtPath(path);

          if (attribute == null) {
            binding.setVariable(Null.noSuchObject);
            continue;
          }

          final Variable variable = getVariableFromJmxAttribute(attribute);

          if (variable != null) {
            binding.setVariable(variable);
          }
        }

      } else if (requestPdu.getType() == PDU.GETNEXT) {

        for (VariableBinding binding : responsePdu.toArray()) {
          final OID oid = binding.getOid();
          final String next = jmxMib.getNextOidFromOid(oid.toString());

          if (next == null) {
            binding.setVariable(Null.noSuchObject);
            continue;
          }

          final OID nextOid = new OID(next);

          binding.setOid(nextOid);

          final String path = jmxMib.getPathFromOid(nextOid.toString());

          if (path == null) {
            binding.setVariable(Null.noSuchObject);
            continue;
          }

          final JmxAttribute attribute = jmxIndex.getAttributeAtPath(path);

          if (attribute == null) {
            binding.setVariable(Null.noSuchObject);
            continue;
          }

          final Variable variable = getVariableFromJmxAttribute(attribute);

          if (variable != null) {
            binding.setVariable(variable);
          }
        }

      } else {

      }

      pRequest.getStateReference().setTransportMapping(pRequest.getTransportMapping());
      pRequest
          .getMessageDispatcher()
          .returnResponsePdu(
              pRequest.getMessageProcessingModel(),
              pRequest.getSecurityModel(),
              pRequest.getSecurityName(),
              pRequest.getSecurityLevel(),
              responsePdu,
              pRequest.getMaxSizeResponsePDU(),
              pRequest.getStateReference(),
              new StatusInformation());

    } catch (Exception e) {
      e.printStackTrace();
    }
  }