Update PUT /agents/group/{group}/restart response for groups with no agents#8123
Merged
davidjiglesias merged 2 commits into4.2from Apr 7, 2021
Merged
Update PUT /agents/group/{group}/restart response for groups with no agents#8123davidjiglesias merged 2 commits into4.2from
davidjiglesias merged 2 commits into4.2from
Conversation
davidjiglesias
approved these changes
Apr 7, 2021
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi team,
This PR closes #8001.
We are raising the
1755error code and message before calling therestart_agentsfunction from the SDK, in thedapi.py.When we try to do the distributed master call (in
distribute_function), we call the functionforward_request. This function usesget_solver_nodeto get the nodes the agents belonging to the specific group are reporting to.If
len(agents) == 0, we raise the error mentioned above:wazuh/framework/wazuh/core/cluster/dapi/dapi.py
Lines 544 to 554 in fd4ac51
In this PR, I have removed the
group_idcheck inget_solver_node(in dapi.py) used to indicate if the API call wasPUT /agents/group/default/restart.Now the agent controller function
restart_agents_by_groupgets the agents that belong to the specific group. If the agent list size is 0, we return a json response with status 200 and 0 failed and affected items.I have also updated unittest and API integration tests.
Manual tests:
default: group with 1 agent assigned
group1: unexistant group
group2: group with no agents assigned
Group with agents:
2021/04/06 10:45:59 INFO: wazuh 172.20.0.1 "PUT /agents/group/default/restart" with parameters {"pretty": "true", "wait_for_complete": "true"} and body {} done in 1.594s: 200Group without agents:
2021/04/06 10:44:42 INFO: wazuh 172.20.0.1 "PUT /agents/group/group2/restart" with parameters {"pretty": "true", "wait_for_complete": "true"} and body {} done in 38.726s: 200Unexistant group:
2021/04/06 12:26:32 INFO: wazuh 172.20.0.1 "PUT /agents/group/group1/restart" with parameters {"pretty": "true", "wait_for_complete": "true"} and body {} done in 2.475s: 404With both
group:readandagent:readdenied (SAME FOR group:read denied and agent:read allowed):The 3 responses were:
With
group:readallowed andagent:readdenied:Groups with agents:
2021/04/06 13:22:38 INFO: manuel 172.20.0.1 "PUT /agents/group/default/restart" with parameters {"pretty": "true", "wait_for_complete": "true"} and body {} done in 0.039s: 200Unexistant group:
2021/04/06 13:23:10 INFO: manuel 172.20.0.1 "PUT /agents/group/group1/restart" with parameters {"pretty": "true", "wait_for_complete": "true"} and body {} done in 0.036s: 404Group with no agents:
2021/04/06 13:23:47 INFO: manuel 172.20.0.1 "PUT /agents/group/group2/restart" with parameters {"pretty": "true", "wait_for_complete": "true"} and body {} done in 0.042s: 200Unittest results:
Rest of unittests passing.
API integration test results:
Regards,
Manuel.