From c8b7e34732fbd60d78ea3803698d7243642babe0 Mon Sep 17 00:00:00 2001
From: mwiegand <mwiegand@seibert-media.net>
Date: Thu, 11 Aug 2022 12:37:28 +0200
Subject: [PATCH] apcaccess telegraf: only one call

---
 bundles/apcupsd/files/telegraf_plugin | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/bundles/apcupsd/files/telegraf_plugin b/bundles/apcupsd/files/telegraf_plugin
index 6a490a1..8eefd45 100644
--- a/bundles/apcupsd/files/telegraf_plugin
+++ b/bundles/apcupsd/files/telegraf_plugin
@@ -2,7 +2,9 @@
 
 date=$(date --utc +%s%N)
 
-for metric in TIMELEFT LOADPCT BCHARGE
+METRICS=$(apcaccess)
+
+for METRIC in TIMELEFT LOADPCT BCHARGE
 do
-  echo "apcupsd $metric=$(apcaccess -p $metric | cut -d' ' -f1) $date"
+  echo "apcupsd $METRIC=$(grep $METRIC <<< $METRICS | cut -d ':' -f 2 | xargs | cut -d ' ' -f 1 ) $date"
 done