collectd: fix dhcpcount
This commit is contained in:
parent
4b90cde92a
commit
2c16297fdb
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue