use of org.jsmiparser.smi.SmiPrimitiveType in project opennms by OpenNMS.
the class JsmiMibParser method getTrapEventDescr.
/**
* Gets the trap event description.
*
* @param trap the trap object
* @return the trap event description
*/
protected String getTrapEventDescr(Notification trap) {
String description = trap.getDescription();
if (description == null) {
LOG.warn("The trap {} doesn't have a description field", trap.getOidStr());
}
// 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 descrEndingNewlines = description == null ? "No Description." : description.replaceAll("^", "\n<p>").replaceAll("$", "</p>\n");
final StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
if (dbuf.charAt(dbuf.length() - 1) == '\n') {
// delete the \n at the end
dbuf.deleteCharAt(dbuf.length() - 1);
}
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>();
SmiType t = var.getType();
while (t.getEnumValues() == null) {
t = t.getBaseType();
}
List<SmiNamedNumber> enumValues = t.getEnumValues();
if (enumValues != null) {
for (SmiNamedNumber v : enumValues) {
map.put(v.getValue(), v.getId());
}
} else {
// This is theoretically impossible, but in case of another bug in JSMIParser, better than an NPE.
map.put(new BigInteger("0"), "Unable to derive list of possible values.");
}
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') {
// delete the \n at the end
dbuf.deleteCharAt(dbuf.length() - 1);
}
dbuf.append("</table>\n\t");
return dbuf.toString();
}
use of org.jsmiparser.smi.SmiPrimitiveType in project opennms by OpenNMS.
the class JsmiMibParser method getTrapVarbindsDecode.
/**
* 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>();
SmiType t = var.getType();
while (t.getEnumValues() == null) {
t = t.getBaseType();
}
List<SmiNamedNumber> enumValues = t.getEnumValues();
if (enumValues != null) {
for (SmiNamedNumber v : enumValues) {
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());
}
Aggregations