Splunk Dev

How to get the stderr from a python command launched by a SearchManager

RiccardoV
Communicator

Hi,
I have a dashboard like that:

<dashboard script="doSearch.js">
    <label>test query</label>
    <row>
    <html>ciao</html>
    </row>
</dashboard>

and the js file is the following, taken from the searchmanager reference:

require([
        'splunkjs/mvc',
        'splunkjs/mvc/utils',
        "splunkjs/mvc/searchmanager",
        "splunkjs/ready!"
    ], function (mvc) {
    var deps = [
        "splunkjs/ready!",

    ];
    require(deps, function (mvc) {
        var SearchManager = require("splunkjs/mvc/searchmanager");
        var mysearch = new SearchManager({
            id : "updatetthreatdb",
            search : "| script python test_command"
        });

        mysearch.on('search:failed', function (properties) {
            // Print the entire properties object
            console.log("FAILED:", properties);
        });

        mysearch.on('search:progress', function (properties) {      
            // Print just the event count from the search job
            console.log("IN PROGRESS.\nEvents so far:", properties.content.eventCount);
        });

        mysearch.on('search:done', function (properties) {
            // Print the search job properties
            console.log("DONE!\nSearch job properties:", properties.content);
        });

        mysearch.on('search:change', function(properties) {
        console.log(properties.content);
        });
    });
});

the python command launches is:

import sys
import time

sys.stderr.write("hi 1\r\n")
time.sleep(5)
sys.stderr.write("hi 2\r\n")
time.sleep(5)
sys.stderr.write("hi 3\r\n")
time.sleep(5)
sys.stderr.write("hi 4\r\n")
time.sleep(5)
sys.stderr.write("hi 5\r\n")

Is there a way to get (javascript side) the stderr messages printed by the script?
thanks a lot!

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

Basically the same way you are doing it to get results.

mysearch.on('search:error', function(err) {
    console.log(err);
    });

See the webframework documentation here:

http://docs.splunk.com/Documentation/WebFramework
0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

Hit me up on IRC, let's hash this out.

RiccardoV
Communicator

thanks for your answer.
I tried with your solution but I see no log on the console.
When the search is done I print the properties.content and I can see here the messages array with all my errors 😞

0 Karma
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 Certification at ...

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 ...