Skip to content

Instantly share code, notes, and snippets.

@mohamednizar
Created November 13, 2019 06:01
Show Gist options
  • Save mohamednizar/99da895b7db6971856054461dfdfb29c to your computer and use it in GitHub Desktop.
Save mohamednizar/99da895b7db6971856054461dfdfb29c to your computer and use it in GitHub Desktop.
Grafana Scripted dashboard , Render dashboard with logged user information
'use strict';
// accessible variables in this scope
var window, document, ARGS, $, jQuery, moment, kbn;
// Setup some variables
var dashboard;
// All url parameters are available via the ARGS object
var ARGS;
// Initialize a skeleton with nothing but a rows array and service object
dashboard = {
rows: [],
};
// Set default time
// time can be overridden in the url using from/to parameters, but this is
// handled automatically in grafana core during dashboard initialization
dashboard.time = {
from: "now-6h",
to: "now"
};
var rows = 1;
var seriesName = 'argName';
// You can get logged user's informations from this
var user = window.grafanaBootData.user
return function (callback) {
// Setup some variables
var dashboard;
// Initialize a skeleton with nothing but a rows array and service object
dashboard = {
rows: [],
services: {}
};
// Set a title
// dashboard.title = 'District Dashbord';
// Set default time
// time can be overridden in the url using from/to parameters, but this is
// handled automatically in grafana core during dashboard initialization
dashboard.time = {
from: "now-6h",
to: "now"
};
var rows = 1;
var seriesName = 'argName';
$.ajax({
method: 'GET',
// get the Dahbord from the application which you need to rendey ,
// currenlty this in support for internal org only , can't access an external dashbord
url: '/api/dashboards/uid/6CQ3Xj0Wk'
})
.done(function (result) {
// Do your hackes and changes
// when dashboard is composed call the callback
// function and pass the dashboard
callback(scynDashboard);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment