prometheus-node-exporter-lua: netclass: Ignore non numbers
authorKym Eden <[email protected]>
Mon, 3 Mar 2025 11:39:30 +0000 (11:39 +0000)
committerEtienne Champetier <[email protected]>
Mon, 23 Jun 2025 09:06:24 +0000 (12:06 +0300)
Prevent error caused by `tonumber` converting empty string to `nil`

Signed-off-by: Kym Eden <[email protected]>
[rework]
Signed-off-by: Etienne Champetier <[email protected]>
utils/prometheus-node-exporter-lua/Makefile
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netclass.lua

index 134f8cfceb52d07fe549091deca9895bb8d46ceb..4c304fe5a708a5ebaccc41743f28e07b47918a6d 100644 (file)
@@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=prometheus-node-exporter-lua
 PKG_VERSION:=2025.06.23
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_MAINTAINER:=Etienne CHAMPETIER <[email protected]>
 PKG_LICENSE:=Apache-2.0
index 11666ecde797f7eb5c018de807e2815f9f9affb7..ccd80e51bba01cabd26afa81bc318672b00a0d2d 100644 (file)
@@ -32,9 +32,9 @@ local function get_metric(device, metric_node_network)
   local operstate = load(device, "operstate")
   local ifalias = load(device, "ifalias")
   metric_node_network.info({device = device, address = address, broadcast = broadcast, duplex = duplex, operstate = operstate, ifalias = ifalias}, 1)
-  local speed = load(device, "speed")
-  if speed ~= nil and tonumber(speed) >= 0 then
-    metric_node_network.speed_bytes({device = device}, tonumber(speed)*1000*1000/8)
+  local speed = tonumber(load(device, "speed"))
+  if speed ~= nil and speed >= 0 then
+    metric_node_network.speed_bytes({device = device}, speed*1000*1000/8)
   end
   local file_to_metric = {
     addr_assign_type   = "address_assign_type",
@@ -55,9 +55,9 @@ local function get_metric(device, metric_node_network)
     type               = "protocol_type",
   }
   for file, metric in pairs(file_to_metric) do
-    local value = load(device, file)
+    local value = tonumber(load(device, file))
     if value ~= nil then
-      metric_node_network[metric]({device = device}, tonumber(value))
+      metric_node_network[metric]({device = device}, value)
     end
   end
 end