Splunk Dev

Am I only allowed to yield results in the generate function?

klim
Path Finder

Is it only possible to yield results in the generate command? If I run the simple command below it only yields the "hello" message in the generate() function even though generate() calls generate2().

import sys, time
from splunklib.searchcommands import \
    dispatch, GeneratingCommand, Configuration, Option, validators

@Configuration()
class GenerateHelloCommand(GeneratingCommand):
    count = Option(require=True, validate=validators.Integer())

    def generate2(self):
        yield {'_time': time.time(), 'event_no': 2, '_raw': "hello 2"}

    def generate(self):
        self.generate2()
        yield {'_time': time.time(), 'event_no': 1, '_raw': "hello"}

dispatch(GenerateHelloCommand, sys.argv, sys.stdin, sys.stdout, __name__)

 

Labels (2)
0 Karma

livehybrid
Super Champion

I believe that the yield in generate2 is "yielded" to genetate, however this does not do anything with it,

instead, depending what you're trying to achieve, you may be able to do:

import sys, time
from splunklib.searchcommands import \
    dispatch, GeneratingCommand, Configuration, Option, validators

@Configuration()
class GenerateHelloCommand(GeneratingCommand):
    count = Option(require=True, validate=validators.Integer())

    def generate2(self):
        yield {'_time': time.time(), 'event_no': 2, '_raw': "hello 2"}

    def generate(self):
        yield self.generate2()
        yield {'_time': time.time(), 'event_no': 1, '_raw': "hello"}

dispatch(GenerateHelloCommand, sys.argv, sys.stdin, sys.stdout, __name__)

 

0 Karma
Get Updates on the Splunk Community!

Splunk App Dev Community Updates – What’s New and What’s Next

Welcome to your go-to roundup of everything happening in the Splunk App Dev Community! Whether you're building ...

The Latest Cisco Integrations With Splunk Platform!

Join us for an exciting tech talk where we’ll explore the latest integrations in Cisco + Splunk! We’ve ...

Enterprise Security Content Update (ESCU) | New Releases

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