From f6cb2a6b0ed1052b1f16ca5278187a6534cdb5b6 Mon Sep 17 00:00:00 2001 From: Kym Eden Date: Mon, 3 Mar 2025 11:39:30 +0000 Subject: [PATCH] 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 --- utils/prometheus-node-exporter-lua/Makefile | 2 +- .../usr/lib/lua/prometheus-collectors/netclass.lua | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/prometheus-node-exporter-lua/Makefile b/utils/prometheus-node-exporter-lua/Makefile index 134f8cfceb..4c304fe5a7 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 11666ecde7..ccd80e51bb 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 -- 2.30.2