# Correlating/Matching data from 2 sources with diferent field types

**URL:** <https://discuss.elastic.co/t/correlating-matching-data-from-2-sources-with-diferent-field-types/349218>\
**Category:** Elastic Security\
**Created:** [December 13, 2023, 6:02am UTC](https://discuss.elastic.co/t/correlating-matching-data-from-2-sources-with-diferent-field-types/349218 "2023-12-13T06:02:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![erni23](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@erni23](https://discuss.elastic.co/u/erni23)\
**Post date:** [December 13, 2023, 6:02am UTC](https://discuss.elastic.co/t/correlating-matching-data-from-2-sources-with-diferent-field-types/349218/1 "2023-12-13T06:02:03Z")

</div>

This is the scenario and I am using elastic 7.17;

•Data source 1: VPN Network traffic data ingested with the usual fields (event.outcome: "success" and event.action: "login” etc (JSON)  
And  
•Data source 2: Logs from door Badge access control entry systems: (badge.request: “granted” and badge.name: “user one”)

I want to create a security rule to match event from data source 1 and data source 2 and get an alert when all events occurs within 15 minutes.

For instance, VPN network traffic event (event.outcome: "success" and event.action: "login" ),  
matches /correlate  
Logs from door Badge access control entry systems (badge.request: “granted” and badge.name: “user one”)

That said, is it possible to query and create a security alert rule with data from those 2 different sources/fields and how?

Which type of security alert rule is the best option to create this type of rule when all events occur within 15 minutes?

When I do a normal discovery query to try and match VPN traffic with door badge, I get nothing.  
However, I do get some result when I create the below security rule using “Event Correlation rule” but I am not sure it’s accurate.

```
Sequence with maxspan=15m

```

[any where event.outcome: "success" and event.action: "login]  
[any where badge.request: “granted” and badge.name: “user one”]

Appreciate your help in advance.

---

<div class="post-metadata">

**Author:** ![RylandHerrick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rylandherrick/32/67401_2.png) [@RylandHerrick](https://discuss.elastic.co/u/RylandHerrick)\
**Post date:** [December 13, 2023, 3:42pm UTC](https://discuss.elastic.co/t/correlating-matching-data-from-2-sources-with-diferent-field-types/349218/2 "2023-12-13T15:42:18Z")

</div>

HI @erni23, welcome!

If you want to be alerted whenever a _sequence_ of events occurs in a certain order, within a certain time frame, then you're correct that the [Event Correlation Rule](https://www.elastic.co/guide/en/security/current/rules-ui-create.html#create-eql-rule) is the right tool for you.

Leveraging the [EQL language](https://www.elastic.co/guide/en/elasticsearch/reference/8.11/eql-syntax.html), these rules allow you to construct a query describing the desired event sequence. When a sequence is found, a single summary alert will be generated, along with a [building block alert](https://www.elastic.co/guide/en/security/current/building-block-rule.html#building-block-rule) for each event in the sequence.

That being said, a few notes on your query:

```auto
sequence with maxspan=15m
 [any where event.outcome: "success" and event.action: "login]
 [any where badge.request: “granted” and badge.name: “user one”]

```

1. There doesn't appear to be any "correlation" happening here; how do you know that the login event is related to the badge request? Typically, the [`by` keyword](https://www.elastic.co/guide/en/elasticsearch/reference/8.11/eql-syntax.html#eql-by-keyword) is used to ensure that the sequence of events all comes from the same IP/host/user, e.g. `sequence by host.ip with maxpan=15m`
2. Replacing your `any`s above with a more specific [event category field](https://www.elastic.co/guide/en/elasticsearch/reference/8.11/eql.html#specify-a-timestamp-or-event-category-field) will give the query better performance, as it will not have to search as many documents. For example:

```auto
sequence with maxspan=15m
 [authentication where event.outcome: "success" and event.action: "login]
 [authentication where badge.request: “granted” and badge.name: “user one”]

```

would effectively add a filter of `event.category: "authentication"` to your query.

So: it looks like you've found the proper solution, and there are a few additional optimizations you can/may make. Please let us know if you have more questions!

---

<div class="post-metadata">

**Author:** ![erni23](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@erni23](https://discuss.elastic.co/u/erni23)\
**Post date:** [December 13, 2023, 5:17pm UTC](https://discuss.elastic.co/t/correlating-matching-data-from-2-sources-with-diferent-field-types/349218/3 "2023-12-13T17:17:55Z")

</div>

Hi Ryland, thanks for the information. However,

1. This does not have to be a correlation event. I just want to be alerted when any of those events occur.

2. I tried creating the rule with "Authentication ( ```  
[authentication where event.outcome: "success" and event.action: "login]

```but

3) The fields that I have provided is just a place holder, it does not have to be authentication event. It could be hostname, ip, id etc

4) Finally, there is no relationship between those 2 sources. The badge logs is ingested via webhook. 

Thanks.
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 10, 2024, 5:18pm UTC](https://discuss.elastic.co/t/correlating-matching-data-from-2-sources-with-diferent-field-types/349218/4 "2024-01-10T17:18:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
