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

Merged
merged 34 commits into from
Dec 3, 2024

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
@guidomodarelli guidomodarelli self-requested a review November 20, 2024 18:34
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
@guidomodarelli

This comment was marked as outdated.

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
@chantal-kelm chantal-kelm self-requested a review November 29, 2024 19:46
chantal-kelm
chantal-kelm previously approved these changes Nov 29, 2024
Copy link
Contributor

github-actions bot commented Dec 2, 2024

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

github-actions bot commented Dec 2, 2024

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

github-actions bot commented Dec 2, 2024

Wazuh Core plugin code coverage (Jest) test % values
Statements 35.56% ( 435 / 1223 )
Branches 36.53% ( 171 / 468 )
Functions 36.24% ( 141 / 389 )
Lines 35.72% ( 433 / 1212 )

Copy link
Contributor

github-actions bot commented Dec 2, 2024

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

github-actions bot commented Dec 2, 2024

Main plugin code coverage (Jest) test % values
Statements 13.42% ( 4026 / 29982 )
Branches 8.96% ( 1749 / 19516 )
Functions 12.99% ( 944 / 7267 )
Lines 13.59% ( 3924 / 28860 )

@Desvelao Desvelao requested a review from chantal-kelm December 2, 2024 15:42
@guidomodarelli
Copy link
Contributor

guidomodarelli commented Dec 3, 2024

Legend:
⚫ 🠊 The test hasn't started yet.
🟢 🠊 All checks passed.
🟡 🠊 There is at least one expected fail or skipped test and no failures.
🔴 🠊 There is at least one failed check.
⚪ 🠊 Doesn't apply.
🔧 🠊 Request changes.

CR 🟢
TEST 🟢

image

image

image

image

image

Copy link
Contributor

@guidomodarelli guidomodarelli left a comment

Choose a reason for hiding this comment

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

LGTM

@asteriscos asteriscos merged commit b318cac into master Dec 3, 2024
8 checks passed
@asteriscos asteriscos deleted the enhancement/7133-add-initialization-service branch December 3, 2024 11:08
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