Skip to content

Instantly share code, notes, and snippets.

@cdahlqvist
Last active January 6, 2017 14:37
Show Gist options
  • Save cdahlqvist/3c2b7cdf773d00b46e202f5a96dbb3e8 to your computer and use it in GitHub Desktop.
Save cdahlqvist/3c2b7cdf773d00b46e202f5a96dbb3e8 to your computer and use it in GitHub Desktop.
def triggered_time = ctx.trigger.triggered_time;
def failure_counts = new HashMap();
ctx.payload.failed_auth_users.aggregations.users.buckets.stream().map(p -> failure_counts.put(p.key,p.doc_count));
def successful_users = ctx.payload.success_auth_users.aggregations.users.buckets.stream().map(p -> p.key).collect(Collectors.toList());
def failure_only_records = ctx.payload.failed_auth_users.aggregations.users.buckets.stream().filter(p -> !successful_users.contains(p.key)).map(e -> ['@timestamp':triggered_time,'user':e.key,'severity':'MEDIUM','failed_auths':e.doc_count]).collect(Collectors.toList());
def success_and_failure_records = ctx.payload.success_auth_users.aggregations.users.buckets.stream().map(e -> ['@timestamp':triggered_time,'user':e.key,'severity':'HIGH','successful_auths':e.doc_count,'failed_auths':failure_counts.get(e.key)]).collect(Collectors.toList());
success_and_failure_records.addAll(failure_only_records);
return ['_doc': success_and_failure_records];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment