Skip to content

Commit

Permalink
Merge pull request #2671 from wazuh/fix/CreateIndexPattern
Browse files Browse the repository at this point in the history
Create Index Pattern without available indices
  • Loading branch information
jsanchez91 committed Dec 4, 2020
2 parents cb3da26 + f8efd30 commit eed3101
Show file tree
Hide file tree
Showing 3 changed files with 3,865 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to the Wazuh app project will be documented in this file.

### Fixed

- Create index pattern even if there aren´t available indices [#2620](https://github.com/wazuh/wazuh-kibana-app/issues/2620)
- Top bar overlayed over expanded visualizations [#2667](https://github.com/wazuh/wazuh-kibana-app/issues/2667)

## Wazuh v4.0.3 - Kibana v7.9.1, v7.9.2, v7.9.3 - Revision 4014
Expand Down
28 changes: 12 additions & 16 deletions public/react-services/saved-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { GenericRequest } from './generic-request';
import { getServices } from '../../../../src/plugins/discover/public/kibana_services';
import { KnownFields } from '../utils/known-fields'

export class SavedObject {
/**
Expand Down Expand Up @@ -154,7 +155,7 @@ export class SavedObject {
`/api/saved_objects/index-pattern/${id}`,
{
attributes: {
fields: JSON.stringify(fields.data.fields),
fields: JSON.stringify(fields),
timeFieldName: 'timestamp',
title: title
}
Expand All @@ -173,14 +174,8 @@ export class SavedObject {
*/
static async refreshIndexPattern(pattern) {
try {
const {title : patternTitle} = await getServices().indexPatterns.get(pattern);
const fields = await GenericRequest.request(
//we check if indices exist before creating the index pattern
'GET',
`/api/index_patterns/_fields_for_wildcard?pattern=${patternTitle}`,
{}
);

const { title: patternTitle } = await getServices().indexPatterns.get(pattern);
const fields = await SavedObject.getIndicesFields(pattern);
await this.refreshFieldsOfIndexPattern(pattern, patternTitle, fields);

return;
Expand All @@ -197,13 +192,7 @@ export class SavedObject {
*/
static async createWazuhIndexPattern(pattern) {
try {
const fields = await GenericRequest.request(
//we check if indices exist before creating the index pattern
'GET',
`/api/index_patterns/_fields_for_wildcard?pattern=${pattern}&meta_fields=_source&meta_fields=_id&meta_fields=_type&meta_fields=_index&meta_fields=_score`,
{}
);

const fields = await SavedObject.getIndicesFields(pattern);
await this.createSavedObject(
'index-pattern',
pattern,
Expand All @@ -228,4 +217,11 @@ export class SavedObject {
: error.message || error;
}
}

static getIndicesFields = async (pattern) => GenericRequest.request(
//we check if indices exist before creating the index pattern
'GET',
`/api/index_patterns/_fields_for_wildcard?pattern=${pattern}`,
{}
).then(response => response.data.fields).catch(() => KnownFields)
}
Loading

0 comments on commit eed3101

Please sign in to comment.