Repository navigation
Conversation
This plugin fetches JSON payloads from configured endpoints.
renakas
reviewed
Oct 15, 2026
renakas
reviewed
Oct 15, 2026
renakas
reviewed
Oct 15, 2026
| except Exception as error: | ||
| return {'error': 'Fetch error: %s' % str(error)} | ||
|
|
||
| def _flatten_payload(self, endpoint_name, payload): |
Collaborator
There was a problem hiding this comment.
Nested and non-numeric values go into the metrics as they are
_flatten_payload only flattens the top level. Everything else is passed through unchanged, so for a payload like:
{"temp": 21.5, "wind": {"speed": 4, "dir": "NW"}, "tags": ["a", "b"], "note": null, "city": "Oslo"}the result contains weather_wind (a dict), weather_tags (a list), weather_note (None) and weather_city (a string). Metrics should be numeric, so these values are either dropped by the backend or break the series. The same applies to a top-level list or string payload (line 213).
Suggestion: flatten recursively with a depth limit and keep only numbers (and booleans as 0/1):
def _flatten_payload(self, prefix, value, depth=3):
if isinstance(value, bool):
return {prefix: int(value)}
if isinstance(value, (int, float)):
return {prefix: value}
if isinstance(value, dict) and depth > 0:
out = {}
for key, child in value.items():
out.update(self._flatten_payload('%s_%s' % (prefix, key), child, depth - 1))
return out
return {} # strings, null, lists, too-deep values are skippedLists could be indexed (weather_tags_0) or ignored; I'd ignore them unless there's a use case.
renakas
reviewed
Oct 15, 2026
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.
This plugin fetches JSON payloads from configured endpoints.