All Apps and Add-ons

How to edit my ldapsearch query to match identify information with a lookup?

kiran331
Builder

Hi

I'm using the below search to get the Identity information into Splunk. Now I have a lookup(critical_users.csv) with critical users. How can I match this lookup with the query to make priority "Critical" and Category "Critical users" and watchlist="true". In the lookup, I have userPrincipalName of the users.

| ldapsearch domain="XXXXXXX" search="(&(objectClass=user)(!(objectClass=computer)))" attrs="sAMAccountName,displayName,givenName,sn,mail,telephoneNumber,manager,department,whenCreated,accountExpires, userAccountControl, distinguishedName,userPrincipalName,employeeID"
|search userAccountControl="NORMAL_ACCOUNT"
|eval suffix=""
| eval priority=case(       like(distinguishedName,"%OU=Privileged Accounts,OU=AD_REFRESH,DC=XX,DC=XXXXXX,DC=com"), "critical",
                            like(distinguishedName,"%OU=USERS,OU=Disabled Accounts,DC=XX,DC=XXXXXX,DC=com"), "critical",
                            1==1,"medium" )
 | eval category=case(       like(distinguishedName,"%OU=Privileged Accounts,OU=AD_REFRESH,DC=XX,DC=XXXXXX,DC=com"), "privileged",
                            like(distinguishedName,"%OU=USERS,OU=Disabled Accounts,DC=XX,DC=XXXXXXX,DC=com"), "disabled",
                             1==1,"normal" )
|eval startDate = strptime(whenCreated,"%Y%m%d%H%M%S.%1NZ")
| eval endDate=if(accountExpires="(never)","",accountExpires)
|eval watchlist="false"
|eval identity =  sAMAccountName +"|"+userPrincipalName+"|"+ distinguishedName+"|"+employeeID 
|table userPrincipalName identity,personalTitle,displayName,givenName,sn,suffix,mail,telephoneNumber,mobile,manager,priority,department,category,watchlist,startDate,endDate
|rename personalTitle as prefix, displayName as nick, givenName as first, sn as last, mail as email, telephoneNumber as phone, mobile as phone2, manager as managedBy, department as bunit
| outputlookup create_empty=false "users.csv"
0 Karma
1 Solution

sundareshr
Legend

Try this

| ldapsearch domain="XXXXXXX" search="(&(objectClass=user)(!(objectClass=computer)))" attrs="sAMAccountName,displayName,givenName,sn,mail,telephoneNumber,manager,department,whenCreated,accountExpires, userAccountControl, distinguishedName,userPrincipalName,employeeID"
|search userAccountControl="NORMAL_ACCOUNT"
|eval suffix=""
| eval priority=case( like(distinguishedName,"%OU=Privileged Accounts,OU=AD_REFRESH,DC=XX,DC=XXXXXX,DC=com"), "critical",
like(distinguishedName,"%OU=USERS,OU=Disabled Accounts,DC=XX,DC=XXXXXX,DC=com"), "critical",
1==1,"medium" )
| eval category=case( like(distinguishedName,"%OU=Privileged Accounts,OU=AD_REFRESH,DC=XX,DC=XXXXXX,DC=com"), "privileged",
like(distinguishedName,"%OU=USERS,OU=Disabled Accounts,DC=XX,DC=XXXXXXX,DC=com"), "disabled",
1==1,"normal" )
|eval startDate = strptime(whenCreated,"%Y%m%d%H%M%S.%1NZ")
| eval endDate=if(accountExpires="(never)","",accountExpires)
|eval watchlist="false"
|eval identity = sAMAccountName +"|"+userPrincipalName+"|"+ distinguishedName+"|"+employeeID 
|table userPrincipalName identity,personalTitle,displayName,givenName,sn,suffix,mail,telephoneNumber,mobile,manager,priority,department,category,watchlist,startDate,endDate
|rename personalTitle as prefix, displayName as nick, givenName as first, sn as last, mail as email, telephoneNumber as phone, mobile as phone2, manager as managedBy, department as bunit
| lookup critical_users.csv userPrincipalName OUTPUT userPrincipalName AS cu 
| eval critical=if(isnotnull(cu), "Critical", critical)
| eval category=if(isnotnull(cu), "Critical Users", category)
| outputlookup create_empty=false "users.csv"

View solution in original post

sundareshr
Legend

Try this

| ldapsearch domain="XXXXXXX" search="(&(objectClass=user)(!(objectClass=computer)))" attrs="sAMAccountName,displayName,givenName,sn,mail,telephoneNumber,manager,department,whenCreated,accountExpires, userAccountControl, distinguishedName,userPrincipalName,employeeID"
|search userAccountControl="NORMAL_ACCOUNT"
|eval suffix=""
| eval priority=case( like(distinguishedName,"%OU=Privileged Accounts,OU=AD_REFRESH,DC=XX,DC=XXXXXX,DC=com"), "critical",
like(distinguishedName,"%OU=USERS,OU=Disabled Accounts,DC=XX,DC=XXXXXX,DC=com"), "critical",
1==1,"medium" )
| eval category=case( like(distinguishedName,"%OU=Privileged Accounts,OU=AD_REFRESH,DC=XX,DC=XXXXXX,DC=com"), "privileged",
like(distinguishedName,"%OU=USERS,OU=Disabled Accounts,DC=XX,DC=XXXXXXX,DC=com"), "disabled",
1==1,"normal" )
|eval startDate = strptime(whenCreated,"%Y%m%d%H%M%S.%1NZ")
| eval endDate=if(accountExpires="(never)","",accountExpires)
|eval watchlist="false"
|eval identity = sAMAccountName +"|"+userPrincipalName+"|"+ distinguishedName+"|"+employeeID 
|table userPrincipalName identity,personalTitle,displayName,givenName,sn,suffix,mail,telephoneNumber,mobile,manager,priority,department,category,watchlist,startDate,endDate
|rename personalTitle as prefix, displayName as nick, givenName as first, sn as last, mail as email, telephoneNumber as phone, mobile as phone2, manager as managedBy, department as bunit
| lookup critical_users.csv userPrincipalName OUTPUT userPrincipalName AS cu 
| eval critical=if(isnotnull(cu), "Critical", critical)
| eval category=if(isnotnull(cu), "Critical Users", category)
| outputlookup create_empty=false "users.csv"

kiran331
Builder

It worked.Thank you!

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...