collectd: fix dhcpcount

This commit is contained in:
Astro 2020-05-15 18:58:50 +02:00
parent 4b90cde92a
commit 2c16297fdb
1 changed files with 7 additions and 5 deletions

View File

@ -10,16 +10,14 @@ loop do
seen = {}
count = 0
addr = nil
starts = nil
ends = nil
ignore = false
IO::readlines("/var/lib/dhcp/dhcpd.leases").each do |line|
if line =~ /^lease (.+) \{/
addr = $1
ignore = seen[addr]
seen[addr] = true
starts = nil
ends = nil
elsif line =~ /starts \d+ (.+?);/
@ -28,9 +26,13 @@ loop do
ends = DateTime.parse $1
elsif line =~ /^\}/
now = DateTime.now
if (not ignore) and starts and ends and
if starts and ends and
starts <= now and ends >= now and
count += 1
unless seen[addr]
count += 1
seen[addr] = true
end
end
end
end