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

Fix dashboard audits #126

Merged
merged 1 commit into from
Oct 28, 2019
Merged
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
17 changes: 13 additions & 4 deletions src/legacy/ui/public/courier/fetch/fetch_now.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ContinueIncompleteProvider } from './continue_incomplete';
import { RequestStatus } from './req_status';
import { i18n } from '@kbn/i18n';

import _ from 'lodash';
import moment from 'moment';
import { auditSearch } from '@logrhythm/nm-web-shared/services/audit';

Expand Down Expand Up @@ -115,13 +116,20 @@ export function FetchNowProvider(Private, Promise) {
const searchSourceFields = searchSource.getFields();

let queryToAudit = '';
let queryVal;
if(Array.isArray(searchSourceFields.query)) {
queryToAudit = searchSourceFields.query[searchSourceFields.query.length - 1].query || '';
queryVal = searchSourceFields.query[searchSourceFields.query.length - 1].query || '';
} else {
queryToAudit = searchSourceFields.query.query || '';
queryVal = searchSourceFields.query.query || '';
}

const dateFilter = Object.values(searchSource.getParent().getFields().filter().range)[0];
if(queryVal) {
queryToAudit = typeof queryVal === 'string' ? queryVal : _.get(queryVal, 'query_string.query', '');
}

const fields = searchSource.getParent().getFields();
const filter = fields && typeof fields.filter === 'function' ? fields.filter() : null;
const dateFilter = filter ? Object.values(searchSource.getParent().getFields().filter().range)[0] : null;

if (
!queryToAudit ||
Expand All @@ -146,7 +154,8 @@ export function FetchNowProvider(Private, Promise) {
function startRequests(searchRequests) {
if(searchRequests.length > 0) {
try {
auditFetch(searchRequests[0].source);
auditFetch(searchRequests[0].source)
.catch(err => console.warn('An error occurred trying to audit the query.', err)); // eslint-disable-line
} catch (err) {
console.warn('An error occurred trying to audit the query.', err); // eslint-disable-line
}
Expand Down