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

enh(service_groups): add search capabilities to host categories endpoint #4181

Merged
merged 3 commits into from
May 27, 2024

Conversation

adr-mo
Copy link
Contributor

@adr-mo adr-mo commented May 24, 2024

This PR intends to add a host_group search capability to the realtime servicegroups endpoint.

Fixes # (issue)

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.10.x
  • 23.04.x
  • 23.10.x
  • 24.04.x
  • master

How this pull request can be tested ?

Please describe the procedure to verify that the goal of the PR is matched. Provide clear instructions so that it can be correctly tested.

Any relevant details of the configuration to perform the test should be added.

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).

@adr-mo adr-mo requested a review from a team as a code owner May 24, 2024 13:53
@adr-mo adr-mo requested review from callapa and wtermellil May 24, 2024 13:53
Copy link
Contributor

coderabbitai bot commented May 24, 2024

Walkthrough

The recent changes to the MonitoringRepositoryRDB.php enhance the functionality of the findServiceGroups method by introducing new arrays for host group and host category concordance. Conditions and INNER JOIN clauses are added to dynamically include host groups and host categories in the SQL query based on search parameters, improving the flexibility and comprehensiveness of the data retrieval process.

Changes

File Path Change Summary
centreon/src/Centreon/Infrastructure/Monitoring/MonitoringRepositoryRDB.php Enhanced findServiceGroups with new concordance arrays for host groups and categories, added conditional INNER JOIN clauses, and updated SQL query logic.

Poem

In the code where data flows,
Host groups and categories now compose,
With INNER JOINs that smartly bind,
Enhancing queries, intertwined.
Services found with greater ease,
Monitoring now aims to please.
🐇✨


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.

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: 3

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between c8515ab and 9b0f315.
Files ignored due to path filters (1)
  • centreon/doc/API/centreon-api.yaml is excluded by !**/*.yaml
Files selected for processing (1)
  • centreon/src/Centreon/Infrastructure/Monitoring/MonitoringRepositoryRDB.php (3 hunks)
Additional comments not posted (1)
centreon/src/Centreon/Infrastructure/Monitoring/MonitoringRepositoryRDB.php (1)

1582-1585: Verify the conditions for joining services.

The conditions for joining services include checks for srv.enabled and srv.service_register. It's important to verify that these conditions correctly reflect the intended business logic, especially the use of srv.service_register.

Verification successful

The conditions for joining services in the MonitoringRepositoryRDB.php file include checks for srv.enabled and srv.service_register. These conditions appear multiple times and seem consistent with the intended business logic.

  • srv.enabled = '1'
  • srv.service_register = '1'

These conditions are used to ensure that only enabled and registered services are included in the joins.

  • centreon/src/Centreon/Infrastructure/Monitoring/MonitoringRepositoryRDB.php:
    • ON srv.service_id = ssg.service_id AND srv.host_id = h.host_id AND srv.enabled = '1' AND srv.service_register = '1'
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the conditions under which services are joined to ensure they are correct.

# Test: Search for the conditions used in service joins. Expect: Conditions align with business logic.
rg --type sql $'srv.service_register = 1'

Length of output: 42



Script:

#!/bin/bash
# Description: Verify the conditions under which services are joined to ensure they are correct.

# Test: Search for the broader context of service joins in SQL files.
rg --type sql 'JOIN srv'

# Test: Search for conditions used in service joins.
rg --type sql 'ON srv'

Length of output: 51



Script:

#!/bin/bash
# Description: Verify the conditions under which services are joined to ensure they are correct.

# Test: Search for any join conditions in SQL files.
rg --type sql 'JOIN'

# Test: Search for service-related conditions in SQL files.
rg --type sql 'service'

Length of output: 58956



Script:

#!/bin/bash
# Description: Verify the conditions under which services are joined in the MonitoringRepositoryRDB.php file.

# Test: Search for SQL join conditions involving services in the MonitoringRepositoryRDB.php file.
rg 'JOIN.*srv' centreon/src/Centreon/Infrastructure/Monitoring/MonitoringRepositoryRDB.php

# Test: Search for service-related conditions in the MonitoringRepositoryRDB.php file.
rg 'srv\.' centreon/src/Centreon/Infrastructure/Monitoring/MonitoringRepositoryRDB.php

Length of output: 11318

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 9b0f315 and d1b80e6.
Files ignored due to path filters (1)
  • centreon/doc/API/centreon-api.yaml is excluded by !**/*.yaml
Files selected for processing (1)
  • centreon/src/Centreon/Infrastructure/Monitoring/MonitoringRepositoryRDB.php (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • centreon/src/Centreon/Infrastructure/Monitoring/MonitoringRepositoryRDB.php

Copy link



Scan Summary:
PIPELINE_SCAN_VERSION: 24.5.0-0
DEV-STAGE: DEVELOPMENT
SCAN_ID: 341f54c5-f812-4581-b3bc-4b77730bb62a
SCAN_STATUS: SUCCESS
SCAN_MESSAGE: Scan successful. Results size: 644052 bytes
====================
Analysis Successful.
====================

==========================
Found 2 Scannable modules.
==========================
JS files within centreon-web-407e1ebf94d1753bb2d92d272b6073a40e2b128f-9252363080-veracode-binary.zip
PHP files within centreon-web-407e1ebf94d1753bb2d92d272b6073a40e2b128f-9252363080-veracode-binary.zip

===================
Analyzed 2 modules.
===================
JS files within centreon-web-407e1ebf94d1753bb2d92d272b6073a40e2b128f-9252363080-veracode-binary.zip
PHP files within centreon-web-407e1ebf94d1753bb2d92d272b6073a40e2b128f-9252363080-veracode-binary.zip

====================
Analyzed 328 issues.
====================

details


--------------------------------
Found 1 issues of High severity.
--------------------------------
CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'): www/class/centreondb.class.php:311
Details: This database query contains a SQL injection flaw. The call to !php_standard_ns.PDO.query() constructs a dynamic SQL query using a variable derived from untrusted input. An attacker could exploit this flaw to execute arbitrary SQL queries against the database. The first argument to query() contains data from the incoming HTTP request, SQL query string-encoded data from the variable queryString. The data from the incoming HTTP request, SQL query string-encoded data originated from an earlier call to PDO.quote. Avoid dynamically constructing SQL queries. Instead, use parameterized prepared statements to prevent the database from interpreting the contents of bind variables as part of the query. Always validate untrusted input to ensure that it conforms to the expected format, using centralized data validation routines when possible. References: CWE OWASP

Total flaws found: 328, New flaws found: 1 as compared to baseline


========================
FAILURE: Found 1 issues!
========================

@adr-mo adr-mo merged commit a336fd1 into develop May 27, 2024
233 checks passed
@adr-mo adr-mo deleted the MON-55175 branch May 27, 2024 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants