Splunk Dev

Why my python Custom reporting command yields more than 1 statistics?

tqnmb97
Observer

Hi, so for the context, I'm developing a custom reporting command that will allow running a python ML script over the result of a search, and yield a prediction over all the records in the search result.

I've followed the template in https://github.com/splunk/splunk-app-examples/tree/master/custom_search_commands/python/reportingsea... to create such a command.

However, running this reportingcsc command (in my case, the command is `source="account202203.csv" | table date, new | reportingcsc cutoff=10 new`) over my dataset yields more than one statistics, while it's quite clear that the reduce method of this custom command would only yield one statistics over the search result.

 

 

 

def reduce(self, records):
        """returns a students count having a higher total marks than cutoff"""
        pass_student_cnt = 0
        for record in records:
            value = float(record["totalMarks"])
            if value >= float(self.cutoff):
                pass_student_cnt += 1
        yield {"student having total marks greater than cutoff ": pass_student_cnt}

 

 

 

It looks like the search result is binned into different chunks, and each chunk goes thru the reduce() method once. However, as a matter of fact, the search result aren't actually binned: If I simply do `source="account202203.csv" | table date, new | stats sum(new)` then it would only yield only 1 statistic.

Any suggestion to do this the right way would be greatly appreciated!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...