Commit 1095373a by Rashid Khan

Fixed interpanel communication

parent 834e63a1
...@@ -28,7 +28,6 @@ var config = new Settings( ...@@ -28,7 +28,6 @@ var config = new Settings(
elasticsearch: 'http://localhost:9200', elasticsearch: 'http://localhost:9200',
timeformat: 'mm/dd HH:MM:ss', timeformat: 'mm/dd HH:MM:ss',
timefield: '@timestamp', timefield: '@timestamp',
//indexpattern: '"logstash-"yyyy.mm.dd',
indexpattern: '"shakespeare"', indexpattern: '"shakespeare"',
modules: ['histogram','map','pie','table','stringquery','sort', modules: ['histogram','map','pie','table','stringquery','sort',
'timepicker'], 'timepicker'],
......
...@@ -9,8 +9,6 @@ var dashboards = ...@@ -9,8 +9,6 @@ var dashboards =
{ {
type : "stringquery", type : "stringquery",
span : 12, span : 12,
group : "main",
query : "wine"
} }
] ]
}, },
...@@ -23,18 +21,18 @@ var dashboards = ...@@ -23,18 +21,18 @@ var dashboards =
type : "timepicker", type : "timepicker",
span : 5, span : 5,
mode : 'relative', mode : 'relative',
index : "\"shakespeare\"",
refresh : { refresh : {
enable : false, enable : false,
interval: 30, interval: 30,
min : 10 min : 10
}, },
timespan: '1h', timespan : '1h',
group : "main" timefield: '@timestamp',
}, },
{ {
type : "sort", type : "sort",
span : 4, span : 4,
group : "main"
} }
] ]
}, },
...@@ -47,14 +45,13 @@ var dashboards = ...@@ -47,14 +45,13 @@ var dashboards =
title : "Monkey Shakespeare Lines", title : "Monkey Shakespeare Lines",
type : "histogram", type : "histogram",
span : 6, span : 6,
show : ['lines','points'], show : ['lines'],
fill : 0, fill : 0.3,
query : [ query : [
{ label : "Query", query : "*", color: '#86B32D' }, { label : "Query", query : "*", color: '#86B32D' },
{ label : "Hamlet", query : "play_name:Hamlet" }, { label : "Hamlet", query : "play_name:Hamlet" },
{ label : "Macbeth", query : "play_name:macbeth" }, { label : "Macbeth", query : "play_name:macbeth" },
], ],
group : "main"
}, },
{ {
title : "Monkey Typists Worldwide", title : "Monkey Typists Worldwide",
...@@ -64,8 +61,6 @@ var dashboards = ...@@ -64,8 +61,6 @@ var dashboards =
span : 6, span : 6,
size : 500, size : 500,
query : "*", query : "*",
group : "main"
} }
] ]
}, },
...@@ -83,7 +78,6 @@ var dashboards = ...@@ -83,7 +78,6 @@ var dashboards =
field : 'country', field : 'country',
//query : { query: "*", field: "country"} //query : { query: "*", field: "country"}
query : { field : "play_name", query : "*" }, query : { field : "play_name", query : "*" },
group : "main"
}, },
{ {
title : "Newest Lines", title : "Newest Lines",
...@@ -91,7 +85,6 @@ var dashboards = ...@@ -91,7 +85,6 @@ var dashboards =
span : 8, span : 8,
query : "*", query : "*",
fields : ['@timestamp','play_name','speaker','text_entry'], fields : ['@timestamp','play_name','speaker','text_entry'],
group : "main"
} }
] ]
} }
......
...@@ -8,6 +8,8 @@ angular.module('kibana.controllers', []) ...@@ -8,6 +8,8 @@ angular.module('kibana.controllers', [])
$scope.config = config; $scope.config = config;
$scope.dashboards = dashboards $scope.dashboards = dashboards
/*
$scope.timespan = config.timespan $scope.timespan = config.timespan
$scope.time = { $scope.time = {
from : time_ago($scope.timespan), from : time_ago($scope.timespan),
...@@ -46,6 +48,7 @@ angular.module('kibana.controllers', []) ...@@ -46,6 +48,7 @@ angular.module('kibana.controllers', [])
$scope.index = p.join(); $scope.index = p.join();
}); });
}); });
*/
// point to your ElasticSearch server // point to your ElasticSearch server
var ejs = $scope.ejs = ejsResource(config.elasticsearch); var ejs = $scope.ejs = ejsResource(config.elasticsearch);
......
angular.module('kibana.histogram', []) angular.module('kibana.histogram', [])
.controller('histogram', function($scope, $rootScope) { .controller('histogram', function($scope, $rootScope) {
var _id = _.uniqueId();
// Set and populate defaults // Set and populate defaults
var _d = { var _d = {
query : "*", query : "*",
...@@ -8,25 +10,34 @@ angular.module('kibana.histogram', []) ...@@ -8,25 +10,34 @@ angular.module('kibana.histogram', [])
color : "#27508C", color : "#27508C",
show : ['bars'], show : ['bars'],
fill : false, fill : false,
group : "default",
}
_.defaults($scope.panel,_d)
$scope.init = function() {
$scope.$on(_id+"-time", function(event,time){set_time(time)});
$scope.$on($scope.panel.group+"-time", function(event,time){set_time(time)});
$scope.$on($scope.panel.group+"-query", function(event, query) {
$scope.panel.query[0].query = query;
$scope.get_data();
});
// Now that we're all setup, request the time from our group
$rootScope.$broadcast($scope.panel.group+"-get_time",_id)
} }
_.each(_d, function(v, k) {
$scope.panel[k] = _.isUndefined($scope.panel[k])
? _d[k] : $scope.panel[k];
});
$scope.get_data = function() { $scope.get_data = function() {
// Make sure we have everything for the request to complete // Make sure we have everything for the request to complete
if(_.isUndefined($scope.panel.time)) if(_.isUndefined($scope.panel.index) || _.isUndefined($scope.panel.time))
return return
var request = $scope.ejs.Request().indices($scope.index); var request = $scope.ejs.Request().indices($scope.panel.index);
// Build the question part of the query // Build the question part of the query
var queries = []; var queries = [];
_.each($scope.panel.query, function(v) { _.each($scope.panel.query, function(v) {
queries.push($scope.ejs.FilteredQuery( queries.push($scope.ejs.FilteredQuery(
ejs.QueryStringQuery(v.query || '*'), ejs.QueryStringQuery(v.query || '*'),
ejs.RangeFilter(config.timefield) ejs.RangeFilter($scope.panel.time.field)
.from($scope.panel.time.from) .from($scope.panel.time.from)
.to($scope.panel.time.to) .to($scope.panel.time.to)
.cache(false)) .cache(false))
...@@ -37,7 +48,7 @@ angular.module('kibana.histogram', []) ...@@ -37,7 +48,7 @@ angular.module('kibana.histogram', [])
_.each(queries, function(v) { _.each(queries, function(v) {
request = request request = request
.facet($scope.ejs.DateHistogramFacet(_.indexOf(queries,v)) .facet($scope.ejs.DateHistogramFacet(_.indexOf(queries,v))
.field(config.timefield) .field($scope.panel.time.field)
.interval($scope.panel.interval) .interval($scope.panel.interval)
.facetFilter($scope.ejs.QueryFilter(v)) .facetFilter($scope.ejs.QueryFilter(v))
).size(0) ).size(0)
...@@ -49,19 +60,20 @@ angular.module('kibana.histogram', []) ...@@ -49,19 +60,20 @@ angular.module('kibana.histogram', [])
// Populate scope when we have results // Populate scope when we have results
results.then(function(results) { results.then(function(results) {
$scope.hits = results.hits.total; $scope.hits = results.hits.total;
// Null values at each end of the time range make sure we see entire range
$scope.data = []; $scope.data = [];
_.each(results.facets, function(v, k) { _.each(results.facets, function(v, k) {
var series = {}; // Null values at each end of the time range ensure we see entire range
var data = [[$scope.panel.time.from.getTime(), null]]; var data = [[$scope.panel.time.from.getTime(), null]];
_.each(v.entries, function(v, k) { _.each(v.entries, function(v, k) {
data.push([v['time'],v['count']]) data.push([v['time'],v['count']])
}); });
data.push([$scope.panel.time.to.getTime(), null]) data.push([$scope.panel.time.to.getTime(), null])
series.data = {
var series = { data: {
label: $scope.panel.query[k].label, label: $scope.panel.query[k].label,
data: data, data: data,
}; }};
if (!(_.isUndefined($scope.panel.query[k].color))) if (!(_.isUndefined($scope.panel.query[k].color)))
series.data.color = $scope.panel.query[k].color; series.data.color = $scope.panel.query[k].color;
$scope.data.push(series.data) $scope.data.push(series.data)
...@@ -69,22 +81,16 @@ angular.module('kibana.histogram', []) ...@@ -69,22 +81,16 @@ angular.module('kibana.histogram', [])
}); });
} }
if (!(_.isUndefined($scope.panel.group))) { function set_time(time) {
$scope.$on($scope.panel.group+"-query", function(event, query) { $scope.panel.time = time;
$scope.panel.query[0].query = query; $scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
$scope.get_data(); $scope.panel.interval = secondsToHms(
}); calculate_interval(time.from,time.to,50,0)/1000),
$scope.$on($scope.panel.group+"-time", function(event, time) { $scope.get_data();
$scope.panel.time = time;
$scope.panel.interval = secondsToHms(
calculate_interval(time.from,time.to,50,0)/1000),
$scope.get_data();
});
} }
// Now that we're all setup, request the time from our group // Ready, init
$rootScope.$broadcast($scope.panel.group+"-get_time") $scope.init();
}) })
.directive('histogram', function() { .directive('histogram', function() {
......
angular.module('kibana.map', []) angular.module('kibana.map', [])
.controller('map', function($scope, $rootScope) { .controller('map', function($scope, $rootScope) {
var _id = _.uniqueId();
// Set and populate defaults // Set and populate defaults
var _d = { var _d = {
query : "*", query : "*",
map : "world", map : "world",
colors : ['#C8EEFF', '#0071A4'], colors : ['#C8EEFF', '#0071A4'],
size : 100, size : 100,
exclude : [] exclude : [],
group : "default",
}
_.defaults($scope.panel,_d)
$scope.init = function() {
$scope.$on(_id+"-time", function(event,time){set_time(time)});
$scope.$on($scope.panel.group+"-time", function(event,time){set_time(time)});
$scope.$on($scope.panel.group+"-query", function(event, query) {
$scope.panel.query = query;
$scope.get_data();
});
// Now that we're all setup, request the time from our group
$rootScope.$broadcast($scope.panel.group+"-get_time",_id)
} }
_.each(_d, function(v, k) {
$scope.panel[k] = _.isUndefined($scope.panel[k])
? _d[k] : $scope.panel[k];
});
$scope.get_data = function() { $scope.get_data = function() {
// Make sure we have everything for the request to complete // Make sure we have everything for the request to complete
if(_.isUndefined($scope.panel.time)) if(_.isUndefined($scope.panel.index) || _.isUndefined($scope.panel.time))
return return
var request = $scope.ejs.Request().indices($scope.index); var request = $scope.ejs.Request().indices($scope.panel.index);
// Then the insert into facet and make the request // Then the insert into facet and make the request
var results = request var results = request
...@@ -47,19 +58,13 @@ angular.module('kibana.map', []) ...@@ -47,19 +58,13 @@ angular.module('kibana.map', [])
}); });
} }
if (!(_.isUndefined($scope.panel.group))) { function set_time(time) {
$scope.$on($scope.panel.group+"-query", function(event, query) { $scope.panel.time = time;
$scope.panel.query = query; $scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
$scope.get_data(); $scope.get_data();
});
$scope.$on($scope.panel.group+"-time", function(event, time) {
$scope.panel.time = time;
$scope.get_data();
});
} }
// Now that we're all setup, request the time from our group $scope.init()
$rootScope.$broadcast($scope.panel.group+"-get_time")
}) })
.directive('map', function() { .directive('map', function() {
...@@ -81,7 +86,6 @@ angular.module('kibana.map', []) ...@@ -81,7 +86,6 @@ angular.module('kibana.map', [])
}); });
function render_panel(scope,elem,attrs) { function render_panel(scope,elem,attrs) {
// Using LABjs, wait until all scripts are loaded before rendering panel // Using LABjs, wait until all scripts are loaded before rendering panel
var scripts = $LAB.script("common/lib/panels/jquery.jvectormap.min.js") var scripts = $LAB.script("common/lib/panels/jquery.jvectormap.min.js")
.script("common/lib/panels/map."+scope.panel.map+".js") .script("common/lib/panels/map."+scope.panel.map+".js")
......
...@@ -4,6 +4,8 @@ labjs = labjs.script("common/lib/panels/jquery.flot.js") ...@@ -4,6 +4,8 @@ labjs = labjs.script("common/lib/panels/jquery.flot.js")
angular.module('kibana.pie', []) angular.module('kibana.pie', [])
.controller('pie', function($scope, $rootScope) { .controller('pie', function($scope, $rootScope) {
var _id = _.uniqueId();
// Set and populate defaults // Set and populate defaults
var _d = { var _d = {
query : "*", query : "*",
...@@ -12,24 +14,29 @@ angular.module('kibana.pie', []) ...@@ -12,24 +14,29 @@ angular.module('kibana.pie', [])
donut : false, donut : false,
tilt : false, tilt : false,
legend : true, legend : true,
group : "default"
} }
_.each(_d, function(v, k) { _.defaults($scope.panel,_d)
$scope.panel[k] = _.isUndefined($scope.panel[k])
? _d[k] : $scope.panel[k]; $scope.init = function() {
}); $scope.$on(_id+"-time", function(event,time){set_time(time)});
$scope.$on($scope.panel.group+"-time", function(event,time){set_time(time)});
if (!(_.isUndefined($scope.panel.group)) && !(_.isArray($scope.panel.query))) { if(!(_.isArray($scope.panel.query))) {
$scope.$on($scope.panel.group+"-query", function(event, query) { $scope.$on($scope.panel.group+"-query", function(event, query) {
$scope.panel.query.query = query; $scope.panel.query.query = query;
$scope.get_data(); $scope.get_data();
}); });
}
// Now that we're all setup, request the time from our group
$rootScope.$broadcast($scope.panel.group+"-get_time",_id)
} }
$scope.get_data = function() { $scope.get_data = function() {
if(_.isUndefined($scope.panel.time)) // Make sure we have everything for the request to complete
if(_.isUndefined($scope.panel.index) || _.isUndefined($scope.panel.time))
return return
var request = $scope.ejs.Request().indices($scope.index); var request = $scope.ejs.Request().indices($scope.panel.index);
// If we have an array, use query facet // If we have an array, use query facet
if(_.isArray($scope.panel.query)) { if(_.isArray($scope.panel.query)) {
...@@ -103,19 +110,14 @@ angular.module('kibana.pie', []) ...@@ -103,19 +110,14 @@ angular.module('kibana.pie', [])
} }
} }
if (!(_.isUndefined($scope.panel.group))) { function set_time(time) {
$scope.$on($scope.panel.group+"-query", function(event, query) { $scope.panel.time = time;
$scope.panel.query.query = query; $scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
$scope.get_data(); $scope.get_data();
});
$scope.$on($scope.panel.group+"-time", function(event, time) {
$scope.panel.time = time;
$scope.get_data();
});
} }
// Now that we're all setup, request the time from our group // Ready, init
$rootScope.$broadcast($scope.panel.group+"-get_time") $scope.init()
}) })
.directive('pie', function() { .directive('pie', function() {
......
angular.module('kibana.sort', []) angular.module('kibana.sort', [])
.controller('sort', function($scope, $rootScope) { .controller('sort', function($scope, $rootScope) {
var _id = _.uniqueId();
// Set and populate defaults // Set and populate defaults
var _d = { var _d = {
label : "Sort", label : "Sort",
query : "*", query : "*",
size : 100, size : 100,
sort : [config.timefield,'desc'], sort : [config.timefield,'desc'],
group : "default"
}
_.defaults($scope.panel,_d);
$scope.init = function() {
$scope.fields = [];
$scope.$on($scope.panel.group+"-fields", function(event, fields) {
$scope.panel.sort = fields.sort;
$scope.fields = _.union(fields.all,$scope.fields);
});
} }
_.each(_d, function(v, k) {
$scope.panel[k] = _.isUndefined($scope.panel[k])
? _d[k] : $scope.panel[k];
});
$scope.toggle_sort = function() { $scope.toggle_sort = function() {
$scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc'; $scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
} }
$scope.init();
$scope.fields = [];
$scope.$on($scope.panel.group+"-fields", function(event, fields) {
$scope.panel.sort = fields.sort;
$scope.fields = _.union(fields.all,$scope.fields);
});
}) })
\ No newline at end of file
angular.module('kibana.stringquery', []) angular.module('kibana.stringquery', [])
.controller('stringquery', function($scope, $rootScope) { .controller('stringquery', function($scope, $rootScope) {
var _id = _.uniqueId();
// Set and populate defaults // Set and populate defaults
var _d = { var _d = {
label : "Search", label : "Search",
query : "*", query : "*",
size : 100, size : 100,
sort : [config.timefield,'desc'], sort : [config.timefield,'desc'],
group : "default"
} }
_.each(_d, function(v, k) { _.defaults($scope.panel,_d);
$scope.panel[k] = _.isUndefined($scope.panel[k])
? _d[k] : $scope.panel[k];
});
if (!(_.isUndefined($scope.panel.group))) { $scope.init = function() {
$scope.send_query = function(query) { $scope.send_query = function(query) {
$rootScope.$broadcast($scope.panel.group+"-query", query) $rootScope.$broadcast($scope.panel.group+"-query", query)
} }
} }
}) $scope.init();
\ No newline at end of file });
\ No newline at end of file
angular.module('kibana.table', []) angular.module('kibana.table', [])
.controller('table', function($scope, $rootScope, $location) { .controller('table', function($scope, $rootScope, $location) {
var _id = _.uniqueId();
// Set and populate defaults // Set and populate defaults
var _d = { var _d = {
query : "*", query : "*",
size : 100, size : 100,
sort : [config.timefield,'desc'], sort : ['@timestamp','desc'],
group : "default",
}
_.defaults($scope.panel,_d)
$scope.init = function () {
$scope.$on(_id+"-time", function(event,time){set_time(time)});
$scope.$on($scope.panel.group+"-time", function(event,time){set_time(time)});
$scope.$on($scope.panel.group+"-query", function(event, query) {
$scope.panel.query = query;
$scope.get_data();
});
$scope.$watch(function() {
return angular.toJson($scope.panel.sort)
}, function(){$scope.get_data()});
// Now that we're all setup, request the time from our group
$rootScope.$broadcast($scope.panel.group+"-get_time",_id)
} }
_.each(_d, function(v, k) {
$scope.panel[k] = _.isUndefined($scope.panel[k])
? _d[k] : $scope.panel[k];
});
$scope.toggle_sort = function() { $scope.toggle_sort = function() {
$scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc'; $scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
...@@ -18,10 +32,10 @@ angular.module('kibana.table', []) ...@@ -18,10 +32,10 @@ angular.module('kibana.table', [])
$scope.get_data = function() { $scope.get_data = function() {
// Make sure we have everything for the request to complete // Make sure we have everything for the request to complete
if(_.isUndefined($scope.panel.time)) if(_.isUndefined($scope.panel.index) || _.isUndefined($scope.panel.time))
return return
var request = $scope.ejs.Request().indices($scope.index); var request = $scope.ejs.Request().indices($scope.panel.index);
var results = request var results = request
.query(ejs.FilteredQuery( .query(ejs.FilteredQuery(
...@@ -58,22 +72,12 @@ angular.module('kibana.table', []) ...@@ -58,22 +72,12 @@ angular.module('kibana.table', [])
}); });
} }
$scope.$watch(function() { function set_time(time) {
return angular.toJson($scope.panel.sort) $scope.panel.time = time;
}, function(){$scope.get_data()}); $scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
$scope.get_data();
if (!(_.isUndefined($scope.panel.group))) {
$scope.$on($scope.panel.group+"-query", function(event, query) {
$scope.panel.query = query;
$scope.get_data();
});
$scope.$on($scope.panel.group+"-time", function(event, time) {
$scope.panel.time = time;
$scope.get_data();
});
} }
// Now that we're all setup, request the time from our group $scope.init();
$rootScope.$broadcast($scope.panel.group+"-get_time")
}) })
/*
## Timepicker
The timepicker panel is used to select time ranges and inform other panel of
them. It also handles searching for indices that match the given time range and
a pattern
### Parameters
* mode :: The default mode of the panel. Options: 'relative', 'absolute' 'since' Default: 'relative'
* time_options :: An array of possible time options. Default: ['5m','15m','1h','6h','12h','24h','2d','7d','30d']
* timespan :: The default options selected for the relative view. Default: '15m'
* timefield :: The field in which time is stored in the document.
* index :: Index pattern to match. Literals should be double quoted. Default: '"logstash-"yyyy.mm.dd'
* refresh: Object containing refresh parameters
* enable :: true/false, enable auto refresh by default. Default: false
* interval :: Seconds between auto refresh. Default: 30
* min :: The lowest interval a user may set
### Group Events
#### Sends
* time :: Object Includes from, to and index
#### Receives
* get_time :: Receives an object containing a uniqueid, broadcasts to it.
*/
angular.module('kibana.timepicker', []) angular.module('kibana.timepicker', [])
.controller('timepicker', function($scope, $rootScope, $timeout) { .controller('timepicker', function($scope, $rootScope, $timeout, $http) {
var _id = _.uniqueId();
// Set and populate defaults // Set and populate defaults
var _d = { var _d = {
mode : "relative", mode : "relative",
time_options : ['5m','15m','1h','6h','12h','24h','2d','7d','30d'], time_options : ['5m','15m','1h','6h','12h','24h','2d','7d','30d'],
timespan : '15m', timespan : '15m',
refresh : { index : '"logstash-"yyyy.mm.dd',
enable: false, group : "default",
interval: 3, refresh : {
min: 3 enable : false,
}, interval: 30,
time : { min : 3
from : $scope.time.from,
to : $scope.time.to
} }
} }
_.each(_d, function(v, k) { _.defaults($scope.panel,_d)
$scope.panel[k] = _.isUndefined($scope.panel[k])
? _d[k] : $scope.panel[k]; $scope.init = function() {
}); // Private refresh interval that we can use for view display without causing
// unnecessary refreshes during changes
// Private refresh interval that we can use for view display without causing $scope.refresh_interval = $scope.panel.refresh.interval
// unnecessary refreshes during changes
$scope.refresh_interval = $scope.panel.refresh.interval // Init a private time object with Date() objects depending on mode
switch($scope.panel.mode) {
// Init a private time object with Date() objects depending on mode case 'absolute':
switch($scope.panel.mode) { $scope.time = {
case 'absolute': from : Date.parse($scope.panel.time.from),
$scope.time = { to : Date.parse($scope.panel.time.to)
from : Date.parse($scope.panel.time.from), }
to : Date.parse($scope.panel.time.to) break;
} case 'since':
break; $scope.time = {
case 'since': from : Date.parse($scope.panel.time.from),
$scope.time = { to : new Date()
from : Date.parse($scope.panel.time.from), }
to : new Date() break;
} case 'relative':
break; $scope.time = {
case 'relative': from : time_ago($scope.panel.timespan),
$scope.time = { to : new Date()
from : time_ago($scope.panel.timespan), }
to : new Date() break;
} }
break; $scope.time.field = $scope.panel.timefield;
} $scope.time_apply();
// Init the values for the time/date pickers // In the case that a panel is not ready to receive a time event, it may
$scope.timepicker = { // request one be sent by broadcasting a 'get_time' with its _id to its group
from : { $scope.$on($scope.panel.group+"-get_time", function(event,id) {
time : $scope.time.from.format("HH:MM:ss"), console.log('time request: '+id)
date : $scope.time.from.format("mm/dd/yyyy") $rootScope.$broadcast(id+"-time", $scope.time)
},
to : {
time : $scope.time.to.format("HH:MM:ss"),
date : $scope.time.to.format("mm/dd/yyyy")
}
}
// In the case that a panel is not ready to receive a time event, it may
// request one be sent by broadcasting a 'get_time' even to its group
if (!(_.isUndefined($scope.panel.group))) {
// Broadcast time when initializing
$rootScope.$broadcast($scope.panel.group+"-time", $scope.time)
// And whenever it is requested
$scope.$on($scope.panel.group+"-get_time", function(event) {
$rootScope.$broadcast($scope.panel.group+"-time", $scope.time)
}); });
}
$scope.$watch('panel.refresh.enable', function() {$scope.refresh()});
$scope.$watch('panel.refresh.enable', function() {$scope.refresh()}); $scope.$watch('panel.refresh.interval', function() {
$scope.$watch('panel.refresh.interval', function() { $timeout(function(){
$timeout(function(){ if(_.isNumber($scope.panel.refresh.interval)) {
if(_.isNumber($scope.panel.refresh.interval)) { if($scope.panel.refresh.interval < $scope.panel.refresh.min) {
if($scope.panel.refresh.interval < $scope.panel.refresh.min) { $scope.panel.refresh.interval = $scope.panel.refresh.min
$scope.panel.refresh.interval = $scope.panel.refresh.min $timeout.cancel($scope.panel.refresh.timer)
return;
}
$timeout.cancel($scope.panel.refresh.timer)
$scope.refresh()
} else {
$timeout.cancel($scope.panel.refresh.timer) $timeout.cancel($scope.panel.refresh.timer)
return;
} }
$timeout.cancel($scope.panel.refresh.timer) });
$scope.refresh()
} else {
$timeout.cancel($scope.panel.refresh.timer)
}
}); });
}); }
$scope.refresh = function() { $scope.refresh = function() {
if ($scope.panel.refresh.enable) { if ($scope.panel.refresh.enable) {
...@@ -145,24 +153,67 @@ angular.module('kibana.timepicker', []) ...@@ -145,24 +153,67 @@ angular.module('kibana.timepicker', [])
} }
} }
}); });
}
$scope.time_apply = function() { return {
$scope.time_check(); from : from,
// Update internal time object to : to
$scope.time = {
from : Date.parse($scope.timepicker.from.date + " " + $scope.timepicker.from.time),
to : Date.parse($scope.timepicker.to.date + " " + $scope.timepicker.to.time)
}; };
}
// Broadcast time $scope.time_apply = function() {
$rootScope.$broadcast($scope.panel.group+"-time", $scope.time) // Update internal time object
$scope.time = $scope.time_check();
$scope.time.field = $scope.panel.timefield
// Get indices for the time period, then broadcast time range and index list
// in a single object. Not sure if I like this.
indices($scope.time.from,$scope.time.to).then(function (p) {
$scope.time.index = p.join();
// Broadcast time
$rootScope.$broadcast($scope.panel.group+"-time", $scope.time)
});
// Update panel's string representation of the time object // Update panel's string representation of the time object
$scope.panel.time = { $scope.panel.time = {
from : $scope.time.from.format("mm/dd/yyyy HH:MM:ss"), from : $scope.time.from.format("mm/dd/yyyy HH:MM:ss"),
to : $scope.time.to.format("mm/dd/yyyy HH:MM:ss") to : $scope.time.to.format("mm/dd/yyyy HH:MM:ss"),
index : $scope.time.index,
}; };
}; };
// returns a promise containing an array of all indices matching the index
// pattern that exist in a given range
function indices(from,to) {
var possible = [];
_.each(date_range(from,to.add_days(1)),function(d){
possible.push(d.format($scope.panel.index));
});
return all_indices().then(function(p) {
return _.intersection(p,possible);
})
};
// returns a promise containing an array of all indices in an elasticsearch
// cluster
function all_indices() {
var something = $http({
url: config.elasticsearch + "/_aliases",
method: "GET"
}).error(function(data, status, headers, config) {
$scope.error = status;
});
return something.then(function(p) {
var indices = [];
_.each(p.data, function(v,k) {
indices.push(k)
});
return indices;
});
}
// Great, every function is ready, init.
$scope.init();
}) })
\ No newline at end of file
#!/usr/bin/env bash #!/usr/bin/env bash
echo "Generating bulk indexable shakespeare lines with timestamp 3 hours in the past and 5 hours into the future" echo "Generating bulk indexable shakespeare lines with timestamp 3 hours in the past and 10 hours into the future"
node reader.js > indexme.json node reader.js > indexme.json
echo "Setting mapping for shakespeare index" echo "Setting mapping for shakespeare index"
curl -XPUT http://localhost:9200/_template/shakespeare -d ' curl -XPUT http://localhost:9200/_template/shakespeare -d '
......
...@@ -21,7 +21,7 @@ fs.readFile('shakespeare.json', 'utf8', function (err,data) { ...@@ -21,7 +21,7 @@ fs.readFile('shakespeare.json', 'utf8', function (err,data) {
} }
function print_obj(o) { function print_obj(o) {
var randomnumber=Math.floor(Math.random()*28800000) var randomnumber=Math.floor(Math.random()*57600000)
var command = {index:{_index: "shakespeare", _type: "line", _id: i}}; var command = {index:{_index: "shakespeare", _type: "line", _id: i}};
o['@timestamp'] = new Date((new Date()).getTime() -9000000 + randomnumber); o['@timestamp'] = new Date((new Date()).getTime() -9000000 + randomnumber);
o.geo = [getRandomInRange(-90, 90, 3),getRandomInRange(-180, 180, 3)] o.geo = [getRandomInRange(-90, 90, 3),getRandomInRange(-180, 180, 3)]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment