Ejemplo n.º 1
0
 /**
  * Gets the trap varbinds decode.
  *
  * @param trap the trap object
  * @return the trap varbinds decode
  */
 protected List<Varbindsdecode> getTrapVarbindsDecode(Notification trap) {
   Map<String, Varbindsdecode> decode = new LinkedHashMap<String, Varbindsdecode>();
   int vbNum = 1;
   for (SmiVariable var : trap.getObjects()) {
     String parmName = "parm[#" + vbNum + "]";
     SmiPrimitiveType type = var.getType().getPrimitiveType();
     if (type.equals(SmiPrimitiveType.ENUM)) {
       SortedMap<BigInteger, String> map = new TreeMap<BigInteger, String>();
       for (SmiNamedNumber v : var.getType().getEnumValues()) {
         map.put(v.getValue(), v.getId());
       }
       for (Entry<BigInteger, 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.º 2
0
 /**
  * Gets the metric type.
  *
  * <p>This should be consistent with NumericAttributeType and StringAttributeType.
  *
  * <p>For this reason the valid types are: counter, gauge, timeticks, integer, octetstring,
  * string.
  *
  * <p>Any derivative is also valid, for example: Counter32, Integer64, etc...
  *
  * @param type the type
  * @return the type
  */
 private String getMetricType(SmiPrimitiveType type) {
   if (type.equals(SmiPrimitiveType.ENUM)) // ENUM are just informational elements.
   return "string";
   if (type.equals(
       SmiPrimitiveType.OBJECT_IDENTIFIER)) // ObjectIdentifier will be treated as strings.
   return "string";
   if (type.equals(SmiPrimitiveType.UNSIGNED_32)) // Unsigned32 will be treated as integer.
   return "integer";
   return type.toString().replaceAll("_", "").toLowerCase();
 }
Ejemplo n.º 3
0
 /**
  * Gets the trap event description.
  *
  * @param trap the trap object
  * @return the trap event description
  */
 protected String getTrapEventDescr(Notification trap) {
   String description = trap.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 StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
   if (dbuf.charAt(dbuf.length() - 1) == '\n') {
     dbuf.deleteCharAt(dbuf.length() - 1); // delete the \n at the end
   }
   dbuf.append("<table>");
   dbuf.append("\n");
   int vbNum = 1;
   for (SmiVariable var : trap.getObjects()) {
     dbuf.append("\t<tr><td><b>\n\n\t").append(var.getId());
     dbuf.append("</b></td><td>\n\t%parm[#").append(vbNum).append("]%;</td><td><p>");
     SmiPrimitiveType type = var.getType().getPrimitiveType();
     if (type.equals(SmiPrimitiveType.ENUM)) {
       SortedMap<BigInteger, String> map = new TreeMap<BigInteger, String>();
       for (SmiNamedNumber v : var.getType().getEnumValues()) {
         map.put(v.getValue(), v.getId());
       }
       dbuf.append("\n");
       for (Entry<BigInteger, 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();
 }