From 5379a912192191e6c81254be8cc90ec10007b6db Mon Sep 17 00:00:00 2001 From: htouvet Date: Mon, 19 Jan 2015 09:03:01 +0100 Subject: [PATCH] added enforced source_ip parameter in case the providers are sharing the same interface --- README.md | 2 ++ check_providers.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec5bad7..00ee1a5 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,8 @@ One section for each provider, named the same as in the shorewall **http://shore |led | 1,2,3 | on Alix router, power on/off led depending of availability | |openvpn_master | 0,1 | is provider used by openvpn (openvpn is restarted if vpn is running on provider)| |fallback | 0,1 | is provider a fallback provider, in this case, it is never disabled. | +|source_ip | 1.2.3.4 | optional source_ip fo rthe provider in cas the providers are sharing the same physical interface | + Typical setup on debian wheezy ============================== diff --git a/check_providers.py b/check_providers.py index 80b494c..f44175d 100644 --- a/check_providers.py +++ b/check_providers.py @@ -1,3 +1,4 @@ + #! /usr/bin/python # -*- coding: UTF-8 -*- #------------------------------------------------------------------------------- @@ -144,6 +145,7 @@ class Provider(object): self.device_type=None self.device_mac=None self.last_ip=None + self.source_ip=None self._gateway=gateway @@ -185,7 +187,7 @@ conntrack v1.2.1 (conntrack-tools): 1 flow entries have been shown. def read_config(self,config_file): - for attrib in ['target_ip','device','gateway']: + for attrib in ['target_ip','device','gateway','source_ip']: if config_file.has_option(self.provider_name,attrib): if attrib == 'gateway': setattr(self,'_gateway',config_file.get(self.provider_name,attrib)) @@ -306,7 +308,9 @@ available == True if actual rtt and loss are below the max_rtt and max_loss IPV4ADDR = re.compile(r'\sinet\s+(?P\d+.\d+.\d+.\d+)[/\s]') MACADDR = re.compile(r'link/(?P\S+)(\s(?P\S+))?') ipaddr = IPV4ADDR.search(output) - if ipaddr: + if self.source_ip: + self.last_ip = self.source_ip + elif ipaddr: self.last_ip = ipaddr.groupdict()['ipv4'] else: self.last_ip = None @@ -476,6 +480,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss status = self.status, last_check_time = self.last_check_time, last_ip = self.last_ip, + source_ip = self.source_ip, device_mac = self.device_mac, device_type = self.device_type, gateway_alive = self.gateway_alive,