Scripted Dashboards (.js)edit

Scripted dashboards are much more powerful than templated dashboards. Of course, with power comes responsibility, and scripted dashboards are more complex to build. The goal in a scripted dashboard is to build and return a javascript object that describes the dashboard schema. A well commented example scripted dashboard can be found in app/dashboards/logstash.js (on github). This file accomplishes the same goals as logstash.json, but with the added power of scripts we can do things like split queries on commas:

Note: Take careful note of the script part of #/dashboard/script/logstash.js. This instructs kibana to treat this file as javascript.

http://yourserver/index.html#/dashboard/script/logstash.js?query=status:403,status:404&from=7d

This will create 2 query objects, status:403 and status:404 and chart them seperately. In fact this dashboard takes another parameter that describes the string by which to split the query on: split

http://yourserver/index.html#/dashboard/script/logstash.js?query=status:403!status:404&from=7d&split=!

We can see this happening in logstash.js (on github) here:

// In this dashboard we let users pass queries as comma separated list to the query parameter.
// Or they can specify a split character using the split parameter
// If query is defined, split it into a list of query objects
// NOTE: ids must be integers, hence the parseInt()s
if(!_.isUndefined(ARGS.query)) {
  queries = _.object(_.map(ARGS.query.split(ARGS.split||','), function(v,k) {
    return [k,{
      query: v,
      id: parseInt(k,10),
      alias: v
    }];
  }));
} else {
  // No queries passed? Initialize a single query to match everything
  queries = {
    0: {
      query: '*',
      id: 0,
    }
  };
}

This dashboard takes more parameters than this, all of which are described in the comments at the top of logstash.js (on github)