collectd: fix dhcpcount

This commit is contained in:
Astro 2020-05-15 18:36:48 +02:00
parent 5162a6b985
commit 4b90cde92a
1 changed files with 29 additions and 21 deletions

View File

@ -4,14 +4,22 @@ require 'date'
INTERVAL = 10
hostname = `hostname`.strip
STDOUT.sync = true
loop do
starts = nil
ends = nil
seen = {}
count = 0
starts = nil
ends = nil
ignore = false
IO::readlines("/var/lib/dhcp/dhcpd.leases").each do |line|
if line =~ /^lease/
if line =~ /^lease (.+) \{/
addr = $1
ignore = seen[addr]
seen[addr] = true
starts = nil
ends = nil
elsif line =~ /starts \d+ (.+?);/
@ -20,8 +28,8 @@ loop do
ends = DateTime.parse $1
elsif line =~ /^\}/
now = DateTime.now
if starts and ends and
starts <= now and ends >= now
if (not ignore) and starts and ends and
starts <= now and ends >= now and
count += 1
end
end