public static AlertContext fromJsonString(String json) { ObjectMapper objectMapper = new ObjectMapper(); try { Map m = objectMapper.readValue(json, Map.class); AlertContext c = new AlertContext(); c.addAll(m); return c; } catch (Exception ex) { LOG.error("fail converting string into alertcontext", ex); return null; } }
public static AlertContext fromJsonString(String json){ ObjectMapper objectMapper = new ObjectMapper(); try{ Map m = objectMapper.readValue(json, Map.class); AlertContext c = new AlertContext(); c.addAll(m); return c; }catch(Exception ex){ LOG.error("fail converting string into alertcontext", ex); return null; } }
@Override public AlertContext deserialize(byte[] bytes) { AlertContext context = new AlertContext(); Map<String, String> properties = new HashMap<String, String>(); final int length = bytes.length; if (length < 4) { return context; } int size = Bytes.toInt(bytes, 0, 4); int offset = 4; for (int i = 0; i < size; i++) { int keySize = Bytes.toInt(bytes, offset, 4); offset += 4; int valueSize = Bytes.toInt(bytes, offset, 4); offset += 4; String key = Bytes.toString(bytes, offset, keySize); offset += keySize; String value =Bytes.toString(bytes, offset, valueSize); offset += valueSize; properties.put(key, value); } context.addAll(properties); return context; }
String alertEvent = sb.toString(); context.addAll(evaluator.getAdditionalContext()); String policyId = context.getProperty(Constants.POLICY_ID); String alertMessage = "The Policy \"" + policyId + "\" has been detected with the below information: " + alertEvent;
if(aResult.getContext() != null) context.addAll(aResult.getContext());