All Apps and Add-ons

Custom JSON Module wont do post processing

phoenixdigital
Builder

Hi All,

I followed the example provided below to build a custom module that passes JSON data through
http://dev.splunk.com/view/SP-CAAADXY

This was all well and good and worked perfectly however I found that it did not perform post processing. For example if I have the following AdvancedXML (on pastebin due to crap formatting ui)
http://pastebin.com/KEsGEEQK

Now you can see I have a post processing search occurring. However the example does not handle post processing.

So after much stuffing around I analysed the SimpleResultsTable.py to see how it did it. See %SPLUNK_HOME%/share/splunk/search_mrsparkle/modules/results/SimpleResultsTable.py

Now I ended up with this
http://pastebin.com/YfVsu9g7

However it still doesn't perform the post process and I get all the results for sectionCode instead of the single one I am running

where sectionCode="g01"

on.

Notice in my advancedXML I am also performing a simple table and it works perfectly and only shows the subset of data.

Is there somewhere else I need to code in postprocessing?

Tags (1)
1 Solution

phoenixdigital
Builder

Ok worked it out. I was missing a crucial part from the .js component

    getResultParams: function($super) {
      var params = $super(),
          context = this.getContext(),
          search = context.get("search"),
          sid = search.job.getSearchId(),
          postprocess = search.getPostProcess();

      if (!sid) this.logger.error(this.moduleType, "Assertion Failed.");

      params.sid = sid;    

      if (postprocess) 
          params.postprocess = postprocess;

      return params;
    },

Adding this initially didn't work however I realised my browser was probably caching this .js so I did a refresh while holding down shift and it started working again.

View solution in original post

phoenixdigital
Builder

Ok worked it out. I was missing a crucial part from the .js component

    getResultParams: function($super) {
      var params = $super(),
          context = this.getContext(),
          search = context.get("search"),
          sid = search.job.getSearchId(),
          postprocess = search.getPostProcess();

      if (!sid) this.logger.error(this.moduleType, "Assertion Failed.");

      params.sid = sid;    

      if (postprocess) 
          params.postprocess = postprocess;

      return params;
    },

Adding this initially didn't work however I realised my browser was probably caching this .js so I did a refresh while holding down shift and it started working again.

araitz
Splunk Employee
Splunk Employee

Great job figuring this out. For busting the cache, you can also hit http://localhost:8000/en-US/_bump and click the bump button.

0 Karma

phoenixdigital
Builder

On further investigation using firebug it appears some parameters are being tacked onto SimpleResultsTable that are not added to my custom one.

http://192.168.32.32:8000/en-GB/module/system/Splunk.Module.SimpleResultsTable/render?count=10&offse...

http://192.168.32.32:8000/en-GB/module/system/Splunk.Module.CustomJSONResults/render?sid=1363660167....

Where do these come from and how do I get these added to my custom script?

0 Karma

araitz
Splunk Employee
Splunk Employee

OOPS you already figured this out.

You can implement getResultParams() - http://dev.splunk.com/view/SP-CAAAD58:

getResultParams: function($super) {
    var params = $super();
    params.foo = 'bar';
    return params;
}

This will add &foo=bar to the query string of the request to your module controller. Note that the default implementation of getResultParams() (which is represented by $super) will populate host_app and client_app for you automagically.

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...