Splunk Search

Subsearch

RanjiRaje
Explorer

Hi everyone, My post is huge. sorry for that. I need suggestion from you for the query I framed.

I have 2 lookup used (lookfileA, lookfileB)

column: BaseA > count by division in lookupfileA
column: Column_IndexA > to compare lookfileA under indexA and get matching host count
column: BaseB > count by division in lookupfileB
column: Inscope > count by division in lookupfileB with Active status
column: Column_OtherIndexes > to compare lookfileB under otherindexes and get matching host count

index=indexA
| lookup lookfileA host as hostname OUTPUTNEW Division
| fields hostname,Division
| stats dc(hostname) as "Column_IndexA" by Division
| append
[| tstats count where index IN ("win","linux") by host
| eval host=upper(host)
| fields - count
| join type=inner host
[| inputlookup lookfileA
| fields host, Division
| eval host=upper(host)]
| stats count as "Column_OtherIndexes" by Division]
| append
[| inputlookup lookfileA
| stats count as "BaseA" by Division]
| append
[| inputlookup lookfileB
| stats count as BaseB by category
| where category IN ("Win","Linux")
| rename category as Division]
| append
[| inputlookup lookfileB
| stats count as Inscope by category,status
| where category IN ("Win","Linux") AND status="Active"
| rename category as Division]
| fields Division,BaseB,Inscope,"Column_OtherIndexes","BaseA","Column_IndexA"
| stats values(*) as * by Division
| table Division,BaseB,Inscope,"Column_OtherIndexes","BaseA","Column_IndexA"
| eval Difference="Column_IndexA" - "Column_OtherIndexes"
| fillnull value=0
| addtotals col=t row=f labelfield=Division label=Total

Below is the sample output and I need to get difference column. Used eval command but getting error

DivisionBaseBInscopeColumn_OtherIndexesBaseA Column_IndexADifference
M30020050300200200-50
N20010020300200200-20
Total50030070600400400-70
Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

What error did you get from the eval command?

I suspect eval is having a problem substracting one string constant from another.  Put the field names in single quotes rather than double quotes.  On the RHS, single quotes denote a field name and double quotes denote a string.  In fact, quotation marks are not needed at all with those names.

| eval Difference = 'Column_IndexA' - 'Column_OtherIndexes'

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

What error did you get from the eval command?

I suspect eval is having a problem substracting one string constant from another.  Put the field names in single quotes rather than double quotes.  On the RHS, single quotes denote a field name and double quotes denote a string.  In fact, quotation marks are not needed at all with those names.

| eval Difference = 'Column_IndexA' - 'Column_OtherIndexes'

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

RanjiRaje
Explorer

Thanks you so much for a quick help. I got the result as expected 🙂

Today I learned that single quotes denotes a field and double quotes denotes a string. Thanks a lot ...

0 Karma
Get Updates on the Splunk Community!

3 Ways to Make OpenTelemetry Even Better

My role as an Observability Specialist at Splunk provides me with the opportunity to work with customers of ...

What's New in Splunk Cloud Platform 9.2.2406?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2406 with many ...

Enterprise Security Content Update (ESCU) | New Releases

In August, the Splunk Threat Research Team had 3 releases of new security content via the Enterprise Security ...