From 4c23e0abe9f104a42542c90b522d2ffaba791051 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 6 Mar 2026 22:11:43 +0100 Subject: [PATCH] [FIX] Some fixes about encoding --- check_providers.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/check_providers.py b/check_providers.py index 442be5d..a9babf1 100644 --- a/check_providers.py +++ b/check_providers.py @@ -247,6 +247,7 @@ ipv4 2 udp 17 178 src=192.168.149.184 dst=80.13.55.10 sport=1194 dport=1194 src= 10: ppp3g: mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 3 6: br1: mtu 1500 qdisc noqueue state UP mode DEFAULT """ + LINK = re.compile(r':\s+<(?P.+)>.* state (?P.+?)\s') link = LINK.search(output.decode('utf-8')) if link: @@ -331,7 +332,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss else: self._available = True else: - self.status = 'Device {} is down or link state is unknown'.format(self.device.decode('utf-8')) + self.status = 'Device {} is down or link state is unknown'.format(str(self.device)) self._available = False self.update_leds() @@ -347,7 +348,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss self.last_ip = ipaddr.groupdict()['ipv4'] else: self.last_ip = None - macaddr = MACADDR.search(output.decode('utf-8')) + macaddr = MACADDR.search(str(output)) if macaddr: self.device_mac = macaddr.groupdict()['mac'] self.device_type = macaddr.groupdict()['type'] @@ -372,7 +373,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss 88.163.76.254 scope link src 88.163.76.120 """ GW = re.compile(r'default via (?P\d+.\d+.\d+.\d+)\s+') - gw = GW.search(output.decode('utf-8')) + gw = GW.search(str(output)) if gw: logger.debug('Gateway : {}'.format(gw.groupdict()['gateway'])) return gw.groupdict()['gateway'] @@ -389,7 +390,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss try: (retcode,routes) = run('ip route list table {}'.format(self.provider_name)) if retcode == 0: - routes = routes.decode('utf-8').splitlines() + routes = str(routes).splitlines() self.last_enabled = len(routes)>0 else: self.last_enabled = False @@ -482,7 +483,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss """Remove default route which could have been added in main routing table and will prevent fallback interface from taking over""" (retcode,routes) = run('ip route list table main dev {}'.format(self.device)) if retcode == 0: - if 'default ' in routes.decode('utf-8'): + if 'default ' in str(routes): print(run('ip route del default table main dev {}'.format(self.device),dry_run=self.dry_run)) def __str__(self): @@ -692,7 +693,7 @@ if __name__ == '__main__': if not provider.enabled: logger.warning("Enabling the available provider {}".format(provider.provider_name)) provider.enable() - run('conntrack -F') + run('/usr/sbin/conntrack -F') if provider.openvpn_master: restart_openvpn() @@ -707,7 +708,7 @@ if __name__ == '__main__': nexthop via 185.16.51.9 realm 3 dev eth1 weight 1 nexthop dev tun2 weight 1 """ - balance = output.decode('utf-8').splitlines() + balance = str(output).splitlines() in_balance = False for l in balance: if provider.gateway in l.split(' ') or provider.device in l.split(' '): @@ -716,6 +717,7 @@ if __name__ == '__main__': if not in_balance: shorewall_restart_needed = True logger.critical("Shorewall restart needed because provider {} is not in default balance route ".format(provider.provider_name)) + run('/usr/sbin/shorewall restart && /usr/sbin/conntrack -F') else: