From 2c16297fdb3f512f67f9dcae065df1f6f690ebf6 Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 15 May 2020 18:58:50 +0200 Subject: [PATCH] collectd: fix dhcpcount --- salt/collectd/dhcpcount.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/salt/collectd/dhcpcount.rb b/salt/collectd/dhcpcount.rb index 60cc42c..092b3e6 100644 --- a/salt/collectd/dhcpcount.rb +++ b/salt/collectd/dhcpcount.rb @@ -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