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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...