Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added field name capitalization to discover and visualize #51

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
define(function (require) {
var app = require('modules').get('app/dashboard');
app.factory('searchAuditor', function (elasticSearchFields,
Restangular) {
var previousQuery = {
query : "",
fromDate : "",
toDate : ""
};
var _ = require('lodash');
var moment = require('moment');
var angular = require('angular');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we requiring angular?

Copy link
Author

@alexweltman alexweltman Jul 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kibana does this on every file that uses an angular method like angular.copy


var timefilter = require('components/timefilter/timefilter');
app.factory('searchAuditor', function (elasticSearchFields,
Restangular, timefilter) {
var FORMAT_STRING = 'YYYY/MM/DD HH:mm:ss';
var INDEX_PATTERN = '[network_]YYYY_MM_DD';

var previousQuery = {
query : '',
fromDate : '',
toDate : ''
};
var formatQuery = function(query) {
var _query = _.isArray(query) ? query : [query];
if (_.isArray(_query)) {
Expand All @@ -22,44 +30,65 @@ define(function (require) {
}
return _query;
};
return {
autoCapQuery : function(query) {
return formatQuery(query)[0];
},
logQuery : function(query, from, to) {
// ignore these searches for search auditing
if (!from || !to ||
query === "" ||
query === "*") {
return;
}
var formatString = "YYYY/MM/DD HH:mm:ss";
var from = moment(from).format(formatString);
var to = moment(to).format(formatString);
if (query === previousQuery.query &&
from === previousQuery.fromDate &&
to === previousQuery.toDate) {
return;
}
previousQuery = {

var logQuery = function(query) {
// ignore these searches for search auditing

var timeRange = timefilter.getBounds();
var timeFrom = timeRange.min;
var timeTo = timeRange.max;

if (!timeFrom || !timeTo ||
query === '' ||
query === '*') {
return;
}

timeFrom = moment(timeFrom).format(FORMAT_STRING);
timeTo = moment(timeTo).format(FORMAT_STRING);

if (query === previousQuery.query &&
timeFrom === previousQuery.fromDate &&
timeTo === previousQuery.toDate) {
return;
}
previousQuery = {
query : query,
fromDate : timeFrom,
toDate : timeTo
};
Restangular
.all('audit/')
.post({
query : query,
fromDate : from,
toDate : to
from : timeFrom,
to : timeTo
})
.then(function(response){
if (response.error){
var error = response.message || 'An unknown error occured';
console.log('Search Audit Error:', error);
}
});
};

return {
logAndCapitalize : function(query) {
var capitalizedQuery = formatQuery(query.query_string.query)[0];
logQuery(capitalizedQuery);
// seems like we need to create a new object to force angular to reflect the
// query change in the view

var newQuery =
{
query_string : {
query : capitalizedQuery,
analyze_wildcard : query.query_string.analyze_wildcard
}
};
Restangular
.all('audit/')
.post({
query : query,
from : from,
to : to
})
.then(function(response){
if (response.error){
var error = response.message || "An unknown error occured";
console.log('Search Audit Error:', error);
}
});
return newQuery;
}

};
});
});
Loading