controllers.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. 'use strict';
  4. angular.module('kibana.controllers', [])
  5. .controller('DashCtrl', function($scope, $location, $http, $timeout, ejsResource) {
  6. $scope.config = config;
  7. $scope.dashboards = dashboards
  8. /*
  9. $scope.timespan = config.timespan
  10. $scope.time = {
  11. from : time_ago($scope.timespan),
  12. to : new Date()
  13. }
  14. // I'm leaving in all this refresh stuff until I figure out how index
  15. // list caching should work. Maybe it should be handled by each time panel?
  16. // That would require dashboard to contain a time panel. Hmm.
  17. $scope.counter = 0;
  18. $scope.playing = true;
  19. $scope.play = function(){
  20. $scope.counter++;
  21. $scope.time.to = new Date();
  22. $scope.time.from = time_ago($scope.timespan);
  23. $scope.$root.$eval()
  24. mytimeout = $timeout($scope.play,config.refresh);
  25. }
  26. $scope.pause = function(){
  27. if($scope.playing) {
  28. $scope.playing = false;
  29. $timeout.cancel(mytimeout);
  30. } else {
  31. $scope.playing = true;
  32. mytimeout = $timeout($scope.play,config.refresh);
  33. }
  34. }
  35. var mytimeout = $timeout($scope.play,config.refresh);
  36. // If from/to to change, update index list
  37. $scope.$watch(function() {
  38. return angular.toJson([$scope.time.from, $scope.time.to])
  39. }, function(){
  40. indices($scope.time.from,$scope.time.to).then(function (p) {
  41. $scope.index = p.join();
  42. });
  43. });
  44. */
  45. // point to your ElasticSearch server
  46. var ejs = $scope.ejs = ejsResource(config.elasticsearch);
  47. $scope.toggle_row = function(row) {
  48. $scope.$broadcast('toggle_row',row)
  49. row.collapse = row.collapse ? false : true;
  50. }
  51. $scope.set_timespan = function(timespan) {
  52. $scope.timespan = timespan;
  53. $scope.time.from = time_ago($scope.timespan);
  54. }
  55. // returns a promise containing an array of all indices matching the index
  56. // pattern that exist in a given range
  57. function indices(from,to) {
  58. var possible = [];
  59. _.each(date_range(from,to.add_days(1)),function(d){
  60. possible.push(d.format(config.indexpattern));
  61. });
  62. return all_indices().then(function(p) {
  63. return _.intersection(p,possible);
  64. })
  65. };
  66. // returns a promise containing an array of all indices in an elasticsearch
  67. // cluster
  68. function all_indices() {
  69. var something = $http({
  70. url: config.elasticsearch + "/_aliases",
  71. method: "GET"
  72. }).error(function(data, status, headers, config) {
  73. $scope.error = status;
  74. });
  75. return something.then(function(p) {
  76. var indices = [];
  77. _.each(p.data, function(v,k) {
  78. indices.push(k)
  79. });
  80. return indices;
  81. });
  82. }
  83. });