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 missing "connection" JSON property #14

Merged
merged 4 commits into from
Dec 28, 2023
Merged

Conversation

S-Bryce
Copy link
Contributor

@S-Bryce S-Bryce commented May 2, 2023

As of the new version of Wazuh (v4.4), the returned JSON by /overview/agents appears to have changed to be the following:

      "agent_status" : {
         "configuration" : {
            "synced" : X,
            "not_synced" : X,
            "total" : X
         },
         "connection" : {
            "disconnected" : X,
            "pending" : X,
            "total" : X,
            "active" : X,
            "never_connected" : X
         }
      }

Which is causing accesses like agents["agent_status"]["active"] to fail and throw a KeyError, e.g.:

Traceback (most recent call last):
  File "./main.py", line 540, in <module>
    REGISTRY.register(WazuhCollector())
  File "/usr/local/lib/python3.8/site-packages/prometheus_client/registry.py", line 40, in register
    names = self._get_names(collector)
  File "/usr/local/lib/python3.8/site-packages/prometheus_client/registry.py", line 80, in _get_names
    for metric in desc_func():
  File "./main.py", line 93, in collect
    "wazuh_active_agents", value=agents["agent_status"]["active"], labels={}
KeyError: 'active'

This PR addresses this by adding the connective JSON property "connection" to such accesses (e.g., agents["agent_status"]["connection"]["active"]).

Bridges between the "agent_status" property and "connection" sub-property values in light of new JSON structuring with 4.4
@pyToshka
Copy link
Owner

pyToshka commented May 2, 2023

@S-Bryce thank you for your pr, unfortunately if response has been changed for version 4.4, exporter will stop working for old versions

@S-Bryce
Copy link
Contributor Author

S-Bryce commented May 2, 2023

@S-Bryce thank you for your pr, unfortunately if response has been changed for version 4.4, exporter will stop working for old versions

Good point! I think it should be possible to check the version of the server and have a conditional for which method to use based on the server's version, or even more simply check to see if the "connnection" key exists at all and if not use the old method.

Will make some edits and push a backwards-compatible update

Now supports versions of Wazuh lower than 4.4
@S-Bryce
Copy link
Contributor Author

S-Bryce commented May 2, 2023

Alright @pyToshka , the PR should support versions below 4.4 now

@S-Bryce
Copy link
Contributor Author

S-Bryce commented Sep 11, 2023

Have you had a chance to look over the backwards compatibility changes @pyToshka? Sorry to be a bother.

@pyToshka pyToshka merged commit b50a66f into pyToshka:main Dec 28, 2023
1 of 2 checks passed
@pyToshka pyToshka linked an issue Dec 28, 2023 that may be closed by this pull request
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.

Keyerror: 'active'
2 participants