summaryrefslogtreecommitdiffstats
path: root/python.d/isc_dhcpd.chart.py
diff options
context:
space:
mode:
Diffstat (limited to 'python.d/isc_dhcpd.chart.py')
-rw-r--r--python.d/isc_dhcpd.chart.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/python.d/isc_dhcpd.chart.py b/python.d/isc_dhcpd.chart.py
index a437f803b..60995342c 100644
--- a/python.d/isc_dhcpd.chart.py
+++ b/python.d/isc_dhcpd.chart.py
@@ -7,14 +7,15 @@ from os import stat, access, R_OK
from os.path import isfile
try:
from ipaddress import ip_network, ip_address
- have_ipaddress = True
+ HAVE_IPADDRESS = True
except ImportError:
- have_ipaddress = False
+ HAVE_IPADDRESS = False
try:
from itertools import filterfalse
except ImportError:
from itertools import ifilterfalse as filterfalse
-from base import SimpleService
+
+from bases.FrameworkServices.SimpleService import SimpleService
priority = 60000
retries = 60
@@ -55,11 +56,10 @@ class Service(SimpleService):
# Will work only with 'default' db-time-format (weekday year/month/day hour:minute:second)
# TODO: update algorithm to parse correctly 'local' db-time-format
- # (epoch <seconds-since-epoch>; # <day-name> <month-name> <day-number> <hours>:<minutes>:<seconds> <year>)
# Also only ipv4 supported
def check(self):
- if not have_ipaddress:
+ if not HAVE_IPADDRESS:
self.error('\'python-ipaddress\' module is needed')
return False
if not (isfile(self.leases_path) and access(self.leases_path, R_OK)):
@@ -146,7 +146,16 @@ class Service(SimpleService):
def binding_active(lease_end_time, current_time):
- return mktime(strptime(lease_end_time, '%w %Y/%m/%d %H:%M:%S')) - current_time > 0
+ # lease_end_time might be epoch
+ if lease_end_time.startswith('epoch'):
+ epoch = int(lease_end_time.split()[1].replace(';',''))
+ return epoch - current_time > 0
+ # max. int for lease-time causes lease to expire in year 2038.
+ # dhcpd puts 'never' in the ends section of active lease
+ elif lease_end_time == 'never':
+ return True
+ else:
+ return mktime(strptime(lease_end_time, '%w %Y/%m/%d %H:%M:%S')) - current_time > 0
def find_lease(value):
@@ -155,4 +164,3 @@ def find_lease(value):
def find_ends(value):
return value[2:6] != 'ends'
-