Splunk Search

How to write splunk Query to find all the occurrences of a Boolean key value pair in logs over a period of time

RemyaT
Explorer

Given below is a snippet of splunk event. My requirement is to find all the occurrences of "isOutstanding": true. Here the point to note is that one event may/may not have multiple occurrences. Need to find the total count from multiple events over a period of time.

{
  \"school\": {
    \"schoolId\": \"1\",
    \"schoolName\": \"SchoolX\",
    \"schoolType\": \"private\",
    \"students\": [
      {
        \"id\": \"1\",
        \"isOutstanding\": true,
        
      },
      {
        \"id\": \"2\",
        \"isOutstanding\": false,
        
      },
      {
        \"id\": \"3\",
        \"isOutstanding\": false,
        
      }
    ]
  }
}

The below Splunk query index=myIndex "isOutstanding":true gives the count of events having "isOutstanding": true. But it doesn't consider the count of multiple occurrences in one event. How can I get the count of all the occourences in an event? TIA

 

Labels (6)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Depending on whether your actual event has the backslashes, try this

| rex max_match=0 "(?<isOutstanding>isOutstanding\\\\\":\s+true)"
| eval count = mvcount(isOutstanding)
| stats sum(count) as total

RemyaT
Explorer

This was helpful but didn't exactly serve my requirement. Has to change a little bit for the final working query

| rex max_match=0 "(?<isOutstanding>isOutstanding\\\\\":true)"
|  stats count(isOutstanding) as total

 

richgalloway
SplunkTrust
SplunkTrust

Use rex to extract the 'isOutstanding' texts and mvcount to count them.

| rex max_match=0 "(?<isOutstanding>isOutstanding)"
| eval count = mvcount(isOutstanding)
---
If this reply helps you, Karma would be appreciated.
0 Karma

PickleRick
SplunkTrust
SplunkTrust

@richgalloway @ITWhisperer If I remember correctly, simple stats count over a single field takes into account mvfields.

Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...