I refactored your original search slightly using rename rather than eval, as there's no need to duplicate the fields. I also removed the dc() from the stats as it's not necessary - it can be done later because you are collecting values and is probably more optimal. index="okta" actor.alternateId=*@* authenticationContext.externalSessionId!="unknown"
| rename "securityContext.asNumber" as ASN,
"authenticationContext.externalSessionId" as "Session ID",
"actor.alternateId" as User
"debugContext.debugData.risk" as Risk
| stats values(user_agent) AS "User Agent" values(ASN) as ASN values(Risk) as Risk by User "Session ID"
| lookup asn_user.csv ASN User OUTPUT ASN as found_ASNs
``` Count the ASN's and Agents here and count the number of ASNs found
in the lookup and set a new field if there is a new ASN found not
seen before ```
| eval "ASN Count"=mvcount(ASN), "Agent Count"=mvcount('User Agent'),
hasNewASN=if('ASN Count'>mvcount(found_ASNs), 1, 0)
``` Do the where before the table ```
| where 'ASN Count' > 1 AND 'Agent Count' > 1 AND hasNewASN=1
| table "Session ID", ASN, "ASN Count", "User Agent", "Agent Count", User, Risk The lookup will lookup ALL the ASNs collected and return all those that are found, so to see if there is a new one, you can just compare the counts. Note that if there are more than 100 ASNs then a CSV will only return 100 - you can make a definition that will allow up to 1000, but if that is going to be an issue, then you will need to put the lookup BEFORE the stats and test for the found ASN and set a flag accordingly, e.g. ...
| lookup asn_user.csv ASN User OUTPUT ASN as found_ASN
| eval newASN=if(isnull(found_AS),1,0)
| stats sum(newASN) as newASNs values(user_agent) AS "User Agent" values(ASN) as ASN values(Risk) as Risk by User "Session ID"
... so you can then count the new ASNs for that user, but if you can do it after the stats, it will be more performant. Note field quoting rules. Field names need to be DOUBLE quoted when containing spaces or other odd characters when on left hand side of eval Field names need to be SINGLE quoted when containing spaces or other odd characters when on right hand side of eval Field names need to beDOUBLE quoted when containing spaces or other odd characters when in a stats aggregation
... View more