We are using MVEL to evaluate the expression by passing the map in the context object. The map contains SNMP trap information such as OID and its values. e.g. sample Map contains following Keys and values.
Map<String,String> trapMap = new HashMap();
trapMap.put("1.3.6.1.4.1.9.9.311.1.1.2.1.3", "(7362915) 20:27:09.15");
trapMap.put("1.3.6.1.4.1.9.9.311.1.1.2.1.2", "2.2");
trapMap.put("1.3.6.1.4.1.9.9.311.1.1.2.1.19", "0");
trapMap.put("1.3.6.1.4.1.9.9.311.1.1.2.1.16", "SIMPLE TRAP --Port Down due to Admin Status down");
trapMap.put("errorStatus", "0");
trapMap.put("IPAddress", "10.127.34.219");
When we evaluate the expression using MVEL.eval() it either fails or return False. Following is the MVEL expression used and its result.
System.out.println("----------########### = "+(MVEL.eval("1.3.6.1.4.1.9.9.311.1.1.2.1.19 == '0'", trapMap)));
//Throws error as
//Exception in thread "main" [Error: invalid number literal: 1.3.6.1.4.1.9.9.311.1.1.2.1.19]
// [Near : {... 1.3.6.1.4.1.9.9.311.1.1.2.1.19 == '0 ....}]
System.out.println("----------########### = "+(MVEL.eval("\"1.3.6.1.4.1.9.9.311.1.1.2.1.19\" == '0'", trapMap)));
//Enclosed trap OID in double quotes and compared with String value then it returns false
System.out.println("----------########### = "+(MVEL.eval("\"1.3.6.1.4.1.9.9.311.1.1.2.1.19\" == 0", trapMap)));
//Enclosed trap OID in double quotes and compared with number then it returns false
Our Map will always contain such OID and values and we want to validate their values using MVEL. Based on this, we need to know
- if the expression mentioned is a valid expression if not then what changes are required to make it work.
- Do we need to add any additional escape characters to the keys mentioned in expression OR
- This is not possible as the key mentioned in the expression is not valid property/identifier.
Aucun commentaire:
Enregistrer un commentaire