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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...

Deep insights, no barriers: Splunk Observability Cloud Free Edition

As software delivery cycles continue to accelerate, observability shouldn’t be a luxury — it should be a ...

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...