Skip to content

Fix: syncAgents() fails in cron context when connection is in non-root entity - #55

Open
TheMoroney wants to merge 2 commits into
initiativa:mainfrom
TheMoroney:main
Open

Fix: syncAgents() fails in cron context when connection is in non-root entity#55
TheMoroney wants to merge 2 commits into
initiativa:mainfrom
TheMoroney:main

Conversation

@TheMoroney

Copy link
Copy Markdown

Testing

To reproduce:

  1. Install plugin and configure the Wazuh connection in any non-root entity (entities_id != 0)
  2. Trigger sync via cron or GLPI automatic actions
  3. Observe that no agents are created despite a successful API/indexer connection

To verify the fix:

  1. Apply the one-line change to syncAgents()
  2. Also update the connection record's entities_id to match your target entity if it was left as 0
  3. Trigger sync — agents should now appear with correct entities_id and is_deleted: 0

Root Cause

Session::getActiveEntity() returns 0 in any context without an active user session (cron, CLI). If the connection lives in entity 1+, the find() call returns nothing and sync silently does nothing.

Fix: syncAgents() fails in cron context when connection is in non-root entity
…context-when-connection-is-in-non-root-entity

Update WazuhAgent.php
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.

1 participant