Ejemplo n.º 1
0
 public static String getTrapEventLabel(MibValueSymbol trapValueSymbol) {
   StringBuffer buf = new StringBuffer();
   buf.append(trapValueSymbol.getMib());
   buf.append(" defined trap event: ");
   buf.append(trapValueSymbol.getName());
   return buf.toString();
 }
Ejemplo n.º 2
0
  protected void registerMIBs()
      throws IOException, MibLoaderException, DuplicateRegistrationException {
    if (modules == null) {
      modules = new Modules(getFactory());
    }
    String filePath = MibsLoader.getValueFromProperties("loadSpecifiedMib");
    System.out.println("filePath = " + filePath);
    MibsLoader mibsLoader = new MibsLoader();
    mibsLoader.loadMibs(filePath);

    Mib mib = mibsLoader.getMib();

    Properties properties = MibsLoader.readProperties(MibsLoader.OIDVALUEMAPFILE);
    for (Object t : properties.keySet()) {
      String key = t.toString();
      String value = properties.getProperty(t.toString());
      System.out.println(key + " = " + value);
      MibValueSymbol mvs = mib.getSymbolByOid(key);
      if (mvs != null) {
        if (mvs.isScalar()) {
          registerScalar(key + ".0", value);
        }

        if (mvs.isTableColumn()) {
          // 模拟配置任意行
          String[] values = value.trim().split(";");
          for (int i = 0; i < values.length; i++) {
            registerScalar(key + "." + Integer.toString(i) + ".0", values[i]);
          }
        }
      }
    }
    modules.registerMOs(server, null);
  }
Ejemplo n.º 3
0
 public static List<MibValue> getTrapVars(MibValueSymbol trapValueSymbol) {
   if (trapValueSymbol.getType() instanceof SnmpNotificationType) {
     SnmpNotificationType v2notif = (SnmpNotificationType) trapValueSymbol.getType();
     return getV2NotificationObjects(v2notif);
   } else if (trapValueSymbol.getType() instanceof SnmpTrapType) {
     SnmpTrapType v1trap = (SnmpTrapType) trapValueSymbol.getType();
     return getV1TrapVariables(v1trap);
   } else {
     throw new IllegalStateException("trap type is not an SNMP v1 Trap or v2 Notification");
   }
 }
Ejemplo n.º 4
0
 private static String getTrapOid(MibValueSymbol trapValueSymbol) {
   if (trapValueSymbol.getType() instanceof SnmpNotificationType) {
     return "." + trapValueSymbol.getValue().toString();
   } else if (trapValueSymbol.getType() instanceof SnmpTrapType) {
     SnmpTrapType v1trap = (SnmpTrapType) trapValueSymbol.getType();
     return "." + v1trap.getEnterprise().toString() + "." + trapValueSymbol.getValue().toString();
   } else {
     throw new IllegalStateException(
         "Trying to get trap information from an object that's not a trap and not a notification");
   }
 }
Ejemplo n.º 5
0
  private MibItem extractMibItems(MibValueSymbol symbol) {

    MibItem item = new MibItem(extractOid(symbol).toString(), symbol.getName(), symbol.toString());

    for (MibValueSymbol child : symbol.getChildren()) {
      MibItem childItem = extractMibItems(child);
      item.addChild(childItem);
    }

    return item;
  }
Ejemplo n.º 6
0
  public Events convertMibToEvents(Mib mib, String ueibase) {
    Events events = new Events();
    for (MibSymbol sym : getAllSymbolsFromMib(mib)) {
      if (!(sym instanceof MibValueSymbol)) {
        continue;
      }

      MibValueSymbol vsym = (MibValueSymbol) sym;
      if ((!(vsym.getType() instanceof SnmpNotificationType))
          && (!(vsym.getType() instanceof SnmpTrapType))) {
        continue;
      }

      events.addEvent(getTrapEvent(vsym, ueibase));
    }
    return events;
  }
Ejemplo n.º 7
0
 public static String getTrapEventUEI(MibValueSymbol trapValueSymbol, String ueibase) {
   StringBuffer buf = new StringBuffer(ueibase);
   if (!ueibase.endsWith("/")) {
     buf.append("/");
   }
   buf.append(trapValueSymbol.getName());
   return buf.toString();
 }
Ejemplo n.º 8
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());
  }
Ejemplo n.º 9
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;
  }
Ejemplo n.º 10
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();
  }