Skip to content
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
Expand Up @@ -7,7 +7,11 @@

import type { estypes } from '@elastic/elasticsearch';
import DateMath from '@kbn/datemath';
import { EXCLUDE_RUN_ONCE_FILTER, FINAL_SUMMARY_FILTER } from '../constants/client_defaults';
import {
EXCLUDE_RUN_ONCE_FILTER,
FINAL_SUMMARY_FILTER,
getRangeFilter,
} from '../constants/client_defaults';
import type { CertificatesResults } from '../../server/queries/get_certs';
import { CertResult, GetCertsParams, Ping } from '../runtime_types';
import { createEsQuery } from '../utils/es_search';
Expand Down Expand Up @@ -46,7 +50,7 @@ export const getCertsRequestBody = ({
}: GetCertsParams) => {
const sort = SortFields[sortBy as keyof typeof SortFields];

const searchRequest = createEsQuery({
return createEsQuery({
from: (pageIndex ?? 0) * size,
size,
sort: asMutableArray([
Expand Down Expand Up @@ -88,6 +92,11 @@ export const getCertsRequestBody = ({
field: 'tls.server.hash.sha256',
},
},
// fetch large enough date range to cover the last 7 days, no particular reason for 7 days
getRangeFilter({
from: 'now-7d',
to: 'now',
}),
{
range: {
'monitor.timespan': {
Expand Down Expand Up @@ -172,8 +181,6 @@ export const getCertsRequestBody = ({
},
},
});

return searchRequest;
};

export const processCertsResult = (result: CertificatesResults): CertResult => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,12 @@ export const getTimeSpanFilter = () => ({
},
},
});

export const getRangeFilter = ({ from, to }: { from: string; to: string }) => ({
range: {
'@timestamp': {
gte: from,
lte: to,
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import type { estypes } from '@elastic/elasticsearch';
import DateMath from '@kbn/datemath';
import { EXCLUDE_RUN_ONCE_FILTER, SUMMARY_FILTER } from '../constants/client_defaults';
import {
EXCLUDE_RUN_ONCE_FILTER,
SUMMARY_FILTER,
getRangeFilter,
} from '../constants/client_defaults';
import { CertResult, GetCertsParams, Ping } from '../runtime_types';
import { createEsQuery } from '../utils/es_search';

Expand Down Expand Up @@ -88,6 +92,10 @@ export const getCertsRequestBody = ({
field: 'tls.server.hash.sha256',
},
},
getRangeFilter({
from: 'now-7d',
to: 'now',
}),
{
range: {
'monitor.timespan': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ describe('getCerts', () => {
"field": "tls.server.hash.sha256",
},
},
Object {
"range": Object {
"@timestamp": Object {
"gte": "now-7d",
"lte": "now",
},
},
},
Object {
"range": Object {
"monitor.timespan": Object {
Expand Down