Skip to content

Commit 937d4ef

Browse files
committed
packages: prometheus...-wifi-stations-extra: use babeld if available
This collector currently doesn't work with profile-libremesh-suggested-packages-tiny due to the lack of shared-state-bat_hosts (since this is based on shared-state-async which is too big for 8/64 devices) This commit allows the collector to print hostnames taking the info from /etc/babeld-hosts It also introduces a check to verify the existence of /tmp/dhcp.leases, this in case of a setup without anygw or another dhcp server.
1 parent 5cb70b3 commit 937d4ef

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

  • packages/prometheus-node-exporter-lua-wifi-stations-extra/files/usr/lib/lua/prometheus-collectors

packages/prometheus-node-exporter-lua-wifi-stations-extra/files/usr/lib/lua/prometheus-collectors/wifi_stations_extra.lua

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,31 @@ local iwinfo = require "iwinfo"
33

44
local function mac2name_init()
55
local mac2name = {}
6+
local f = ""
7+
68
filename = "/etc/bat-hosts"
7-
for line in io.lines(filename) do
8-
local mac, name = line:match("(..:..:..:..:..:..)%s+([^%s]+)")
9-
if mac then mac2name[mac:lower()] = name end
9+
f = io.open(filename, "r")
10+
if(f == nil) then
11+
filename = "/etc/babeld-hosts"
12+
f = io.open(filename, "r")
13+
end
14+
if(f ~= nil) then
15+
for line in io.lines(filename) do
16+
if (string.match(filename, "babeld")) then
17+
line = string.gsub(line, "ff:fe:", "")
18+
end
19+
local mac, name = line:match("(..:..:..:..:..:..)%s+([^%s]+)")
20+
if mac then mac2name[mac:lower()] = name end
21+
end
1022
end
23+
1124
filename = "/tmp/dhcp.leases"
12-
for line in io.lines(filename) do
13-
local mac, ip, name = line:match("(..:..:..:..:..:..)%s+([^%s]+)%s+([^%s]+)")
14-
if mac then mac2name[mac:lower()] = name end
25+
f = io.open(filename, "r")
26+
if(f ~= nil) then
27+
for line in io.lines(filename) do
28+
local mac, ip, name = line:match("(..:..:..:..:..:..)%s+([^%s]+)%s+([^%s]+)")
29+
if mac then mac2name[mac:lower()] = name end
30+
end
1531
end
1632
return mac2name
1733
end

0 commit comments

Comments
 (0)