From: Kym Eden Date: Mon, 3 Mar 2025 11:39:30 +0000 (+0000) Subject: prometheus-node-exporter-lua: netclass: Ignore non numbers X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=f6cb2a6b0ed1052b1f16ca5278187a6534cdb5b6;p=openwrt-packages.git prometheus-node-exporter-lua: netclass: Ignore non numbers Prevent error caused by `tonumber` converting empty string to `nil` Signed-off-by: Kym Eden [rework] Signed-off-by: Etienne Champetier --- diff --git a/utils/prometheus-node-exporter-lua/Makefile b/utils/prometheus-node-exporter-lua/Makefile index 134f8cfce..4c304fe5a 100644 --- a/utils/prometheus-node-exporter-lua/Makefile +++ b/utils/prometheus-node-exporter-lua/Makefile @@ -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 PKG_LICENSE:=Apache-2.0 diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netclass.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netclass.lua index 11666ecde..ccd80e51b 100644 --- a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netclass.lua +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netclass.lua @@ -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