Skip to content

Add json_fetch plugin for fetching JSON data - #90

Open
mlgtcode wants to merge 2 commits into
plesk:masterfrom
mlgtcode:patch-1
Open

mlgtcode wants to merge 2 commits into
plesk:masterfrom
mlgtcode:patch-1

Conversation

@mlgtcode

Copy link
Copy Markdown

This plugin fetches JSON payloads from configured endpoints.

Screenshot 2026-07-25 at 16-39-10 Server Metric Json_fetch - rpi - 360 Monitoring

This plugin fetches JSON payloads from configured endpoints.
@renakas
renakas requested a review from laurisb October 15, 2026 08:19
Comment thread agent360/plugins/json_fetch.py Resolved
Comment thread agent360/plugins/json_fetch.py Resolved
Comment thread agent360/plugins/json_fetch.py Outdated
except Exception as error:
return {'error': 'Fetch error: %s' % str(error)}

def _flatten_payload(self, endpoint_name, payload):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 skipped

Lists could be indexed (weather_tags_0) or ignored; I'd ignore them unless there's a use case.

Comment thread agent360/plugins/json_fetch.py Resolved
Address review: restrict URL schemes, cap response size, numeric metrics only
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.

2 participants