-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add new endpoint 'recalculate-agent-group-hashes' to wazuh-db #23441
Conversation
…ate-agent-group-hashes.
…ction. + adds new function wdb_global_recalculate_agent_groups_hash_without_sync_status.
+ Fixed ut for function wdb_global_recalculate_all_agent_groups_hash
1fa1e79
to
4b994e0
Compare
src/wazuh_db/wdb.c
Outdated
[WDB_STMT_GLOBAL_UPDATE_AGENT_INFO] = "UPDATE agent SET config_sum = :config_sum, ip = :ip, manager_host = :manager_host, merged_sum = :merged_sum, name = :name, node_name = :node_name, os_arch = :os_arch, os_build = :os_build, os_codename = :os_codename, os_major = :os_major, os_minor = :os_minor, os_name = :os_name, os_platform = :os_platform, os_uname = :os_uname, os_version = :os_version, version = :version, last_keepalive = :last_keepalive, connection_status = :connection_status, disconnection_time = :disconnection_time, group_config_status = :group_config_status, status_code= :status_code, sync_status = :sync_status WHERE id = :id;", | ||
[WDB_STMT_GLOBAL_GET_GROUPS] = "SELECT DISTINCT `group`, group_hash from agent WHERE id > 0 AND group_hash > ? ORDER BY group_hash;", | ||
[WDB_STMT_GLOBAL_GET_AGENTS] = "SELECT id FROM agent WHERE id > ?;", | ||
[WDB_STMT_GLOBAL_GET_AGENTS_BY_CONNECTION_STATUS] = "SELECT id FROM agent WHERE id > ? AND connection_status = ?;", | ||
[WDB_STMT_GLOBAL_GET_AGENTS_BY_CONNECTION_STATUS_AND_NODE] = "SELECT id FROM agent WHERE id > ? AND connection_status = ? AND node_name = ? ORDER BY id LIMIT ?;", | ||
[WDB_STMT_GLOBAL_GET_AGENTS_TO_RECALCULATE_GROUP_HASH] = "SELECT id FROM agent WHERE id > 0;", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use the query WDB_STMT_GLOBAL_GET_AGENTS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/wazuh_db/wdb_parser.c
Outdated
int wdb_parse_global_recalculate_agent_group_hashes(wdb_t* wdb, char* output) { | ||
|
||
if (OS_SUCCESS != wdb_global_recalculate_all_agent_groups_hash(wdb)) { | ||
mdebug1("Error recalculating group hash of agents in global.db."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can change this log to warning
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
…ALCULATE_GROUP_HASH, WDB_STMT_GLOBAL_GET_AGENTS is used. + Changes the debugging message “Error recalculating group hash of agents in global.db.” to warning
a0cc761
to
22449c8
Compare
UTs running in local environment: UTs server
UTs agent linux
|
Description
This PR adds the new endpoint 'recalculate-agent-group-hashes' to wazuh-db, this endpoint performs the recalculation of agent-group hashes for each agent stored in the global.db database.
Conditions (agent by agent) for hash recalculation:
The 'group' field of that agent must be different from NULL.Conditions for updating the value of the 'group_hash' and 'group' column in the database:
The newly calculated hash must be different from the previous one.Conditions for updating the value of the 'group_sync_status' column in the database:
The newly calculated hash must be different from the previous one.The value of 'group_sync_status' will be set to 'synced' if the manager is a single-node or a worker node.The value of 'group_sync_status' will be set to 'syncreq' if the manager is the master node.Values that can be returned by the endpoint:
ok
err Error recalculating group hash of agents in global.db
Tests