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(gorgone): Add mbi legacy function to manage host template recursivity #4130

Conversation

Evan-Adam
Copy link
Contributor

Description

host category can be added to host template.
As host template are recursive (a host template can be a parent of another host template) we need to recursivly check every parent for category when adding host in mbi database.

Fixes # Refs:MON-37036

Type of change

  • Patch fixing an issue (non-breaking change)
  • New functionality (non-breaking change)
  • Breaking change (patch or feature) that might cause side effects breaking part of the Software

Target serie

  • 22.04.x
  • 22.10.x
  • 23.04.x
  • 23.10.x
  • 24.04.x
  • 24.10.x (master)

How this pull request can be tested ?

see jira, need to have a centreon db with one host using a host template, with a host category on the host template
launch /usr/share/centreon-bi/bin/centreonBIETL -r
host category should be present in mbi db.

Checklist

Community contributors & Centreon team

  • I have followed the coding style guidelines provided by Centreon
  • I have commented my code, especially new classes, functions or any legacy code modified. (docblock)
  • I have commented my code, especially hard-to-understand areas of the PR.
  • I have rebased my development branch on the base branch (master, maintenance).

Copy link
Contributor

coderabbitai bot commented May 17, 2024

Walkthrough

The recent updates in Host.pm primarily focus on enhancing code readability and consistency through reformatting and minor refactoring. These changes include improved indentation, added spaces, and variable renaming for clarity, while maintaining the original logic and control flow.

Changes

File Path Change Summary
centreon-gorgone/.../libs/centreon/Host.pm Reformatting code blocks, adjusting indentation, adding spaces for readability, and renaming variables for consistency. No functional changes.

Poem

In the code where hosts reside,
Formatting changes, side by side.
Indents fixed and spaces clear,
Making logic crystal here.
Though no function took a twist,
Clarity now does exist.
A rabbit's touch, a coder's cheer! 🐇✨


Tip

Early Access Features
  • gpt-4o model for chat

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Evan-Adam Evan-Adam force-pushed the MON-37036-mbi-gorgone-host-categories-defined-on-templates-arent-present-in-the-host-relations branch from 5080afa to 36c4b6b Compare May 17, 2024 14:33
@Evan-Adam Evan-Adam marked this pull request as ready for review May 17, 2024 15:22
@Evan-Adam Evan-Adam requested a review from a team as a code owner May 17, 2024 15:23
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between db496b9 and 36c4b6b.
Files selected for processing (1)
  • centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/Host.pm (2 hunks)
Files skipped from review due to trivial changes (1)
  • centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/Host.pm

@Evan-Adam Evan-Adam force-pushed the MON-37036-mbi-gorgone-host-categories-defined-on-templates-arent-present-in-the-host-relations branch from 36c4b6b to 7c4c320 Compare May 23, 2024 08:38
@Evan-Adam Evan-Adam requested a review from omercier May 23, 2024 08:40
@Evan-Adam Evan-Adam force-pushed the MON-37036-mbi-gorgone-host-categories-defined-on-templates-arent-present-in-the-host-relations branch from 7c4c320 to 1ac3cc9 Compare May 23, 2024 08:44
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 36c4b6b and 7c4c320.
Files selected for processing (1)
  • centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/Host.pm (2 hunks)
Additional comments not posted (6)
centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/Host.pm (6)

33-43: Constructor new appears to be correctly setting up an instance of the class with optional centstorage database connection. The formatting is clean and the logic is straightforward.


48-49: The method setEtlProperties is simple and correctly assigns ETL properties to the instance. No issues found here.


111-121: The method loadAllHosts is well-implemented with clear logic for loading hosts and their template relations. Similar to loadAllCategories, ensure the SQL query performance is optimized.


249-294: The method GetHostTemplateAndCategoryForOneHost correctly retrieves host templates and their categories. The SQL query is well-formed, but ensure that it is covered by performance tests, especially given its complexity and potential for large result sets.


93-103: The method loadAllCategories correctly queries and processes host categories. The use of hash references to store categories and their relations is appropriate. Ensure that the query performance is acceptable with large datasets.


54-73: The method getAllHosts has been modified to include a condition based on the activated flag. This is a good use of conditional logic to control query behavior. However, ensure that the activated flag is being set and used correctly elsewhere in the code.

Verification successful

The activated flag is used consistently across multiple files to control query behavior based on whether the flag is set or not. The flag is initialized to 1 and set to 0 if any arguments are passed to the function, which is a common pattern in the provided code snippets.

Files and Relevant Code Snippets:

  • CentreonService.pm
    • The activated flag is used to conditionally append AND service_activate='1' to the query.
  • CentreonHost.pm
    • The activated flag is used to conditionally append AND host_activate='1' to the query.
  • MySQLTables.pm
    • The activated flag is used in a logging statement to indicate whether partitioning is activated for a table.
  • Host.pm
    • The activated flag is used to conditionally append AND host_activate='1' to the query.
  • ETLProperties.pm
    • The activated flag is used to conditionally append AND host_activate='1' to the query.

The usage of the activated flag appears to be consistent and correct across these files. The flag is used to control the inclusion of certain conditions in SQL queries, ensuring that only active records are retrieved when the flag is set.

Conclusion

The activated flag is being set and used correctly in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of the `activated` flag in other parts of the codebase.
rg --type perl 'activated'

Length of output: 1708



Script:

#!/bin/bash
# Extracting the relevant code snippets where the `activated` flag is used in the identified files.

# CentreonService.pm
rg --type perl --context 5 'activated' centreon/lib/perl/centreon/reporting/CentreonService.pm

# CentreonHost.pm
rg --type perl --context 5 'activated' centreon/lib/perl/centreon/reporting/CentreonHost.pm

# MySQLTables.pm
rg --type perl --context 5 'activated' centreon-gorgone/gorgone/modules/centreon/mbi/libs/bi/MySQLTables.pm

# Host.pm
rg --type perl --context 5 'activated' centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/Host.pm

# ETLProperties.pm
rg --type perl --context 5 'activated' centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/ETLProperties.pm

Length of output: 5613

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 36c4b6b and 1ac3cc9.
Files selected for processing (1)
  • centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/Host.pm (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/Host.pm

…vity

host category can be added to host template.
As host template are recursive (a host template can be a parent of
another host template) we need to recursivly check every parent for
category when adding host in mbi database.
REF:MON-37036
REF:MON-37036
@Evan-Adam Evan-Adam force-pushed the MON-37036-mbi-gorgone-host-categories-defined-on-templates-arent-present-in-the-host-relations branch from 1ac3cc9 to 432c4f4 Compare May 27, 2024 08:14
@Evan-Adam Evan-Adam merged commit 35aed99 into develop May 27, 2024
2 checks passed
@Evan-Adam Evan-Adam deleted the MON-37036-mbi-gorgone-host-categories-defined-on-templates-arent-present-in-the-host-relations branch May 27, 2024 08:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1ac3cc9 and 432c4f4.
Files selected for processing (1)
  • centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/Host.pm (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • centreon-gorgone/gorgone/modules/centreon/mbi/libs/centreon/Host.pm

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.

None yet

3 participants