Yes, it is possible. But there is no direct way to implement this feature. Grafana allows dashboard API to create or update dashboards. You need to modify the default script dashboard object to adapt to this dashboard API as well as scripted dashboards.
Following is the default scripted dashboard:
'use strict';
var window, document, ARGS, $, jQuery, moment, kbn;
var dashboard = {
rows : [],
};
dashboard.title = 'Scripted Dashboard';
dashboard.time = {
from: "now-6h",
to: "now"
};
dashboard.rows.push({
title: 'Chart',
height: '300px',
panels: [
{
title: 'Events',
type: 'graph'
}]
});
return dashboard;
Modified script to achieve the purpose:
'use strict' ;
var window, document, ARGS, $, jQuery, moment, kbn;
var ScriptedDashboard= {
dashboard :{},
overwrite: true
};
/* Create a simple dashboard*/
function createDashboard(dashboard){
dashboard.title = 'Grafana Dashboard';
dashboard.time = {
from : "now-6h",
to : "now"
};
dashboard.id= null;
dashboard.uid= null;
}
function sendHTTPData(method, url, data){
var httpRequest = new XMLHttpRequest();
httpRequest.open( method,url , true);
httpRequest.setRequestHeader("Content-Type", "application/json");
httpRequest.setRequestHeader("Access-Control-Allow-Origin","*");
var reqData = JSON.stringify(data);
httpRequest.send(reqData);
}
createDashboard(ScriptedDashboard.dashboard);
sendHTTPData("POST", "http://192.168.0.104:3000/api/dashboards/db", ScriptedDashboard);
return ScriptedDashboard.dashboard;
See the difference between the above-scripted dashboards.