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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...