示例#1
0
  private static List<Varbindsdecode> getTrapVarbindsDecode(MibValueSymbol trapValueSymbol) {
    Map<String, Varbindsdecode> decode = new LinkedHashMap<String, Varbindsdecode>();

    int vbNum = 1;
    for (MibValue vb : getTrapVars(trapValueSymbol)) {
      String parmName = "parm[#" + vbNum + "]";

      SnmpObjectType snmpObjectType =
          ((SnmpObjectType) ((ObjectIdentifierValue) vb).getSymbol().getType());
      if (snmpObjectType.getSyntax().getClass().equals(IntegerType.class)) {
        IntegerType integerType = (IntegerType) snmpObjectType.getSyntax();

        if (integerType.getAllSymbols().length > 0) {
          SortedMap<Integer, String> map = new TreeMap<Integer, String>();
          for (MibValueSymbol sym : integerType.getAllSymbols()) {
            map.put(new Integer(sym.getValue().toString()), sym.getName());
          }

          for (Entry<Integer, String> entry : map.entrySet()) {
            if (!decode.containsKey(parmName)) {
              Varbindsdecode newVarbind = new Varbindsdecode();
              newVarbind.setParmid(parmName);
              decode.put(newVarbind.getParmid(), newVarbind);
            }

            Decode d = new Decode();
            d.setVarbinddecodedstring(entry.getValue());
            d.setVarbindvalue(entry.getKey().toString());
            decode.get(parmName).addDecode(d);
          }
        }
      }

      vbNum++;
    }

    return new ArrayList<Varbindsdecode>(decode.values());
  }
示例#2
0
  public static String getTrapEventDescr(MibValueSymbol trapValueSymbol) {
    String description = ((SnmpType) trapValueSymbol.getType()).getDescription();

    // FIXME There a lot of detail here (like removing the last \n) that can go away when we don't
    // need to match mib2opennms exactly

    final String descrStartingNewlines = description.replaceAll("^", "\n<p>");

    final String descrEndingNewlines = descrStartingNewlines.replaceAll("$", "</p>\n");

    // final String descrTabbed = descrEndingNewlines.replaceAll("(?m)^", "\t");
    // final StringBuffer dbuf = new StringBuffer(descrTabbed);

    final StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
    if (dbuf.charAt(dbuf.length() - 1) == '\n') {
      dbuf.deleteCharAt(dbuf.length() - 1); // delete the \n at the end
    }

    // if (dbuf.lastIndexOf("\n") != -1) {
    //    dbuf.insert(dbuf.lastIndexOf("\n") + 1, '\t');
    // }

    // final StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
    // dbuf.append("\n");

    dbuf.append("<table>");
    dbuf.append("\n");
    int vbNum = 1;
    for (MibValue vb : getTrapVars(trapValueSymbol)) {
      dbuf.append("\t<tr><td><b>\n\n\t").append(vb.getName());
      dbuf.append("</b></td><td>\n\t%parm[#").append(vbNum).append("]%;</td><td><p>");

      SnmpObjectType snmpObjectType =
          ((SnmpObjectType) ((ObjectIdentifierValue) vb).getSymbol().getType());
      if (snmpObjectType.getSyntax().getClass().equals(IntegerType.class)) {
        IntegerType integerType = (IntegerType) snmpObjectType.getSyntax();

        if (integerType.getAllSymbols().length > 0) {
          SortedMap<Integer, String> map = new TreeMap<Integer, String>();
          for (MibValueSymbol sym : integerType.getAllSymbols()) {
            map.put(new Integer(sym.getValue().toString()), sym.getName());
          }

          dbuf.append("\n");
          for (Entry<Integer, String> entry : map.entrySet()) {
            dbuf.append("\t\t")
                .append(entry.getValue())
                .append("(")
                .append(entry.getKey())
                .append(")\n");
          }
          dbuf.append("\t");
        }
      }

      dbuf.append("</p></td></tr>\n");
      vbNum++;
    }

    if (dbuf.charAt(dbuf.length() - 1) == '\n') {
      dbuf.deleteCharAt(dbuf.length() - 1); // delete the \n at the end
    }
    dbuf.append("</table>\n\t");

    return dbuf.toString();
  }