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

Add initialization service #7145

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

Desvelao
Copy link
Member

@Desvelao Desvelao commented Nov 11, 2024

Description

This pull request adds the initialization service. This allows to initialize some configuration in the global tenant and provides a service and API to manage the tasks.

Issues Resolved

#7133

Evidence

Logs
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["warning","plugins","wazuhCore","initialization","check-server-api-connection-compatibility"],"pid":136,"message":"Error checking the connection and compatibility with server API [imposter-cli]: Invalid URL"}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["warning","plugins","wazuhCore","initialization","check-server-api-connection-compatibility"],"pid":136,"message":"Error checking the connection and compatibility with server API [manager]: getaddrinfo ENOTFOUND wazuh.manager"}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["info","plugins","wazuhCore","initialization","index-pattern:alerts"],"pid":136,"message":"Index pattern with ID [wazuh-alerts-*] does not exist"}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["info","plugins","wazuhCore","initialization","index-pattern:monitoring"],"pid":136,"message":"Index pattern with ID [wazuh-monitoring-*] does not exist"}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["info","plugins","wazuhCore","initialization","index-pattern:vulnerabilities-states"],"pid":136,"message":"Index pattern with ID [wazuh-states-vulnerabilities-*] does not exist"}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["info","plugins","wazuhCore","initialization","index-pattern:statistics"],"pid":136,"message":"Index pattern with ID [wazuh-statistics-*] does not exist"}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["info","plugins","wazuhCore","initialization","check-server-api-connection-compatibility"],"pid":136,"message":"Server API [imposter] version [5.0.0] is compatible with the Dashboard version"}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["info","plugins","wazuhCore","initialization","check-server-api-connection-compatibility"],"pid":136,"message":"Start check server API connection and compatibility finished"}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["warning","plugins","wazuhCore","initialization","index-pattern:alerts"],"pid":136,"message":"Fields for index pattern with ID [wazuh-alerts-*] could not be obtained. This could indicate there are not matching indices because they were not generated or there is some error in the process that generates and indexes that data. The index pattern will be created with a set of pre-defined fields."}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["info","plugins","wazuhCore","initialization","index-pattern-template:alerts"],"pid":136,"message":"Template [wazuh] found for index pattern with title [wazuh-alerts-*]: "}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["info","plugins","wazuhCore","initialization","index-pattern-template:alerts"],"pid":136,"message":"Start check of existent template finished"}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["warning","plugins","wazuhCore","initialization","index-pattern:statistics"],"pid":136,"message":"Fields for index pattern with ID [wazuh-statistics-*] could not be obtained. This could indicate there are not matching indices because they were not generated or there is some error in the process that generates and indexes that data. The index pattern will be created with a set of pre-defined fields."}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["warning","plugins","wazuhCore","initialization","index-pattern:vulnerabilities-states"],"pid":136,"message":"Fields for index pattern with ID [wazuh-states-vulnerabilities-*] could not be obtained. This could indicate there are not matching indices because they were not generated or there is some error in the process that generates and indexes that data. The index pattern will be created with a set of pre-defined fields."}
{"type":"log","@timestamp":"2024-11-27T09:44:18Z","tags":["warning","plugins","wazuhCore","initialization","index-pattern:monitoring"],"pid":136,"message":"Fields for index pattern with ID [wazuh-monitoring-*] could not be obtained. This could indicate there are not matching indices because they were not generated or there is some error in the process that generates and indexes that data. The index pattern will be created with a set of pre-defined fields."}
{"type":"log","@timestamp":"2024-11-27T09:44:19Z","tags":["info","plugins","wazuhCore","initialization","index-pattern:vulnerabilities-states"],"pid":136,"message":"Created index pattern with ID [wazuh-states-vulnerabilities-*] title [wazuh-states-vulnerabilities-*]"}
{"type":"log","@timestamp":"2024-11-27T09:44:19Z","tags":["info","plugins","wazuhCore","initialization","index-pattern:monitoring"],"pid":136,"message":"Created index pattern with ID [wazuh-monitoring-*] title [wazuh-monitoring-*]"}
{"type":"log","@timestamp":"2024-11-27T09:44:19Z","tags":["info","plugins","wazuhCore","initialization","setting:metaFields"],"pid":136,"message":"Updated [metaFields] setting to: [\"_source\",\"_index\"]"}
{"type":"log","@timestamp":"2024-11-27T09:44:19Z","tags":["info","plugins","wazuhCore","initialization","setting:metaFields"],"pid":136,"message":"Start setting finished"}
{"type":"log","@timestamp":"2024-11-27T09:44:19Z","tags":["info","plugins","wazuhCore","initialization","index-pattern:statistics"],"pid":136,"message":"Created index pattern with ID [wazuh-statistics-*] title [wazuh-statistics-*]"}
{"type":"log","@timestamp":"2024-11-27T09:44:19Z","tags":["info","plugins","wazuhCore","initialization","setting:timepicker:timeDefaults"],"pid":136,"message":"Updated [timepicker:timeDefaults] setting to: \"{\\\"from\\\":\\\"now-24h\\\",\\\"to\\\":\\\"now\\\"}\""}
{"type":"log","@timestamp":"2024-11-27T09:44:19Z","tags":["info","plugins","wazuhCore","initialization","setting:timepicker:timeDefaults"],"pid":136,"message":"Start setting finished"}
{"type":"log","@timestamp":"2024-11-27T09:44:19Z","tags":["info","plugins","wazuhCore","initialization","index-pattern:alerts"],"pid":136,"message":"Created index pattern with ID [wazuh-alerts-*] title [wazuh-alerts-*]"}
{"type":"log","@timestamp":"2024-11-27T09:44:20Z","tags":["info","plugins","wazuhCore","initialization","setting:timeline:max_buckets"],"pid":136,"message":"Updated [timeline:max_buckets] setting to: 200000"}
{"type":"log","@timestamp":"2024-11-27T09:44:20Z","tags":["info","plugins","wazuhCore","initialization","setting:timeline:max_buckets"],"pid":136,"message":"Start setting finished"}

image
image
image
image

Test

Legend:
⚫: none
🟢: pass
🟡: warning
🔴: fail
⚪: not applicable

Other

Test Result
With a fresh environment, run the Wazuh dashboard (ensure the frontend health-check is not executed: change the default app as necessary), and ensure the index patterns related to alerts, monitoring, statistics and vulnerabilities are found in Dashboard Management > Index patterns and the timeline:max_buckets, metaFields, timepicker:timeDefaults settings were changed in Dashboard Management > Advanced settings. Review the Wazuh dashboard logs ensuring the initialization tasks were run without problems.

Details

⚫ With a fresh environment, run the Wazuh dashboard (ensure the frontend health-check is not executed: change the default app as necessary), and ensure the index patterns related to alerts, monitoring, statistics and vulnerabilities are found in Dashboard Management > Index patterns and the timeline:max_buckets, metaFields, timepicker:timeDefaults settings were changed in Dashboard Management > Advanced settings. Review the Wazuh dashboard logs ensuring the initialization tasks were run without problems.

Check List

  • All tests pass
    • yarn test:jest
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

- Add initialization service
- Migrate frontend healthcheck tasks to run in the backend side through
  the initialization service
  - Check existence of index pattern: alerts
  - Check existence of index pattern: monitoring
  - Check existence of index pattern: statistics
  - Check existence of index pattern: vulnerabilities-states
  - Check defined template for alerts index pattern
  - Check Wazuh dashboard setting: metaFields
  - Check Wazuh dashboard setting: timeline:max_buckets
  - Check Wazuh dashboard setting: timepicker:timeDefaults
  - Check connection-compatibility with Wazuh server APIs
…tasks

- Add API endpoints to manage the initialization tasks
- Move injectected depencencies to get in each task
- Add scopes to differenciate where the task is called
@Desvelao Desvelao self-assigned this Nov 11, 2024
@Desvelao Desvelao linked an issue Nov 11, 2024 that may be closed by this pull request
2 tasks
plugins/wazuh-core/server/initialization/server-api.ts Outdated Show resolved Hide resolved
plugins/wazuh-core/server/initialization/server-api.ts Outdated Show resolved Hide resolved
plugins/wazuh-core/server/initialization/server-api.ts Outdated Show resolved Hide resolved
plugins/wazuh-core/server/initialization/server-api.ts Outdated Show resolved Hide resolved
plugins/wazuh-core/server/initialization/server-api.ts Outdated Show resolved Hide resolved
plugins/wazuh-core/server/services/initialization/types.ts Outdated Show resolved Hide resolved
plugins/wazuh-core/server/services/types.ts Outdated Show resolved Hide resolved
plugins/wazuh-core/server/services/initialization/types.ts Outdated Show resolved Hide resolved
plugins/wazuh-core/server/services/initialization/types.ts Outdated Show resolved Hide resolved
@Desvelao Desvelao mentioned this pull request Nov 27, 2024
6 tasks
@chantal-kelm chantal-kelm self-requested a review November 27, 2024 16:42
@guidomodarelli
Copy link
Contributor

Test Result
With a fresh environment, run the Wazuh dashboard (ensure the frontend health-check is not executed: change the default app as necessary), and ensure the index patterns related to alerts, monitoring, statistics and vulnerabilities are found in Dashboard Management > Index patterns and the timeline:max_buckets, metaFields, timepicker:timeDefaults settings were changed in Dashboard Management > Advanced settings. Review the Wazuh dashboard logs ensuring the initialization tasks were run without problems. 🔴

Details

🔴 With a fresh environment, run the Wazuh dashboard (ensure the frontend health-check is not executed: change the default app as necessary), and ensure the index patterns related to alerts, monitoring, statistics and vulnerabilities are found in Dashboard Management > Index patterns and the timeline:max_buckets, metaFields, timepicker:timeDefaults settings were changed in Dashboard Management > Advanced settings. Review the Wazuh dashboard logs ensuring the initialization tasks were run without problems.
Peek.2024-11-27.16-59.mp4

chantal-kelm
chantal-kelm previously approved these changes Nov 27, 2024
Copy link
Member

@chantal-kelm chantal-kelm left a comment

Choose a reason for hiding this comment

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

CR: ✅
TEST: ✅

Captura de pantalla 2024-11-27 a la(s) 7 01 22 p  m Captura de pantalla 2024-11-27 a la(s) 7 00 12 p  m Captura de pantalla 2024-11-27 a la(s) 7 02 27 p  m Captura de pantalla 2024-11-27 a la(s) 7 01 38 p  m

chantal-kelm
chantal-kelm previously approved these changes Nov 28, 2024
Copy link
Member

@chantal-kelm chantal-kelm left a comment

Choose a reason for hiding this comment

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

CR: ✅
Test: ✅

Captura de pantalla 2024-11-28 a la(s) 3 36 37 p  m Captura de pantalla 2024-11-28 a la(s) 3 38 26 p  m Captura de pantalla 2024-11-28 a la(s) 3 39 25 p  m Captura de pantalla 2024-11-27 a la(s) 7 01 38 p  m Captura de pantalla 2024-11-28 a la(s) 3 40 10 p  m

…to enhancement/7133-add-initialization-service
Copy link
Contributor

Wazuh Core plugin code coverage (Jest) test % values
Statements 35.42% ( 435 / 1228 )
Branches 36.38% ( 171 / 470 )
Functions 35.6% ( 141 / 396 )
Lines 35.63% ( 433 / 1215 )

Copy link
Contributor

Wazuh Engine plugin code coverage (Jest) test % values
Statements 8.63% ( 64 / 741 )
Branches 7.94% ( 22 / 277 )
Functions 1.87% ( 7 / 373 )
Lines 9.1% ( 64 / 703 )

Copy link
Contributor

Wazuh Check Updates plugin code coverage (Jest) test % values
Statements 76.44% ( 172 / 225 )
Branches 58.65% ( 61 / 104 )
Functions 61.7% ( 29 / 47 )
Lines 76.44% ( 172 / 225 )

Copy link
Contributor

Wazuh Fleet plugin code coverage (Jest) test % values
Statements 4.68% ( 9 / 192 )
Branches 16.66% ( 7 / 42 )
Functions 1.11% ( 1 / 90 )
Lines 4.76% ( 9 / 189 )

Copy link
Contributor

Main plugin code coverage (Jest) test % values
Statements 13.43% ( 4027 / 29984 )
Branches 8.96% ( 1749 / 19516 )
Functions 12.98% ( 944 / 7270 )
Lines 13.59% ( 3925 / 28861 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create initialization service
5 participants