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

Add mechanism to suppress expected wazuh-db exception #23371

Merged
merged 3 commits into from May 14, 2024

Conversation

fdalmaup
Copy link
Member

Related issue
Closes #23333

Description

Adds a mechanism to suppress the Cannot execute Global database query; FOREIGN KEY constraint failed failure message when synchronizing the agent information of a recently deleted agent.

Logs/Alerts example

ossce.log
2024/05/10 12:39:18 wazuh-db[147] wdb_parser.c:859 at wdb_parse(): DEBUG: Global query: sync-agent-info-set [{"id":1,"name":"f77e92dad2f2","ip":"172.18.0.5","os_name":"Ubuntu","os_version":"20.04.6 LTS","os_major":"20","os_minor":"04","os_codename":"Focal Fossa","os_platform":"ubuntu","os_uname":"Linux |f77e92dad2f2 |5.15.0-105-generic |#115~20.04.1-Ubuntu SMP Mon Apr 15 17:33:04 UTC 2024 |x86_64","os_arch":"x86_64","version":"Wazuh v4.8.0","config_sum":"ab73af41699f13fdd81903b5f23d8d00","merged_sum":"4a8724b20dee0124ff9656783c490c4e","manager_host":"9a9bd3dcf169","node_name":"9a9bd3dcf169","last_keepalive":1715337557,"connection_status":"active","disconnection_time":0,"group_config_status":"synced","status_code":0,"labels":[{"id":1,"key":"#\"_agent_ip\"","value":"172.18.0.5"},{"id":1,"key":"#\"_manager_hostname\"","value":"9a9bd3dcf169"},{"id":1,"key":"#\"_node_name\"","value":"9a9bd3dcf169"},{"id":1,"key":"#\"_wazuh_version\"","value":"Wazuh v4.8.0"}]}]
2024/05/10 12:39:18 wazuh-db[147] wdb.c:1112 at wdb_exec_stmt_silent(): DEBUG: SQL statement execution failed
2024/05/10 12:39:18 wazuh-db[147] wdb_parser.c:5997 at wdb_parse_global_sync_agent_info_set(): DEBUG: Global DB Cannot execute SQL query; err database queue/db/global.db: FOREIGN KEY constraint failed
2024/05/10 12:39:18 wazuh-db[147] main.c:397 at run_worker(): DEBUG: Client 33 disconnected.
2024/05/10 12:39:18 wazuh-db[147] wdb_parser.c:859 at wdb_parse(): DEBUG: Global query: sync-agent-groups-get {"condition": "sync_status", "set_synced": true, "get_global_hash": true}
2024/05/10 12:39:18 wazuh-db[147] wdb_integrity.c:759 at wdb_get_global_group_hash(): DEBUG: No group hash was found to calculate the global group hash.
cluster.log
2024/05/10 12:39:07 DEBUG: [Master] [SendSync] Receiving SendSync request (remoted) from 9a9bd3dcf169 (535832)
2024/05/10 12:39:08 DEBUG: [Worker 9a9bd3dcf169] [Main] Command received: b'syn_a_w_m_p'
2024/05/10 12:39:08 DEBUG: [Worker 9a9bd3dcf169] [Main] Command received: b'new_str'
2024/05/10 12:39:08 DEBUG: [Worker 9a9bd3dcf169] [Main] Command received: b'str_upd'
2024/05/10 12:39:08 DEBUG: [Worker 9a9bd3dcf169] [Main] Command received: b'syn_a_w_m'
2024/05/10 12:39:08 INFO: [Worker 9a9bd3dcf169] [Agent-info sync] Starting.
2024/05/10 12:39:08 DEBUG: [Worker 9a9bd3dcf169] [Agent-info sync] 0/1 chunks updated in wazuh-db in 0.000s.
2024/05/10 12:39:08 INFO: [Worker 9a9bd3dcf169] [Agent-info sync] Finished in 0.003s. Updated 0 chunks.

Framework Unit Tests

Results
$ pytest framework
====================================================================================== test session starts ======================================================================================
platform linux -- Python 3.10.14, pytest-7.3.1, pluggy-1.3.0
rootdir: /home/fdalmau/git/wazuh/framework
configfile: pytest.ini
plugins: metadata-3.0.0, cov-3.0.0, aiohttp-1.0.4, trio-0.7.0, tavern-1.23.5, asyncio-0.18.1, html-2.1.1, anyio-4.3.0
asyncio: mode=auto
collected 2211 items                                                                                                                                                                            

framework/scripts/tests/test_agent_groups.py ..............                                                                                                                               [  0%]
framework/scripts/tests/test_agent_upgrade.py ...............                                                                                                                             [  1%]
framework/scripts/tests/test_cluster_control.py ......                                                                                                                                    [  1%]
framework/scripts/tests/test_rbac_control.py .........                                                                                                                                    [  1%]
framework/scripts/tests/test_wazuh_clusterd.py .......                                                                                                                                    [  2%]
framework/scripts/tests/test_wazuh_logtest.py ......................                                                                                                                      [  3%]
framework/wazuh/core/cluster/dapi/tests/test_dapi.py ................................                                                                                                     [  4%]
framework/wazuh/core/cluster/tests/test_client.py ................                                                                                                                        [  5%]
framework/wazuh/core/cluster/tests/test_cluster.py ...................................                                                                                                    [  7%]
framework/wazuh/core/cluster/tests/test_common.py ....................................................................................                                                    [ 10%]
framework/wazuh/core/cluster/tests/test_control.py ......                                                                                                                                 [ 11%]
framework/wazuh/core/cluster/tests/test_local_client.py ..............                                                                                                                    [ 11%]
framework/wazuh/core/cluster/tests/test_local_server.py ........................                                                                                                          [ 12%]
framework/wazuh/core/cluster/tests/test_master.py ................................................                                                                                        [ 15%]
framework/wazuh/core/cluster/tests/test_server.py .............................                                                                                                           [ 16%]
framework/wazuh/core/cluster/tests/test_utils.py ................                                                                                                                         [ 17%]
framework/wazuh/core/cluster/tests/test_worker.py ..................................                                                                                                      [ 18%]
framework/wazuh/core/tests/test_active_response.py ....................                                                                                                                   [ 19%]
framework/wazuh/core/tests/test_agent.py ................................................................................................................................................ [ 26%]
.....                                                                                                                                                                                     [ 26%]
framework/wazuh/core/tests/test_cdb_list.py ......................................                                                                                                        [ 27%]
framework/wazuh/core/tests/test_common.py .........                                                                                                                                       [ 28%]
framework/wazuh/core/tests/test_configuration.py ........................................................................................                                                 [ 32%]
framework/wazuh/core/tests/test_database.py .............                                                                                                                                 [ 32%]
framework/wazuh/core/tests/test_decoder.py ................                                                                                                                               [ 33%]
framework/wazuh/core/tests/test_exception.py ..........                                                                                                                                   [ 34%]
framework/wazuh/core/tests/test_input_validator.py ...                                                                                                                                    [ 34%]
framework/wazuh/core/tests/test_logtest.py ..                                                                                                                                             [ 34%]
framework/wazuh/core/tests/test_manager.py ...............................                                                                                                                [ 35%]
framework/wazuh/core/tests/test_mitre.py .............                                                                                                                                    [ 36%]
framework/wazuh/core/tests/test_pyDaemonModule.py .....                                                                                                                                   [ 36%]
framework/wazuh/core/tests/test_results.py ........................................                                                                                                       [ 38%]
framework/wazuh/core/tests/test_rootcheck.py .............                                                                                                                                [ 38%]
framework/wazuh/core/tests/test_rule.py .......................                                                                                                                           [ 39%]
framework/wazuh/core/tests/test_sca.py .............................                                                                                                                      [ 41%]
framework/wazuh/core/tests/test_security.py .............                                                                                                                                 [ 41%]
framework/wazuh/core/tests/test_stats.py .................                                                                                                                                [ 42%]
framework/wazuh/core/tests/test_syscheck.py .......                                                                                                                                       [ 42%]
framework/wazuh/core/tests/test_syscollector.py ...                                                                                                                                       [ 43%]
framework/wazuh/core/tests/test_task.py ........                                                                                                                                          [ 43%]
framework/wazuh/core/tests/test_utils.py ................................................................................................................................................ [ 49%]
...................................................................................................................................................                                       [ 56%]
framework/wazuh/core/tests/test_wazuh_queue.py .......................                                                                                                                    [ 57%]
framework/wazuh/core/tests/test_wazuh_socket.py ....................                                                                                                                      [ 58%]
framework/wazuh/core/tests/test_wdb.py ...............................                                                                                                                    [ 59%]
framework/wazuh/core/tests/test_wlogging.py ............                                                                                                                                  [ 60%]
framework/wazuh/rbac/tests/test_auth_context.py ..                                                                                                                                        [ 60%]
framework/wazuh/rbac/tests/test_decorators.py .............................................................................................................                               [ 65%]
framework/wazuh/rbac/tests/test_default_configuration.py .......................................................                                                                          [ 68%]
framework/wazuh/rbac/tests/test_orm.py ..............................................................                                                                                     [ 70%]
framework/wazuh/rbac/tests/test_preprocessor.py ...........                                                                                                                               [ 71%]
framework/wazuh/tests/test_active_response.py ............                                                                                                                                [ 71%]
framework/wazuh/tests/test_agent.py ..........................................................................................................................                            [ 77%]
framework/wazuh/tests/test_cdb_list.py .....................................................                                                                                              [ 79%]
framework/wazuh/tests/test_ciscat.py .................................                                                                                                                    [ 81%]
framework/wazuh/tests/test_cluster.py ..........                                                                                                                                          [ 81%]
framework/wazuh/tests/test_decoder.py ..........................................................                                                                                          [ 84%]
framework/wazuh/tests/test_event.py ....                                                                                                                                                  [ 84%]
framework/wazuh/tests/test_group.py .......                                                                                                                                               [ 84%]
framework/wazuh/tests/test_logtest.py ......                                                                                                                                              [ 85%]
framework/wazuh/tests/test_manager.py ....................................                                                                                                                [ 86%]
framework/wazuh/tests/test_mitre.py .......                                                                                                                                               [ 87%]
framework/wazuh/tests/test_rootcheck.py ..................................................                                                                                                [ 89%]
framework/wazuh/tests/test_rule.py ..........................................................................                                                                             [ 92%]
framework/wazuh/tests/test_sca.py ...........                                                                                                                                             [ 93%]
framework/wazuh/tests/test_security.py .......................................................................                                                                            [ 96%]
framework/wazuh/tests/test_stats.py ...............                                                                                                                                       [ 97%]
framework/wazuh/tests/test_syscheck.py .........................                                                                                                                          [ 98%]
framework/wazuh/tests/test_syscollector.py ............                                                                                                                                   [ 98%]
framework/wazuh/tests/test_task.py ............................                                                                                                                           [100%]

=============================================================================== 2211 passed in 260.70s (0:04:20) ================================================================================

@fdalmaup fdalmaup self-assigned this May 10, 2024
@fdalmaup fdalmaup linked an issue May 10, 2024 that may be closed by this pull request
4 tasks
Copy link
Member

@GGP1 GGP1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, just requested two tiny optimizations because the send_data_to_wbd() function is the core of many cluster tasks

framework/wazuh/core/cluster/common.py Outdated Show resolved Hide resolved
framework/wazuh/core/cluster/common.py Outdated Show resolved Hide resolved
@fdalmaup fdalmaup requested a review from GGP1 May 10, 2024 12:48
Copy link
Member

@GGP1 GGP1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Selutario Selutario merged commit d0696f5 into 4.8.0 May 14, 2024
43 of 44 checks passed
@Selutario Selutario deleted the fix/23333-ignore-db-error branch May 14, 2024 07:59
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.

Investigate error in Agent-info sync task
3 participants