@cryptotaxi247 / netdata-1 / commits / 7cd999adc

isc_dhcpd python2 compatibility; #1424

Costa Tsaousis (ktsaou) committed Dec 26, 2016 at 12:37 UTC 7cd999adc1314a2d5c3745b94444d3941fe8ee8c
1 file changed +13 -5
python.d/isc_dhcpd.chart.py
+13 -5
@@ -42,11 +42,11 @@ class Service(SimpleService):
42 else:
43 try:
44 self.pools = self.pools.split()
45 - if not [ip_network(pool) for pool in self.pools]:
45 + if not [ip_network(return_utf(pool)) for pool in self.pools]:
46 self.error('Pools list is empty')
47 return False
48 - except (ValueError, IndexError, AttributeError, SyntaxError):
49 - self.error('Pools configurations is incorrect')
48 + except (ValueError, IndexError, AttributeError, SyntaxError) as e:
49 + self.error('Pools configurations is incorrect', str(e))
50 return False
51
52 # Creating static charts
@@ -96,7 +96,8 @@ class Service(SimpleService):
96
97 file_parse_time = round((time_end - time_start) * 1000)
98
99 - except Exception:
99 + except Exception as e:
100 + self.error("Failed to parse leases file:", str(e))
101 return None
102
103 else:
@@ -148,7 +149,7 @@ def is_binding_active(binding):
149
150
151 def is_address_in(address, pool):
151 - return ipaddress(address) in ip_network(pool)
152 + return ipaddress(return_utf(address)) in ip_network(return_utf(pool))
153
154
155 def find_lease(value):
@@ -157,3 +158,10 @@ def find_lease(value):
158
159 def find_ends(value):
160 return value[2:6] != 'ends'
161 +
162 +def return_utf(s):
163 + # python2 returns "<type 'str'>" for simple strings
164 + # python3 returns "<class 'str'>" for unicode strings
165 + if str(type(s)) == "<type 'str'>":
166 + return unicode(s, 'utf-8')
167 + return s