Exemplo n.º 1
0
  public Logmsg getTrapEventLogmsg(MibValueSymbol trapValueSymbol) {
    Logmsg msg = new Logmsg();
    msg.setDest("logndisplay");

    final StringBuffer dbuf = new StringBuffer();
    dbuf.append("<p>");
    dbuf.append("\n");
    dbuf.append("\t").append(trapValueSymbol.getName()).append(" trap received\n");
    int vbNum = 1;
    for (MibValue vb : getTrapVars(trapValueSymbol)) {
      dbuf.append("\t").append(vb.getName()).append("=%parm[#").append(vbNum).append("]%\n");
      vbNum++;
    }

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

    msg.setContent(dbuf.toString());

    return msg;
  }
Exemplo n.º 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();
  }