I have a need to find a user(s) that have multiple infections over a 7 day period. Example would be user1 has an infection today, I need to go back 7 days to see if this user has had any other infections.
My thought was to run a subsearch for looking back 7 days to "today at midnight" and find user(s) that have an infection event. Then, run the same search for "today" (midnight to "now"), and if the user from the sub-search is found and only that user, alert. I want to combine or display all of the events from both searches.
Example would be:
user1 - events on: (4 events)12/10/2020, (1 event)12/16/2020
user2 - events on: 12/11/2020
user3 - events on 12/10/2020
Run the first search, past 7 days finds all of the above. The outer search will search for the last 60 minutes and find user1. I want to alert on and display the 5 events from user1.
This will generate an alert. Throttling will be done in the alert configs to remove duplicates.
Thanks as always.
@wtaylor149 Please try the search I posted, for you it would be. You can avoid sub-search by using below query.
index=av_logs sourcetype="av" "Risk_Action"="Virus found" earliest=-8d@d latest=now | bin span=1h _time|stats count by user Server_Name signature action _time| eval flag=if(_time>=now()-(3600*24), 1,0)|eventstats sum(flag) as flag by user| where flag > 0
Unfortunately that does not work either. I'm not sure, but this seems like something so easy. I just want to run a search for the past 60 minutes, take the user and other field/values and run the same search on 7 days ago and if that same user is found in the logs add those events to the subsearch results.
What is the output you are getting with that search. Also that is for last day and not in last 60 minutes. If you want to check if user was infected in last 60 min, please change span to span=1m instead of span=1h and also change now() - (3600 * 24) to now() - 3600. Also share the result once you update.
I didn't get any results from that search. The difficult thing is that these events are few and far between. One day I can see 10 events and then no events for 2 days. Sorry, I just don't understand why I'm not able to meld the two search results together in one result. Seems so simple.
@wtaylor149 you can do something like, I am considering userswho had an infection in last 7 days and also in last 1 hour. This search needs to run over last 7 days, in case you want to run for users who had infection in last 7 days and today change the time calculation accordingly.
<your search> |bin span=1m _time|stats count by user _time| eval flag=if(_time>=now()-3600, 1,0)|eventstats sum(flag) as flag by user| where flag > 0
Vijeta, Thanks for the reply. I'm not sure that search will work. I'm looking to run a search hourly, looking back one hour. The search is example below.
In this example my goal is to take the events found in the subsearch and display them along with the events found in the outer search. I've tried append, appendcols and join on user to get this to work but, depending on the command, I only get the results from the outer search and not both outer and inner search results. I could have sworn I've done this in the past, but nothing I've tried is working.
index=av_logs sourcetype="av" "Risk_Action"="Virus found" earliest=-1d@d latest=now
| stats count by user Server_Name signature action
[search index=av_logs sourcetype="av" "Risk_Action"="Virus found" earliest=-8d@d latest=-1d@d
| stats count as eventCount values(signature) as signature, values(Server_Name) as Server_Name, values(action) as action by _time user
| fields user signature Server_Name action]
| stats count by _time user Server_Name signature action