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; } }
private AlertEmailComponent getEventComponent(AlertContext context) { AlertContext eventFieldsContext = new AlertContext(); String eventFields = context.getProperty(Constants.ALERT_EVENT_FIELDS); String[] fields = eventFields.split(EVENT_FIELDS_SPLITTER); for (String key : fields) { eventFieldsContext.addProperty(key, context.getProperty(key)); } AlertEmailComponent component = new AlertEmailComponent(); component.setAlertContext(eventFieldsContext); return component; } }
@JsonProperty("alertContext") public AlertContext getWrappedAlertContext() { return AlertContext.fromJsonString(alertContext); }
String alertExecutorId = siddhiAlertContext.alertExecutor.getExecutorId(); AlertAPIEntity entity = new AlertAPIEntity(); AlertContext context = new AlertContext(); String sourceStreams = evaluator.getAdditionalContext().get(Constants.SOURCE_STREAMS); String[] sourceStreamsArr = sourceStreams.split(","); context.addProperty(attrRenameList.get(index), rets.get(index)); for (Entry<String, String> entry : context.getProperties().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); context.addAll(evaluator.getAdditionalContext()); String policyId = context.getProperty(Constants.POLICY_ID); String alertMessage = "The Policy \"" + policyId + "\" has been detected with the below information: " + alertEvent; String site = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.SITE); context.addProperty(Constants.ALERT_EVENT, alertEvent); context.addProperty(Constants.ALERT_EVENT_FIELDS, alertEventFields); context.addProperty(Constants.ALERT_MESSAGE, alertMessage); context.addProperty(Constants.ALERT_TIMESTAMP_PROPERTY, DateTimeUtil.millisecondsToHumanDateWithSeconds(System.currentTimeMillis())); context.addProperty(EagleConfigConstants.APPLICATION, application); context.addProperty(EagleConfigConstants.SITE, site); entity.setTimestamp(timestamp); tags.put(Constants.SOURCE_STREAMS, context.getProperty(Constants.SOURCE_STREAMS)); tags.put(Constants.POLICY_ID, context.getProperty(Constants.POLICY_ID)); tags.put(Constants.ALERT_SOURCE, source); tags.put(Constants.ALERT_EXECUTOR_ID, alertExecutorId);
AlertContext context = new AlertContext(); if(aResult.getContext() != null) context.addAll(aResult.getContext()); context.addProperty(Constants.ALERT_EVENT, aResult.toString()); context.addProperty(Constants.ALERT_MESSAGE, alertMessage); context.addProperty(Constants.ALERT_TIMESTAMP_PROPERTY, DateTimeUtil.millisecondsToHumanDateWithSeconds(System.currentTimeMillis())); context.addProperty(EagleConfigConstants.APPLICATION, applicatioin); context.addProperty(EagleConfigConstants.SITE, site); } catch (Exception ex) { LOG.error("site, dataSource not set in config file, ", ex); context.addProperty(EagleConfigConstants.APPLICATION, applicatioin); context.addProperty(EagleConfigConstants.SITE, site); context.addProperty(Constants.POLICY_NAME, alertContext.policyId); entity.setAlertContext(context.toJsonString()); return entity;
component.setAlertContext(AlertContext.fromJsonString(entity.getAlertContext())); List<AlertEmailComponent> components = new ArrayList<AlertEmailComponent>(); components.add(component); email.setComponents(components); if (AlertContext.fromJsonString(entity.getAlertContext()).getProperty(Constants.SUBJECT) != null) { email.setSubject(AlertContext.fromJsonString(entity.getAlertContext()).getProperty(Constants.SUBJECT));
public AlertEmailSender(AlertEmailContext alertEmail){ this.recipents = alertEmail.getRecipients(); this.configFileName = alertEmail.getVelocityTplFile(); this.subject = alertEmail.getSubject(); this.sender = alertEmail.getSender(); this.cc = alertEmail.getCc(); for(AlertEmailComponent bean : alertEmail.getComponents()){ this.alertContexts.add(bean.getAlertContext().getProperties()); } String tmp = ManagementFactory.getRuntimeMXBean().getName(); this.origin = tmp.split("@")[1] + "(pid:" + tmp.split("@")[0] + ")"; threadName = Thread.currentThread().getName(); LOG.info("Initialized "+threadName+": origin is : " + this.origin+", recipient of the email: " + this.recipents+", velocity TPL file: " + this.configFileName); }
@JsonProperty("alertContext") public void setDecodedAlertContext(AlertContext alertContext) { if(alertContext != null) this.alertContext = alertContext.toJsonString(); _pcs.firePropertyChange("alertContext", null, null); }
private List<String> getKeyList(AlertAPIEntity entity) { List<String> keys = new ArrayList<>(entity.getTags().values()); if(fields != null && !fields.isEmpty()) { for (String field: fields) { AlertContext context = entity.getWrappedAlertContext(); keys.add(context.getProperty(field)); } } return keys; }
AlertContext context = AlertContext.fromJsonString(entity.getAlertContext()); component.setAlertContext(context); AlertEmailComponent eventComponent = getEventComponent(context); email.setComponents(components); if (context.getProperty(Constants.SUBJECT) != null) { email.setSubject(context.getProperty(Constants.SUBJECT));
public AlertEmailSender(AlertEmailContext alertEmail){ this.recipents = alertEmail.getRecipients(); this.configFileName = alertEmail.getVelocityTplFile(); this.subject = alertEmail.getSubject(); this.sender = alertEmail.getSender(); this.cc = alertEmail.getCc(); for(AlertEmailComponent bean : alertEmail.getComponents()){ this.alertContexts.add(bean.getAlertContext().getProperties()); } String tmp = ManagementFactory.getRuntimeMXBean().getName(); this.origin = tmp.split("@")[1] + "(pid:" + tmp.split("@")[0] + ")"; threadName = Thread.currentThread().getName(); LOG.info("Initialized "+threadName+": origin is : " + this.origin+", recipient of the email: " + this.recipents+", velocity TPL file: " + this.configFileName); }
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 byte[] serialize(AlertContext context) { final Map<String, String> pair = context.getProperties(); int totalSize = 4; for (Entry<String, String> entry : pair.entrySet()) {
@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; }