---
title: Example Advanced EPL Rules
description: Example Advanced EPL RulesExample Advanced EPL Rules Following are the examples of Advanced ESA rules. Each example has multiple ways of implementing
---

[Skip to content](https://mydev.netwitness.com/knowledge-base/exampleadvancedeplrules#main-content)

![NW Logo](https://mydev.netwitness.com/hs-fs/hubfs/Portal-Partner%20Program/AssetFiles/NW%20Logo%20(2).png?width=180&height=32&name=NW%20Logo%20(2).png)

- [Home](https://mydev.netwitness.com/home)
- Integrations
  
  Show submenu for Integrations

    - [Netwitness Platform Integrations](https://mydev.netwitness.com/netwitnessplatformintegrations)
    - [Third Party Integrations](https://mydev.netwitness.com/thirdpartyintegrations)
- [Knowledge Center](https://mydev.netwitness.com/knowledge-base)
- Community
  
  Show submenu for Community

    - [Blogs](https://mydev.netwitness.com/netwitness-security-llc-blog)
    - Discussions
- Customers
  
  Show submenu for Customers

    - [Manage Products and Licenses](https://mydev.netwitness.com/nwportal)
    - Downloads
- Partners
  
  Show submenu for Partners

    - [Partner Program](https://mydev.netwitness.com/partner)
    - [Partner Resources](https://mydev.netwitness.com/partnerresources)
    - [Submit a New Deal Registration](https://mydev.netwitness.com/dealregistration)
    - [Become a Partner](https://mydev.netwitness.com/becomeapartner)
    - [Update Your Partner Locator Profile](https://www.netwitness.com/partner-locator/?utm_source=pardotnewsletter&utm_medium=email&utm_campaign=partner_march)
    - [NetWitness LinkedIn Partner Hub](https://linkedin.com/showcase/netwitnesspartners/)
- Education
  
  Show submenu for Education

    - [Instructor Led Training Schedule](https://mydev.netwitness.com/instructorledtrainingschedule)
    - [NetWitness Training Catalog](https://mydev.netwitness.com/netwitnesstrainingcatalog)
    - [Security Awareness Training](https://mydev.netwitness.com/securityawarenesstraining)
    - [New Product Readiness](https://mydev.netwitness.com/newproductreadiness)
    - [On-Demand Virtual Labs](https://mydev.netwitness.com/ondemandvirtuallabs)
    - [Additional Training Information](https://mydev.netwitness.com/additionaltraininginformation)
    - [Frequently Asked Questions](https://mydev.netwitness.com/educationfaq)
    - [Contact NetWitness Education Team](https://mydev.netwitness.com/contact-netwitness-education-team)
- Support
  
  Show submenu for Support

    - [Contact Support](https://mydev.netwitness.com/contact-support)
    - [Create a New Case](https://mydev.netwitness.com/create-support-case)
    - [View My Cases](https://mydev.netwitness.com/viewmycase)
    - [Product Version Life Cycle](https://mydev.netwitness.com/product-version-life-cycle)
    - [Warranty & Replacement Parts](https://mydev.netwitness.com/warranty-and-replacement-parts)
    - [Community Support Forum](https://mydev.netwitness.com/community-support-forum)
    - [Technical Support Guide](https://mydev.netwitness.com/technical-support-guide)

Open main navigation

Close main navigation

- [Home](https://mydev.netwitness.com/home)
- Integrations
  
  Show submenu for Integrations

    - [Netwitness Platform Integrations](https://mydev.netwitness.com/netwitnessplatformintegrations)
    - [Third Party Integrations](https://mydev.netwitness.com/thirdpartyintegrations)
- [Knowledge Center](https://mydev.netwitness.com/knowledge-base)
- Community
  
  Show submenu for Community

    - [Blogs](https://mydev.netwitness.com/netwitness-security-llc-blog)
    - Discussions
- Customers
  
  Show submenu for Customers

    - [Manage Products and Licenses](https://mydev.netwitness.com/nwportal)
    - Downloads
- Partners
  
  Show submenu for Partners

    - [Partner Program](https://mydev.netwitness.com/partner)
    - [Partner Resources](https://mydev.netwitness.com/partnerresources)
    - [Submit a New Deal Registration](https://mydev.netwitness.com/dealregistration)
    - [Become a Partner](https://mydev.netwitness.com/becomeapartner)
    - [Update Your Partner Locator Profile](https://www.netwitness.com/partner-locator/?utm_source=pardotnewsletter&utm_medium=email&utm_campaign=partner_march)
    - [NetWitness LinkedIn Partner Hub](https://linkedin.com/showcase/netwitnesspartners/)
- Education
  
  Show submenu for Education

    - [Instructor Led Training Schedule](https://mydev.netwitness.com/instructorledtrainingschedule)
    - [NetWitness Training Catalog](https://mydev.netwitness.com/netwitnesstrainingcatalog)
    - [Security Awareness Training](https://mydev.netwitness.com/securityawarenesstraining)
    - [New Product Readiness](https://mydev.netwitness.com/newproductreadiness)
    - [On-Demand Virtual Labs](https://mydev.netwitness.com/ondemandvirtuallabs)
    - [Additional Training Information](https://mydev.netwitness.com/additionaltraininginformation)
    - [Frequently Asked Questions](https://mydev.netwitness.com/educationfaq)
    - [Contact NetWitness Education Team](https://mydev.netwitness.com/contact-netwitness-education-team)
- Support
  
  Show submenu for Support

    - [Contact Support](https://mydev.netwitness.com/contact-support)
    - [Create a New Case](https://mydev.netwitness.com/create-support-case)
    - [View My Cases](https://mydev.netwitness.com/viewmycase)
    - [Product Version Life Cycle](https://mydev.netwitness.com/product-version-life-cycle)
    - [Warranty & Replacement Parts](https://mydev.netwitness.com/warranty-and-replacement-parts)
    - [Community Support Forum](https://mydev.netwitness.com/community-support-forum)
    - [Technical Support Guide](https://mydev.netwitness.com/technical-support-guide)

 How can we help you?

- There are no suggestions because the search field is empty.

1. [NetWitness Knowledge Base](https://mydev.netwitness.com/knowledge-base?hsLang=en)
2. [Documentation](https://mydev.netwitness.com/knowledge-base/documentation?hsLang=en)

April 6, 2026

# Example Advanced EPL Rules

## Example Advanced EPL RulesExample Advanced EPL Rules

Following are the examples of Advanced ESA rules. Each example has multiple ways of implementing the same use-case.

For best practices on writing advanced EPL rules, see [ESA Rule Writing Best Practices](https://community.netwitness.com/t5/netwitness-platform-threat/esa-rule-writing-best-practices/ta-p/677917).

## Example #1:Example #1:

Create a user account and delete the same user account in 300s. User information is stored in user\_src meta.

## EPL #1:EPL #1:

- **Column 1:** Rule Name
- **Column 2:** CreateAndDelete Useraccount1

- **Column 1:** Rule Description
- **Column 2:** Create a user account followed by an action to delete the same user account in 300 seconds.

- **Column 1:** Rule Code
- **Column 2:**
  
  @RSAAlert(oneInSeconds=0)  
  SELECT \* FROM Event(ec\_subject='User'  
   AND ec\_outcome='Success'  
   AND user\_src is NOT NULL  
   AND ec\_activity IN ('Create', 'Delete')  
   ).win:time(300 seconds)
  
  match\_recognize (partition by user\_src  
   ​ measures C as c, D as d  
   pattern (C D)  
   define  
   C as C.ec\_activity='Create' ,  
   D as D.ec\_activity='Delete');

- **Column 1:** Note
- **Column 2:** 
    - Filter events needed for pattern in given time frame. Filter conditions should be such that only required events are passed to match recognize function. In this case, they are create and delete user account Events. That is, Event(ec\_subject='User' AND ec\_outcome='Success' AND user\_src is NOT NULL AND ec\_activity IN ('Create', 'Delete')
    - Partition by creates buckets. In this case, Esper creates buckets per value of user\_src. And hence value of user\_src is common between both events.
    - Define the pattern you want. Right now it is set to Create Followed by Delete. You can do multiple creates followed by delete (C+ D). Pattern is very similar to regular expression.
    - Most efficient use case.
    - The ‘loose’ pattern match of (C+ D) will result in decreased performance. Unless you need to include all C events within the generated alert, keep the strict pattern match of (C D). See the Esper documentation for more details.

## EPL #2:EPL #2:

- **Column 1:** Rule Name
- **Column 2:** CreateAndDeleteUseraccount2

- **Column 1:** Rule Description
- **Column 2:** Create a user account followed by an action to delete the same user account in 300 seconds.

- **Column 1:** Rule Code
- **Column 2:**
  
  @RSAAlert(oneInSeconds=0)  
  SELECT \* from pattern\[every (a= Event(ec\_subject='User' AND ec\_outcome='Success' AND user\_dst is NOT NULL AND ec\_activity IN ('Create'))
  
   -\> 
  
  ( Event(ec\_subject='User' AND ec\_outcome='Success' AND user\_dst is NOT NULL AND ec\_activity IN ('Create') AND user\_src = a.user\_src)  
   ) )where timer:within(300 Sec) \];

- **Column 1:** Note
- **Column 2:** 
    - Lets say same user is created twice and deleted once in that order. Then the above pattern will fire 2 alerts.
    - A thread is created for every User creation.
    - There is no way to control threads. It is important to have time bounds and preferably small intervals.
    - If you do not need every first event to start a new thread and match with the subsequent second event, then add suppression syntax of @SuppressOverlappingMatches after the pattern keyword. See the Esper documentation for more details.

## Example #2:Example #2:

Detect pattern where user created followed by login by same user and user is deleted in end. In case of windows logs user info is stored in either user\_dst or user\_src depending on event.

user\_src(create) = user\_dst(Login) = user\_src(Delete)

## EPL #3:EPL #3:

- **Column 1:** Rule Name
- **Column 2:** CreateUserLoginandDeleteUser

- **Column 1:** Rule Description
- **Column 2:** Detect a pattern where a user creates a User account followed by login by the same user followed by deletion of the User account.

- **Column 1:** Rule Code
- **Column 2:**
  
  @RSAAlert(oneInSeconds=0)  
  SELECT \* FROM Event(ec\_subject='User'  
   and ec\_activity in ('Create','Logon','Delete')  
   and ec\_theme in ('UserGroup', 'Authentication')  
   and ec\_outcome='Success'  
   ).win:time(300 seconds)  
   match\_recognize (measures C as c, L as l, D as d  
   pattern (C L D)  
   define  
   C as C.ec\_activity = 'Create',  
   L as L.ec\_activity = 'Logon' AND L.user\_dst = C.user\_src,  
   D as D.ec\_activity = 'Delete' AND D.user\_src = C.user\_src  
   );

- **Column 1:** Note
- **Column 2:** 
    - Since user\_src/user\_dst is not common across all events we can't use partition. It will be 1 single bucket running 1 pattern at a time. For example, for user 1 and 2 if the stream of events are C1C2L1D1, C1L1C2D1, there will be no alert because C1 thread got reset by C2. Alert will be fired only if C1L1D1 are in order and no other event either from same user or other user falls in between.
    - Another solution would be to use Named Window and merge user\_dst and user\_src into single column and then run match recognize. (EPL #3).
    - Pattern can also be used. You might get more alerts than expected. (EPL #4).

## EPL #4: Using NamedWindows and match recognizeEPL #4: Using NamedWindows and match recognize

- **Column 1:** Rule Name
- **Column 2:** CreateUserLoginandDeleteUser

- **Column 1:** Rule Description
- **Column 2:** Detect a pattern where a user creates a User account followed by login by the same user followed by deletion of the User account.

- **Column 1:** Rule Code
- **Column 2:**
  
  @Name('NormalizedWindow')  
  create window FilteredEvents.win:time(300 sec)   
  (user String, ecactivity string, sessionid Long);
  
  @Name('UsersrcEvents')   
  Insert into FilteredEvents   
  select user\_src as user, ec\_activity as ecactivity, sessionid from Event(  
  ec\_subject='User' and ec\_activity in ('Create','Delete') and ec\_theme in ('UserGroup', 'Authentication') and ec\_outcome='Success' and user\_src is not null );
  
  @Name('UsrdstEvents')   
  Insert into FilteredEvents   
  select user\_dst as user, ec\_activity
  
  as ecactivity, sessionid from Event(  
  ec\_subject='User' and ec\_activity in (Logon’) and ec\_theme in ('UserGroup', 'Authentication') and ec\_outcome='Success' and user\_dst is not null   
  );
  
  @Name('Pattern')
  
  @RSAAlert(oneInSeconds=0, identifiers={"user"})

  select \* from FilteredEvents  
   ​ match\_recognize (
  
   partition by user
  
   measures C as c, L as l, D as d  
   pattern (C L+D)
  
   define   
  C as C.ecactivity= ‘Create’,
  
  L as L.ecactivity= ‘Logon’,  
   D as D.ecactivity=’Delete’  
   );

## EPL #5: Using Every @RSAAlert(identifiers={"user\_src"})EPL #5: Using Every @RSAAlert(identifiers={"user\_src"})

- **Column 1:** Rule Name
- **Column 2:** CreateUserLoginandDeleteUser

- **Column 1:** Rule Description
- **Column 2:**
  
  Detect a pattern where a user creates a User account followed by login by the same user followed by deletion of the User account.

- **Column 1:** Rule Code
- **Column 2:**
  
  SELECT a.time as time,a.ip\_src as ip\_src,a.user\_dst as user\_dst,a.ip\_dst as ip\_dst,a.alias\_host as alias\_host from pattern\[every (a=Event (ec\_subject='User' and ​ec\_activity='Create' and ec\_theme='UserGroup' and ec\_outcome='Success') -\> (Event(ec\_subject='User' and ec\_activity='Logon' and ec\_theme='Authentication' and user\_src=a.user\_dst) -\> b=Event(ec\_subject='User' and ec\_activity='Delete' and ec\_theme='UserGroup' and user\_dst=a.user\_dst))) where timer:within(300 sec)\];

## Example #3:Example #3:

Excessive login failures from same sourceIP.

## EPL #6: @RSAAlert(identifiers={"ip\_src"})EPL #6: @RSAAlert(identifiers={"ip\_src"})

- **Column 1:** Rule Name
- **Column 2:** ExcessLoginFailure

- **Column 1:** Rule Description
- **Column 2:** The same user tried logging in from the same Source IP and faced login failures.

- **Column 1:** Rule Code
- **Column 2:**
  
  @RSAAlert(oneInSeconds=0)  
   SELECT \* FROM Event ( ip\_src IS NOT NULL AND ec\_activity ='Logon'   
  AND ec\_outcome = 'Failure').win:time\_batch(300 seconds) GROUP BY   
  ip\_src HAVING COUNT(\*) = 10;

- **Column 1:** Note
- **Column 2:** 
    - Uses time \_batch: Looks at events in batches(tumbling window). Every event matching the filter criteria will be kept for the specified time window.
    - “GROUP BY” clause aggregates events within the data window by ip\_src and HAVING clause instructs a count of 10 events with the same ip\_src must occur within the time window.
    - One of the issues with tumbling windows is that events occurring towards the end of the batch might not lead to an alert.
  
  In the below sequence of events at t=301 even though 10 login failures occurred for the same login in the last 300 secs, there will be no alert because the batch of events was dropped at t=300.
  
    - Above problem can be resolved using win:time windows (EPL#7)instead of win:time\_length\_batch windows.
    - Outer group by is to control events when time elapses. Say you have 9 events at end of 60 secs, Esper engine will push those 9 events to listener. Group by and count will restrict it since count is not equal to 10.
    - Time and count can be modified as needed.
- **Column 3:** Time t
- **Column 4:** Login Failures for Specific Users
- **Column 5:** Alert
- **Column 6:** Time Batch
- **Column 7:** 0
- **Column 8:** 0
- **Column 9:** 0
- **Column 10:** 1
- **Column 11:** 295
- **Column 12:** 6
- **Column 13:** 0
- **Column 14:** 1
- **Column 15:** 299
- **Column 16:** 3
- **Column 17:** 0
- **Column 18:** 1
- **Column 19:** 301
- **Column 20:** 1
- **Column 21:** 0
- **Column 22:** 2
- **Column 23:** 420
- **Column 24:** 6
- **Column 25:** 0
- **Column 26:** 2
- **Column 27:** 550
- **Column 28:** 3
- **Column 29:** 0
- **Column 30:** 2
- **Column 31:** 600
- **Column 32:** 0
- **Column 33:** 0
- **Column 34:** 3
- **Column 35:** 720
- **Column 36:** 6
- **Column 37:** 0
- **Column 38:** 3
- **Column 39:** 850
- **Column 40:** 3
- **Column 41:** 0
- **Column 42:** 3
- **Column 43:** 900
- **Column 44:** 1
- **Column 45:** 1
- **Column 46:** 3 ends and 4 begins

- **Column 1:** Time t
- **Column 2:** Login Failures for Specific Users
- **Column 3:** Alert
- **Column 4:** Time Batch

- **Column 1:** 0
- **Column 2:** 0
- **Column 3:** 0
- **Column 4:** 1

- **Column 1:** 295
- **Column 2:** 6
- **Column 3:** 0
- **Column 4:** 1

- **Column 1:** 299
- **Column 2:** 3
- **Column 3:** 0
- **Column 4:** 1

- **Column 1:** 301
- **Column 2:** 1
- **Column 3:** 0
- **Column 4:** 2

- **Column 1:** 420
- **Column 2:** 6
- **Column 3:** 0
- **Column 4:** 2

- **Column 1:** 550
- **Column 2:** 3
- **Column 3:** 0
- **Column 4:** 2

- **Column 1:** 600
- **Column 2:** 0
- **Column 3:** 0
- **Column 4:** 3

- **Column 1:** 720
- **Column 2:** 6
- **Column 3:** 0
- **Column 4:** 3

- **Column 1:** 850
- **Column 2:** 3
- **Column 3:** 0
- **Column 4:** 3

- **Column 1:** 900
- **Column 2:** 1
- **Column 3:** 1
- **Column 4:** 3 ends and 4 begins

## EPL #7: @RSAAlert(identifiers={"ip\_src"})EPL #7: @RSAAlert(identifiers={"ip\_src"})

- **Column 1:** Rule Name
- **Column 2:** ExcessLoginFailure

- **Column 1:** Rule Description
- **Column 2:** The same user tried logging in from the same Source IP and faced login failures.

- **Column 1:** Rule Code
- **Column 2:**
  
  @RSAAlert(oneInSeconds=0)  
   SELECT \* FROM Event ( ip\_src IS NOT NULL AND ec\_activity ='Logon'   
  AND ec\_outcome = 'Failure').win:time(300 seconds) GROUP BY   
  ip\_src HAVING COUNT(\*) = 10;

- **Column 1:** Note
- **Column 2:** 
    - This is a sliding window and hence after an alert is fired for a set of events they can be used for another alert as well until time has passed.
    - If 10 events were involved in causing the alert only the last event will appear.
    - Events are not removed from the time window. You could use output rate limiting. See the Esper documentation for more details.

## Example #4:Example #4:

Multiple failed logins from multiple different users from same source to same destination, a single user from multiple different sources to same destination.

## EPL #8: using time\_batchEPL #8: using time\_batch

- **Column 1:** Rule Name
- **Column 2:** MultiplefailedLogins

- **Column 1:** Rule Description
- **Column 2:** There are multiple failed logins for the following cases:  
   \- From multiple users from same source to same destination.  
   \- Single user from multiple sources to the same destination.

- **Column 1:** Rule Code
- **Column 2:**
  
  @RSAAlert(oneInSeconds=0)  
  SELECT \* FROM Event (
  
  ec\_activity='Logon'
  
  AND ec\_outcome='Failure'
  
  AND ip\_src IS NOT NULL
  
  AND ip\_dst IS NOT NULL
  
  AND user\_dst IS NOT NULL
  
  )
  
  .win:time\_batch(300 seconds)
  
  group by ip\_src,ip\_dst
  
  having count(distinct user\_dst) \>= 5;

- **Column 1:** Note
- **Column 2:** 
    - ip.dst and ip.src are common across all events.
    - user\_dst is unique for all events.
    - Alert is fired when there are at least 5 different users try to login from same ip.src and ip.dst combination.

## Example #5:Example #5:

No Log traffic from a device in a given timeframe.

## EPL #9: using timer:intervalEPL #9: using timer:interval

- **Column 1:** Rule Name
- **Column 2:** NoLogTraffic

- **Column 1:** Rule Description
- **Column 2:** There is no log traffic observed from a device in a given time frame.

- **Column 1:** Rule Code
- **Column 2:**
  
  SELECT \* FROM pattern \[every a = Event(device\_ip IN ('10.0.0.0','10.0.0.1') AND medium = 32) -\> (timer:interval (3600 seconds) AND NOT Event(device\_ip = a.device\_ip AND device\_type = a.device\_type AND medium = 32))\];

- **Column 1:** Note
- **Column 2:** 
    - Rule only detects sudden loss of traffic. It won't alert if there is no traffic to begin with. You need at least 1 event for rule to alert.
    - List of device ip address or device hostnames as input. Only these systems will be tracked.
    - Time input is required. Alert is fired when time interval between events exceeds input time.

## Example #6:Example #6:

Multiple Failed Logins NOT followed by a Lockout event by the same user.

## EPL #10: using timer and LockoutEPL #10: using timer and Lockout

- **Column 1:** Rule Name
- **Column 2:** FailedloginswoLockout

- **Column 1:** Rule Description
- **Column 2:** There are multiple failed logins that are not followed by Lockout event by the same user.

- **Column 1:** Rule Code
- **Column 2:**
  
  `SELECT * FROM pattern [every-distinct(a.user_dst, a.device_ip, 1 msec) (a= Event(ec_activity='Logon' and ec_outcome='Failure' and user_dst IS NOT NULL) -> [2]( Event( device_ip =a.device_ip and ec_activity='Logon' and ec_outcome='Failure' and user_dst=a.user_dst)`
  
  `AND NOT Event( ( ec_activity='Logon' and ec_outcome='Success' and device_ip = a.device_ip and user_dst=a.user_dst) or (ec_activity='Lockout' and device_ip = a.device_ip and user_dst=a.user_dst))))`
  
  `where timer:within(60 seconds) -> (timer:interval(30 seconds) and not Event(device_ip=a.device_ip and user_dst=a.user_dst and ec_activity='Lockout')) ];`

- **Column 1:** Note
- **Column 2:** 
    - Above query detects the absence of a Lockout Event after the occurrence of 2 failed logins from same user.
    - The occurrence of the multiple failed logins are timed and are assumed to occur within a certain period of time. Also, in-practice the Lockout event is assumed to occur within a short time after the occurrence of the last failed login event because the threshold value of Failed logins per user is set in a given domain.
    - In current query, every distinct will suppress new thread for combination of user and device for 1 millisec.
    - Time allowed for 3 failed logins is 60 secs since 1st failed attempt. Wait period for lockout event to occur is 30 secs

## Example #7:Example #7:

Custom functions to perform LIKE and REGEX operations for ARRAY elements.

## EPL #11: @RSAAlert(oneInSeconds=0)EPL #11: @RSAAlert(oneInSeconds=0)

- **Column 1:** Rule Name
- **Column 2:** MatchLikeRegex

- **Column 1:** Rule Description

[![Netwitness Logo](https://mydev.netwitness.com/hs-fs/hubfs/Quote%20Template%20-%20NW%20Logo/Netwitness%20Logo.png?width=158&height=42&name=Netwitness%20Logo.png "Netwitness Logo")](https://mydev.netwitness.com/?hsLang=en)

<https://www.linkedin.com/company/netwitness-platform/> <https://www.youtube.com/@netwitness>

Copyright © 2026, NetWitness LLC. All rights reserved.

[NetWitness Platform](https://www.netwitness.com/)

[Acceptable Use Policy](https://www.netwitness.com/wp-content/uploads/Acceptable-Use-Policy-092022.pdf) [Privacy Statement](https://www.netwitness.com/wp-content/uploads/NetWitness-Privacy-Statement-07292024.pdf)

![NetWitness Logo](https://mydev.netwitness.com/hubfs/Portal-Partner%20Program/netwitness-logo-RGB-white%201.png)

[![LinkedIn](https://mydev.netwitness.com/hubfs/Portal-Partner%20Program/linkedin.png)](https://www.linkedin.com/company/netwitness-platform/) [![YouTube](https://mydev.netwitness.com/hubfs/Portal-Partner%20Program/Youtube.jpg)](https://www.youtube.com/@netwitness)

© 2026 NetWitness LLC. All rights reserved.