Developing for Splunk Enterprise
Highlighted

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

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
Highlighted

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

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
Highlighted

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

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
Highlighted

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

SplunkTrust
SplunkTrust

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