collectd/dhcpcount: properly calculate timeout
This commit is contained in:
parent
699adb37bb
commit
f08a3e486e
|
@ -35,9 +35,17 @@ LoadPlugin ping
|
|||
</Plugin>
|
||||
|
||||
{%- elif plugin == 'dhcpcount' and conf %}
|
||||
{%- set timeout = 60 %}
|
||||
{%- for iface, ips in salt['grains.get']('ip_interfaces').items() %}
|
||||
{%- set dhcp_conf = pillar['dhcp'].get(iface) %}
|
||||
{%- if dhcp_conf and dhcp_conf.get('time') and dhcp_conf.get('time') > timeout %}
|
||||
{%- set timeout = dhcp_conf['time'] %}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
||||
LoadPlugin exec
|
||||
<Plugin exec>
|
||||
Exec "nobody" "/usr/bin/dhcpcount.rb"
|
||||
Exec "nobody" "/usr/bin/dhcpcount.rb" "{{ timeout }}"
|
||||
</Plugin>
|
||||
|
||||
{%- elif conf is mapping %}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
require 'date'
|
||||
|
||||
INTERVAL = 10
|
||||
TIMEOUT = ARGV[0].to_i
|
||||
hostname = `hostname`.strip
|
||||
STDOUT.sync = true
|
||||
|
||||
|
@ -12,22 +13,18 @@ loop do
|
|||
|
||||
addr = nil
|
||||
starts = nil
|
||||
ends = nil
|
||||
|
||||
IO::readlines("/var/lib/dhcp/dhcpd.leases").each do |line|
|
||||
if line =~ /^lease (.+) \{/
|
||||
addr = $1
|
||||
|
||||
starts = nil
|
||||
ends = nil
|
||||
elsif line =~ /starts \d+ (.+?);/
|
||||
starts = DateTime.parse $1
|
||||
elsif line =~ /ends \d+ (.+?);/
|
||||
ends = DateTime.parse $1
|
||||
starts = DateTime.parse($1).to_time
|
||||
elsif line =~ /^\}/
|
||||
now = DateTime.now
|
||||
if starts and ends and
|
||||
starts <= now and ends >= now and
|
||||
now = Time.now
|
||||
if starts and
|
||||
now >= starts and now < starts + TIMEOUT
|
||||
|
||||
unless seen[addr]
|
||||
count += 1
|
||||
|
|
Loading…
Reference in New Issue