This repository was archived by the owner on May 28, 2019. It is now read-only.
forked from anryko/grafana-influx-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetdash.js
60 lines (46 loc) · 1.5 KB
/
getdash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* global _ */
/*
* Complex scripted dashboard
* This script generates a dashboard object that Grafana can load. It also takes a number of user
* supplied URL parameters (int ARGS variable)
*/
// Accessable variables in this scope
var window, document, ARGS, $, jQuery, moment, kbn;
return function scriptedDashboard (callback) {
'use strict';
require(['app/getdash/getdash.app'], function getDahs (dash) {
// GET variables
var displayHost = '';
var displayMetric = '';
var displayTime;
var displaySpan = 12;
var async = true;
// sanitize :: String -> new String
var sanitize = function sanitize (str) {
return str.replace(/[^\w\s-,.*/]/gi, '');
};
if(!_.isUndefined(ARGS.host))
displayHost = sanitize(ARGS.host);
if(!_.isUndefined(ARGS.metric))
displayMetric = sanitize(ARGS.metric);
if(!_.isUndefined(ARGS.time))
displayTime = sanitize(ARGS.time);
if(!_.isUndefined(ARGS.span))
displaySpan = sanitize(ARGS.span);
if(!_.isUndefined(ARGS.async))
async = !!JSON.parse(ARGS.async.toLowerCase());
// Dashboard configuration
var dashConf = {
host: displayHost,
metric: displayMetric,
time: displayTime,
span: displaySpan,
async: async,
title: 'Scripted Dashboard for ' + displayHost,
// Series used to get the list of all hosts
// (Some metric that is common for all hosts).
defaultQueries: [ 'load_midterm' ]
};
dash.get(dashConf, callback);
});
};