MetricsHub
MetricsHub Community Connectors 1.0.22
-
Home
- Connector Developer Guide Computes 24
arrayTranslate (Compute)
When To Use
Use arrayTranslate when a single cell contains several values packed into one string — typically a WMI/WBEM array property such as OperationalStatus, which the engine serializes as 2|11. Each element is split out, translated individually through the translation table, and the non-empty results are re-joined.
Element matching is case-insensitive, like translate[1]. Elements that translate to an empty string are dropped from the result; unmatched elements take the table's default translation, or are dropped as well if there is no default entry.
Syntax
sources:
physicalDisks:
# __PATH;DeviceId;OperationalStatus
type: wmi
namespace: root\Microsoft\Windows\Storage
query: SELECT __PATH, DeviceId, OperationalStatus FROM MSFT_PhysicalDisk
computes:
- type: arrayTranslate
column: 3
translationTable: ${translation::OperationalStatusInformationTranslationTable}
resultSeparator: ' - '
# Translation tables are declared in the top-level `translations:` section
translations:
OperationalStatusInformationTranslationTable:
"2": ""
"11": In Service
"13": Lost Communication
"53272": Device Hardware Error
default: Unknown
Properties
| Property | Required | Default | Description |
|---|---|---|---|
type |
Yes | None | arrayTranslate. |
column |
Yes | None | 1-based index of the column containing the array value. |
translationTable |
Yes | None | Reference to a table declared under the top-level translations: section, written ${translation::TableName}. The default key is the fallback translation for unmatched elements. |
arraySeparator |
No | \| |
Separator between elements in the input cell. Treated as a regular expression, so escape special characters (e.g. \. for a dot). |
resultSeparator |
No | \| |
Plain string inserted between translated elements in the output cell. |
Table Transformation Example
With the table above, column: 3 and resultSeparator: ' - ':
Input
| __PATH | DeviceId | OperationalStatus |
|---|---|---|
| …PhysicalDisk.ObjectId=“0” | 0 | 2|11 |
| …PhysicalDisk.ObjectId=“1” | 1 | 53272|13 |
Result
| __PATH | DeviceId | StatusInformation |
|---|---|---|
| …PhysicalDisk.ObjectId=“0” | 0 | In Service |
| …PhysicalDisk.ObjectId=“1” | 1 | Device Hardware Error - Lost Communication |
On the first row, 2 translates to an empty string and is silently dropped, leaving only In Service.
Recommended Pattern
- Map “everything is fine” codes to
""so healthy elements disappear and only anomalies remain in the informational text. - To turn a status array into a single monitorable state, first
arrayTranslatethe codes intook/degraded/failed, then applyconvert[2] witharray2SimpleStatusto keep the worst one (see WinStorageSpaces). - Use
duplicateColumnupstream when you need both an informational text and a status derived from the same array.
Common Mistakes
- Forgetting that
arraySeparatoris a regular expression: a separator like.or+must be escaped (\.,\+). - Expecting unmatched elements to pass through unchanged: without a
defaultentry they are removed entirely, which can produce empty cells. - Using
arrayTranslateon a plain single-value column —translate[1] is the right compute there. - Miscounting the column index: WMI sources prepend requested properties in query order, and
__PATHcounts as a column.
Community Examples
From WinStorageSpaces, included directly from the connector source:
# Translate the 2nd OperationalStatus field into a more readable string
# __PATH;DeviceId;Status;StatusInformation;OperationalStatus
- type: arrayTranslate
column: 4
translationTable: ${translation::OperationalStatusInformationTranslationTable}
resultSeparator: ' - '
- [1] translate.html
- [2] convert.html
- [3] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/hardware/WinStorageSpaces/WinStorageSpaces.yaml
