Anzahl der aktuellen DHCPD-Leases in alfred-announce.py eingebaut
parent
a0d0290a64
commit
f4e023cde9
|
@ -37,6 +37,7 @@ Version Datum Änderung(en) von
|
||||||
-------- ----------- ------------------------------------------------------ ----
|
-------- ----------- ------------------------------------------------------ ----
|
||||||
0.1 2015-10-18 Änderungsprotokoll eingebaut tho
|
0.1 2015-10-18 Änderungsprotokoll eingebaut tho
|
||||||
0.2 2016-08-30 Automatisierung Land des Exit-VPNs tho
|
0.2 2016-08-30 Automatisierung Land des Exit-VPNs tho
|
||||||
|
0.3 2016-12-04 DHCPD-Leases integrieren zur Anzeige der Clientanz. tho
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -54,6 +55,8 @@ import socket
|
||||||
import zlib
|
import zlib
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
import datetime
|
||||||
|
|
||||||
cfg = {
|
cfg = {
|
||||||
'logfile': '/var/log/alfred-announced.log',
|
'logfile': '/var/log/alfred-announced.log',
|
||||||
|
@ -233,6 +236,22 @@ def fn_fastd_peers():
|
||||||
npeers += 1
|
npeers += 1
|
||||||
return npeers
|
return npeers
|
||||||
|
|
||||||
|
def fn_dhcpd_leases():
|
||||||
|
regex_leaseblock = re.compile(r"lease (?P<ip>\d+\.\d+\.\d+\.\d+) {(?P<config>[\s\S]+?)\n}")
|
||||||
|
regex_properties = re.compile(r"\s+(?P<key>\S+) (?P<value>[\s\S]+?);")
|
||||||
|
leases = 0
|
||||||
|
with open("/var/lib/dhcp/dhcpd.leases") as lease_file:
|
||||||
|
macs = set()
|
||||||
|
for match in regex_leaseblock.finditer(lease_file.read()):
|
||||||
|
block = match.groupdict()
|
||||||
|
properties = {key: value for (key, value) in regex_properties.findall(block['config'])}
|
||||||
|
if properties['binding'].split(' ')[1] == 'active' and properties['ends'] != 'never':
|
||||||
|
dt_ends = datetime.datetime.strptime(properties['ends'][2:], "%Y/%m/%d %H:%M:%S")
|
||||||
|
if dt_ends > datetime.datetime.utcnow() and properties['hardware'].startswith('ethernet'):
|
||||||
|
macs.add(properties['hardware'][9:])
|
||||||
|
leases = len(macs)
|
||||||
|
return leases
|
||||||
|
|
||||||
# Hinweis: Die durch Punkte getrennten Teilschlüssel müssen gültige
|
# Hinweis: Die durch Punkte getrennten Teilschlüssel müssen gültige
|
||||||
# PHP-Variablennamen sein.
|
# PHP-Variablennamen sein.
|
||||||
item = {
|
item = {
|
||||||
|
@ -257,9 +276,9 @@ item = {
|
||||||
'statistics.traffic': { 'interval': 60, 'exec': fn_traffic },
|
'statistics.traffic': { 'interval': 60, 'exec': fn_traffic },
|
||||||
'statistics.uptime': { 'interval': 60, 'exec': fn_uptime },
|
'statistics.uptime': { 'interval': 60, 'exec': fn_uptime },
|
||||||
'statistics.peers': { 'interval': 60, 'exec': fn_fastd_peers },
|
'statistics.peers': { 'interval': 60, 'exec': fn_fastd_peers },
|
||||||
|
'statistics.leases': { 'interval': 60, 'exec': fn_dhcpd_leases },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Die Meßwerte nach Intervall gruppieren
|
# Die Meßwerte nach Intervall gruppieren
|
||||||
#items_by_interval = defaultdict(list)
|
#items_by_interval = defaultdict(list)
|
||||||
#for k, v in item.iteritems():
|
#for k, v in item.iteritems():
|
||||||
|
|
Loading…
Reference in New Issue