We are currently in the process of developing a Telecom App dashboard. Our goal is to retrieve logs using Logstash and Elastic search, and then present them on the UI using the ng-Table directive of Angularjs.
While we have successfully obtained the logs, we are facing an issue with sending the response between two controllers from different modules.
Below is the code snippet:
Code for retrieving logs from Elastic search:
// Creating EsConnector module which depends on the elasticsearch module
var EsConnector = angular.module('EsConnector', ['elasticsearch']);
// Creating the es service using esFactory
EsConnector.service('es', function (esFactory) {
return esFactory({ host: 'localhost:9200' });
});
// Defining an Angular controller to check server health
EsConnector.controller('ServerHealthController', function($scope, es) {
es.cluster.health(function (err, resp) {
if (err) {
$scope.data = err.message;
} else {
$scope.data = resp;
}
});
});
// Defining an Angular controller to fetch query results
EsConnector.controller('QueryController', function($scope, es) {
// Searching for documents
es.search({
index: 'logstash-2014.08.29',
size: 500,
body: {
"query":
{
"match": {
"CallId":-1 }
},
}
}).then(function (response) {
$scope.hits = response.hits.hits;
});
});
We are looking for a way to pass the data (i.e., hits obtained from QueryController in EsConnector module) to MainController in the app module.
Here is the app module:
var app = angular.module('SnapshotApp',['ngTable']);
app.controller('MainController', function($scope, ngTableParams){
$scope.query = {}
$scope.queryBy = '$'
var data = ; \\ We want to populate 'data' with 'hits' from QueryController
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
total: data.length, // length of data
getData: function($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
Approaching the situation could involve merging both modules.
Thank you.