forked from zentralwerk/network
collectd: add dhcpcount for *-gw
This commit is contained in:
parent
c3e3eadfb3
commit
88b011772f
5
salt-pillar/collectd/gw.sls
Normal file
5
salt-pillar/collectd/gw.sls
Normal file
|
@ -0,0 +1,5 @@
|
|||
collectd:
|
||||
network: client
|
||||
interface: True
|
||||
conntrack: True
|
||||
dhcpcount: True
|
|
@ -14,10 +14,13 @@ base:
|
|||
- dhcp
|
||||
- bird.radv
|
||||
- bird.ospf
|
||||
- collectd.gw
|
||||
'pub-gw or serv-gw or radio-gw':
|
||||
- dhcp
|
||||
- bird.radv
|
||||
- bird.ospf
|
||||
'pub-gw':
|
||||
- collectd.gw
|
||||
'c3d2-gw or c3d2-anon or mgmt-gw':
|
||||
- bird.ospf
|
||||
'c3d2-gw':
|
||||
|
|
|
@ -38,6 +38,12 @@ LoadPlugin ping
|
|||
Interval 10
|
||||
</Plugin>
|
||||
|
||||
{%- elif plugin == 'dhcpcount' and conf is True %}
|
||||
LoadPlugin exec
|
||||
<Plugin exec>
|
||||
Exec "collectd" "/usr/bin/dhcpcount.rb"
|
||||
</Plugin>
|
||||
|
||||
{%- elif conf is mapping %}
|
||||
LoadPlugin {{ plugin }}
|
||||
|
||||
|
|
31
salt/collectd/dhcpcount.rb
Normal file
31
salt/collectd/dhcpcount.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'date'
|
||||
|
||||
hostname = `hostname`.strip
|
||||
|
||||
loop do
|
||||
starts = nil
|
||||
ends = nil
|
||||
count = 0
|
||||
|
||||
IO::readlines("/var/lib/dhcp/dhcpd.leases").each do |line|
|
||||
if line =~ /^lease/
|
||||
starts = nil
|
||||
ends = nil
|
||||
elsif line =~ /starts \d+ (.+?);/
|
||||
starts = DateTime.parse $1
|
||||
elsif line =~ /ends \d+ (.+?);/
|
||||
ends = DateTime.parse $1
|
||||
elsif line =~ /^\}/
|
||||
now = DateTime.now
|
||||
if starts and ends and
|
||||
starts <= now and ends >= now
|
||||
count += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "PUTVAL #{hostname}/dhcpd/leases N:#{count}"
|
||||
|
||||
sleep 10
|
||||
end
|
|
@ -15,3 +15,10 @@ collectd:
|
|||
file.managed:
|
||||
- source: salt://collectd/collectd.conf
|
||||
- template: 'jinja'
|
||||
|
||||
{%- if pillar['collectd'].get('dhcpcount') %}
|
||||
/usr/bin/dhcpcount.rb:
|
||||
file.managed:
|
||||
- source: salt://collectd/dhcpcount.rb
|
||||
- mode: 755
|
||||
{%- endif %}
|
||||
|
|
|
@ -13,6 +13,7 @@ base:
|
|||
- forwarding
|
||||
- bird
|
||||
- dhcp
|
||||
- collectd
|
||||
'priv13-gw':
|
||||
- firewall.priv-stateful
|
||||
'pub-gw or serv-gw':
|
||||
|
@ -20,6 +21,8 @@ base:
|
|||
- forwarding
|
||||
- bird
|
||||
- dhcp
|
||||
'pub-gw':
|
||||
- collectd
|
||||
'c3d2-gw or c3d2-anon or mgmt-gw':
|
||||
- no-ssh
|
||||
- forwarding
|
||||
|
|
Loading…
Reference in New Issue
Block a user