From 6328e90823ee4fbbc5f87a5892b640ed5682772f Mon Sep 17 00:00:00 2001 From: Dirk Heilig Date: Tue, 19 Nov 2024 14:36:49 +0100 Subject: [PATCH] sort output --- mqtt2prom/run | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mqtt2prom/run b/mqtt2prom/run index d7c49dc..c29629f 100755 --- a/mqtt2prom/run +++ b/mqtt2prom/run @@ -314,6 +314,17 @@ function output(): void $filteredData[$hash] = $entry; } + usort($filteredData, function ($a, $b) { + $r = strcmp($a["name"], $b["name"]); + if ($r !== 0) { + return $r; + } + return strcmp( + strval(json_encode($a["labels"])), + strval(json_encode($b["labels"])) + ); + }); + foreach ($filteredData as $entry) { $labels = []; if (isset($entry["labels"])) { @@ -423,6 +434,7 @@ function getEnvWithDefaultInt(string $key, int $default): int { return intval(getEnvWithDefault($key, $default)); } + function getEnvWithDefault( string $key, bool|string|int $default