-
Notifications
You must be signed in to change notification settings - Fork 1
MON-199535 Factorize Tools Implementation #231
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
Merged
gregory-lvtx
merged 27 commits into
develop
from
MON-199535-factorize-tools-implementation
Jun 4, 2026
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2c6f093
Define base tools related to mixins
gregory-lvtx c22c50f
Use _list for acknowledgements
gregory-lvtx fee6719
Use _list for commands
gregory-lvtx e480128
Use _list, _delete for downtimes
gregory-lvtx 87a7b98
Use _list for monitoring servers
gregory-lvtx 434d0c5
Use _list, _create, _delete for host categories
gregory-lvtx 85480bd
Use _list, _create, _delete for host groups
gregory-lvtx 0075a4f
Use _list, _create, _delete for host severities
gregory-lvtx fbc5108
Use _list, _create, _delete, _patch for host templates
gregory-lvtx deb0af1
Use _list, _create, _delete, _patch for hosts
gregory-lvtx cf46004
Use _list, _create, _delete, _patch for hosts
gregory-lvtx ff8931d
Use _list for service groups
gregory-lvtx 65d1d1e
Fix typos
gregory-lvtx c22b09c
Write unit test for _list method
gregory-lvtx ffdc40a
Write unit test for _patch method
gregory-lvtx b48046b
Remove old _list method
gregory-lvtx a3961eb
Add extras parameter to list mixin to use it for resource
gregory-lvtx 4175d0e
Use generic _list method for resources
gregory-lvtx 5143c52
Update host group configuration model to simplify update tool
gregory-lvtx a4c7004
Inherit update mixin from read one for typing issue
gregory-lvtx 7c5c209
Define generic method to update resource
gregory-lvtx 2f767f7
Use generic _update for host categories
gregory-lvtx d2f3a05
Use generic _update for host severities
gregory-lvtx dc92e78
Use generic _update for host groups
gregory-lvtx 1109836
No need icon class anymore
gregory-lvtx bfc8282
Keep only hosts ids to be aligned with base params
gregory-lvtx 1e45940
Test _delete with one succes and one error
gregory-lvtx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import asyncio | ||
| import json | ||
| from collections.abc import Sequence | ||
| from typing import Any | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
| from centreon_mcp.utils.base import BaseFilter, BaseOrder | ||
| from centreon_mcp.utils.mixins import ( | ||
| CreateMixin, | ||
| DeleteMixin, | ||
| ListMixin, | ||
| PatchMixin, | ||
| UpdateMixin, | ||
| ) | ||
|
|
||
|
|
||
| async def _list[CentreonModel: ListMixin]( | ||
| model: type[CentreonModel], | ||
| filters: Sequence[BaseFilter] | None = None, | ||
| limit: int = 10, | ||
| page: int = 1, | ||
| order: BaseOrder | None = None, | ||
| extras: dict[str, Any] | None = None, | ||
| ) -> list[CentreonModel]: | ||
| """ | ||
| Generic function to list resources based on provided filters, pagination and order. | ||
| """ | ||
| search = json.dumps(BaseFilter.join(filters)) | ||
| sort_by = order.model_dump_json() if order else None | ||
| return await model.list(search, limit, page, sort_by, extras) | ||
|
|
||
|
|
||
| async def _delete[CentreonModel: DeleteMixin]( | ||
|
gregory-lvtx marked this conversation as resolved.
|
||
| model: type[CentreonModel], model_ids: list[int] | ||
| ) -> dict[int, bool | BaseException]: | ||
| """ | ||
| Generic function to delete multiple resources based on their ids. | ||
| """ | ||
| tasks = [asyncio.create_task(model.delete(model_id)) for model_id in model_ids] | ||
| results = await asyncio.gather(*tasks, return_exceptions=True) | ||
| return dict(zip(model_ids, results, strict=True)) | ||
|
|
||
|
|
||
| async def _create[CentreonModel: CreateMixin]( | ||
| model: type[CentreonModel], params: BaseModel | ||
| ) -> bool: | ||
| """ | ||
| Generic function to create a resource based on params. | ||
| """ | ||
| return await model.create(params) | ||
|
|
||
|
|
||
| async def _patch[CentreonModel: PatchMixin]( | ||
| model: type[CentreonModel], model_id: int, params: BaseModel | ||
| ) -> bool: | ||
| """ | ||
| Generic function to patch a resource based on params. | ||
| """ | ||
| return await model.patch(model_id, params) | ||
|
|
||
|
|
||
| async def _update[CentreonModel: UpdateMixin, FullParams: BaseModel]( | ||
| model: type[CentreonModel], full_params_cls: type[FullParams], model_id: int, params: BaseModel | ||
| ) -> bool: | ||
| """ | ||
| Generic function to update a resource from params. | ||
| """ | ||
| current = await model.get(model_id) | ||
| data = current.model_dump(exclude={"id"}, exclude_none=True) # type: ignore | ||
| data |= params.model_dump(exclude_none=True) | ||
| return await model.update(model_id, full_params_cls(**data)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.