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",
} }
_.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)});
$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)
}
$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.query[0].query = query;
$scope.get_data();
});
$scope.$on($scope.panel.group+"-time", function(event, time) {
$scope.panel.time = time; $scope.panel.time = time;
$scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
$scope.panel.interval = secondsToHms( $scope.panel.interval = secondsToHms(
calculate_interval(time.from,time.to,50,0)/1000), calculate_interval(time.from,time.to,50,0)/1000),
$scope.get_data(); $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",
} }
_.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)});
$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)
}
$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.query = query;
$scope.get_data();
});
$scope.$on($scope.panel.group+"-time", function(event, time) {
$scope.panel.time = time; $scope.panel.time = time;
$scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
$scope.get_data(); $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];
});
if (!(_.isUndefined($scope.panel.group)) && !(_.isArray($scope.panel.query))) { $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(!(_.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.query.query = query;
$scope.get_data();
});
$scope.$on($scope.panel.group+"-time", function(event, time) {
$scope.panel.time = time; $scope.panel.time = time;
$scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
$scope.get_data(); $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"
} }
_.each(_d, function(v, k) { _.defaults($scope.panel,_d);
$scope.panel[k] = _.isUndefined($scope.panel[k])
? _d[k] : $scope.panel[k];
});
$scope.toggle_sort = function() {
$scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
}
$scope.init = function() {
$scope.fields = []; $scope.fields = [];
$scope.$on($scope.panel.group+"-fields", function(event, fields) { $scope.$on($scope.panel.group+"-fields", function(event, fields) {
$scope.panel.sort = fields.sort; $scope.panel.sort = fields.sort;
$scope.fields = _.union(fields.all,$scope.fields); $scope.fields = _.union(fields.all,$scope.fields);
}); });
}
$scope.toggle_sort = function() {
$scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
}
$scope.init();
}) })
\ 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",
} }
_.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)});
$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)
}
$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)
}, function(){$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.panel.time = time;
$scope.panel.index = _.isUndefined(time.index) ? $scope.panel.index : time.index
$scope.get_data(); $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',
index : '"logstash-"yyyy.mm.dd',
group : "default",
refresh : { refresh : {
enable: false, enable : false,
interval: 3, interval: 30,
min: 3 min : 3
},
time : {
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 // Private refresh interval that we can use for view display without causing
// unnecessary refreshes during changes // unnecessary refreshes during changes
$scope.refresh_interval = $scope.panel.refresh.interval $scope.refresh_interval = $scope.panel.refresh.interval
...@@ -46,30 +69,15 @@ angular.module('kibana.timepicker', []) ...@@ -46,30 +69,15 @@ angular.module('kibana.timepicker', [])
} }
break; break;
} }
$scope.time.field = $scope.panel.timefield;
// Init the values for the time/date pickers $scope.time_apply();
$scope.timepicker = {
from : {
time : $scope.time.from.format("HH:MM:ss"),
date : $scope.time.from.format("mm/dd/yyyy")
},
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 // 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 // request one be sent by broadcasting a 'get_time' with its _id to its group
if (!(_.isUndefined($scope.panel.group))) { $scope.$on($scope.panel.group+"-get_time", function(event,id) {
// Broadcast time when initializing console.log('time request: '+id)
$rootScope.$broadcast($scope.panel.group+"-time", $scope.time) $rootScope.$broadcast(id+"-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() {
...@@ -87,7 +95,7 @@ angular.module('kibana.timepicker', []) ...@@ -87,7 +95,7 @@ angular.module('kibana.timepicker', [])
} }
}); });
}); });
}
$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', [])
} }
} }
}); });
return {
from : from,
to : to
};
} }
$scope.time_apply = function() { $scope.time_apply = function() {
$scope.time_check();
// Update internal time object // Update internal time object
$scope.time = { $scope.time = $scope.time_check();
from : Date.parse($scope.timepicker.from.date + " " + $scope.timepicker.from.time), $scope.time.field = $scope.panel.timefield
to : Date.parse($scope.timepicker.to.date + " " + $scope.timepicker.to.time)
};
// 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 // Broadcast time
$rootScope.$broadcast($scope.panel.group+"-time", $scope.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