Shumoku Docs

Search documentation

Shared docs and current release

Loading search…

日本語

@shumoku/core · 0.4.0 · function

flattenObject

Source

Flatten an arbitrary upstream record into `DiscoveredMetric[]` for the plugin "All metrics" passthrough panel. This is the generic dumper every `HostsCapable` plugin should use instead of hand-enumerating fields (which is how zabbix ended up coercing every value to a number and dropping categorical attributes). Walk the object: - object children join into the metric name with `_` (`{ a: { b: 1 } }` with prefix `p` → `p_a_b`), - array-of-primitives emits a `<name>_count`, - array-of-objects emits a `<name>_count` then expands each element with a `<key>_index` label, - null / undefined / empty-string / non-finite leaves are skipped as noise. Lifted verbatim (behavior-preserving) from the aruba-instant-on plugin, which had the only correct generic implementation.

flattenObject(obj: unknown, prefix: string, labels?: Record<string, string>): DiscoveredMetric[]

Parameters

Parameter Type Description Default
obj unknown No additional description.
prefix string No additional description.
labels Record<string, string> No additional description. {}

Returns

DiscoveredMetric[]

libs/@shumoku/core/src/plugin-kit/metrics-flatten.ts:24