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!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...