collectd: fix dhcpcount
This commit is contained in:
parent
4b90cde92a
commit
2c16297fdb
|
@ -10,16 +10,14 @@ loop do
|
||||||
seen = {}
|
seen = {}
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
|
addr = nil
|
||||||
starts = nil
|
starts = nil
|
||||||
ends = nil
|
ends = nil
|
||||||
ignore = false
|
|
||||||
|
|
||||||
IO::readlines("/var/lib/dhcp/dhcpd.leases").each do |line|
|
IO::readlines("/var/lib/dhcp/dhcpd.leases").each do |line|
|
||||||
if line =~ /^lease (.+) \{/
|
if line =~ /^lease (.+) \{/
|
||||||
addr = $1
|
addr = $1
|
||||||
ignore = seen[addr]
|
|
||||||
|
|
||||||
seen[addr] = true
|
|
||||||
starts = nil
|
starts = nil
|
||||||
ends = nil
|
ends = nil
|
||||||
elsif line =~ /starts \d+ (.+?);/
|
elsif line =~ /starts \d+ (.+?);/
|
||||||
|
@ -28,9 +26,13 @@ loop do
|
||||||
ends = DateTime.parse $1
|
ends = DateTime.parse $1
|
||||||
elsif line =~ /^\}/
|
elsif line =~ /^\}/
|
||||||
now = DateTime.now
|
now = DateTime.now
|
||||||
if (not ignore) and starts and ends and
|
if starts and ends and
|
||||||
starts <= now and ends >= now and
|
starts <= now and ends >= now and
|
||||||
count += 1
|
|
||||||
|
unless seen[addr]
|
||||||
|
count += 1
|
||||||
|
seen[addr] = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue