Fix error whith arping path
This commit is contained in:
+32
-24
@@ -25,6 +25,7 @@ import signal
|
|||||||
|
|
||||||
from iniparse import RawConfigParser
|
from iniparse import RawConfigParser
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
from distutils.spawn import find_executable
|
||||||
|
|
||||||
usage="""\
|
usage="""\
|
||||||
%prog -c configfile action
|
%prog -c configfile action
|
||||||
@@ -33,9 +34,9 @@ Check reachability of multiple providers managed by Shorewall
|
|||||||
enable or disable the providers based on maximum packets loss or RTT
|
enable or disable the providers based on maximum packets loss or RTT
|
||||||
|
|
||||||
action is either :
|
action is either :
|
||||||
monitor : monitor in background all providers and enable/disable them
|
monitor : monitor in background all providers and enable/disable them
|
||||||
check [all,<provider>] : check all or one provider and display reachability
|
check [all,<provider>] : check all or one provider and display reachability
|
||||||
check-json [all,<provider>] : check providers and output state as json data
|
check-json [all,<provider>] : check providers and output state as json data
|
||||||
"""
|
"""
|
||||||
|
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
@@ -94,27 +95,34 @@ ARPING 192.168.149.254
|
|||||||
|
|
||||||
--- 192.168.149.254 statistics ---
|
--- 192.168.149.254 statistics ---
|
||||||
4 packets transmitted, 4 packets received, 0% unanswered (0 extra)
|
4 packets transmitted, 4 packets received, 0% unanswered (0 extra)
|
||||||
"""
|
"""
|
||||||
# iputils-arping
|
# iputils-arping
|
||||||
#root@gw-pironniere:/opt/check-providers# arping -c2 192.168.149.254
|
#root@gw-pironniere:/opt/check-providers# arping -c2 192.168.149.254
|
||||||
"""\
|
"""\
|
||||||
ARPING 192.168.149.254 from 192.168.149.184 eth0
|
ARPING 192.168.149.254 from 192.168.149.184 eth0
|
||||||
Unicast reply from 192.168.149.254 [00:0A:FA:24:18:F7] 0.886ms
|
Unicast reply from 192.168.149.254 [00:0A:FA:24:18:F7] 0.886ms
|
||||||
Unicast reply from 192.168.149.254 [00:0A:FA:24:18:F7] 0.777ms
|
Unicast reply from 192.168.149.254 [00:0A:FA:24:18:F7] 0.777ms
|
||||||
Sent 2 probes (1 broadcast(s))
|
Sent 2 probes (1 broadcast(s))
|
||||||
"""
|
"""
|
||||||
ARPING1 = re.compile(r'bytes from (?P<mac>\S+).*time=(?P<rtt>[0-9.]*) (?P<unit>.*)')
|
ARPING1 = re.compile(r'bytes from (?P<mac>\S+).*time=(?P<rtt>[0-9.]*) (?P<unit>.*)')
|
||||||
ARPING2 = re.compile(r'reply from.*\[(?P<mac>\S+)\]\s+(?P<rtt>[0-9.]*)(?P<unit>.*)')
|
ARPING2 = re.compile(r'reply from.*\[(?P<mac>\S+)\]\s+(?P<rtt>[0-9.]*)(?P<unit>.*)')
|
||||||
|
ARPING_PATH = find_executable('arping')
|
||||||
(returncode,output) = run('/usr/sbin/arping -c{ping_count} -i{device} {target_ip}'.format(
|
if ARPING_PATH == None:
|
||||||
|
raise Exception('No arping command found')
|
||||||
|
elif "/usr/bin/arping" in ARPING_PATH:
|
||||||
|
(returncode,output) = run('arping -c{ping_count} -I{device} {target_ip}'.format(
|
||||||
ping_count = ping_count,
|
ping_count = ping_count,
|
||||||
device = device,
|
device = device,
|
||||||
target_ip = target_ip,
|
target_ip = target_ip,
|
||||||
))
|
))
|
||||||
|
|
||||||
packets = [p.groupdict() for p in ARPING1.finditer(output)]
|
|
||||||
if not packets:
|
|
||||||
packets = [p.groupdict() for p in ARPING2.finditer(output)]
|
packets = [p.groupdict() for p in ARPING2.finditer(output)]
|
||||||
|
elif "/usr/sbin/arping" in ARPING_PATH:
|
||||||
|
(returncode,output) = run('arping -c{ping_count} -i{device} {target_ip}'.format(
|
||||||
|
ping_count = ping_count,
|
||||||
|
device = device,
|
||||||
|
target_ip = target_ip,
|
||||||
|
))
|
||||||
|
packets = [p.groupdict() for p in ARPING1.finditer(output)]
|
||||||
result = {}
|
result = {}
|
||||||
if packets:
|
if packets:
|
||||||
result['mac'] = packets[-1]['mac']
|
result['mac'] = packets[-1]['mac']
|
||||||
@@ -129,7 +137,7 @@ ARPING 192.168.149.254
|
|||||||
class Provider(object):
|
class Provider(object):
|
||||||
def __init__(self,provider_name,device=None,gateway=None,target_ip=None,max_rtt=2000.0,max_loss=30,ping_count=10,ping_interval=0.5,timeout=1.5,led=None):
|
def __init__(self,provider_name,device=None,gateway=None,target_ip=None,max_rtt=2000.0,max_loss=30,ping_count=10,ping_interval=0.5,timeout=1.5,led=None):
|
||||||
"""Parameters of an Internet provider as defined in Shorewall and availability limits
|
"""Parameters of an Internet provider as defined in Shorewall and availability limits
|
||||||
"""
|
"""
|
||||||
self.target_ip=target_ip
|
self.target_ip=target_ip
|
||||||
self.provider_name=provider_name
|
self.provider_name=provider_name
|
||||||
self.device=device
|
self.device=device
|
||||||
@@ -169,9 +177,9 @@ class Provider(object):
|
|||||||
def used_by_openvpn(self,proto='udp',port=1194):
|
def used_by_openvpn(self,proto='udp',port=1194):
|
||||||
(retcode,output) = run('conntrack -L -p {proto} --dport {port} -o extended | grep "={src}"'.format(proto=proto,src=self.last_ip,port=port))
|
(retcode,output) = run('conntrack -L -p {proto} --dport {port} -o extended | grep "={src}"'.format(proto=proto,src=self.last_ip,port=port))
|
||||||
"""
|
"""
|
||||||
ipv4 2 udp 17 178 src=192.168.149.184 dst=80.13.55.10 sport=1194 dport=1194 src=80.13.55.10 dst=192.168.149.184 sport=1194 dport=1194 [ASSURED] mark=1 use=1
|
ipv4 2 udp 17 178 src=192.168.149.184 dst=80.13.55.10 sport=1194 dport=1194 src=80.13.55.10 dst=192.168.149.184 sport=1194 dport=1194 [ASSURED] mark=1 use=1
|
||||||
conntrack v1.2.1 (conntrack-tools): 1 flow entries have been shown.
|
conntrack v1.2.1 (conntrack-tools): 1 flow entries have been shown.
|
||||||
"""
|
"""
|
||||||
conn = output.splitlines()[:-1]
|
conn = output.splitlines()[:-1]
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
@@ -201,7 +209,7 @@ class Provider(object):
|
|||||||
4: eth2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master br1 state DOWN mode DEFAULT qlen 1000
|
4: eth2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master br1 state DOWN mode DEFAULT qlen 1000
|
||||||
10: ppp3g: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 3
|
10: ppp3g: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 3
|
||||||
6: br1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
|
6: br1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
|
||||||
"""
|
"""
|
||||||
LINK = re.compile(r':\s+<(?P<link_states>.+)>.* state (?P<link_status>.+?)\s')
|
LINK = re.compile(r':\s+<(?P<link_states>.+)>.* state (?P<link_status>.+?)\s')
|
||||||
link = LINK.search(output)
|
link = LINK.search(output)
|
||||||
if link:
|
if link:
|
||||||
@@ -241,8 +249,8 @@ class Provider(object):
|
|||||||
|
|
||||||
def check_available(self):
|
def check_available(self):
|
||||||
"""ping the target and change available property based on max_rtt and max_loss
|
"""ping the target and change available property based on max_rtt and max_loss
|
||||||
available == True if actual rtt and loss are below the max_rtt and max_loss
|
available == True if actual rtt and loss are below the max_rtt and max_loss
|
||||||
"""
|
"""
|
||||||
self._available = None
|
self._available = None
|
||||||
self.last_check_time = datetime.datetime.now()
|
self.last_check_time = datetime.datetime.now()
|
||||||
if self.device_up:
|
if self.device_up:
|
||||||
@@ -323,9 +331,9 @@ class Provider(object):
|
|||||||
#from dhcp
|
#from dhcp
|
||||||
(retcode,output) = run('ip route list table {}'.format(self.provider_name))
|
(retcode,output) = run('ip route list table {}'.format(self.provider_name))
|
||||||
"""root@htouv:~# ip route list dev eth1
|
"""root@htouv:~# ip route list dev eth1
|
||||||
88.163.76.0/24 proto kernel scope link src 88.163.76.120
|
88.163.76.0/24 proto kernel scope link src 88.163.76.120
|
||||||
88.163.76.254 scope link src 88.163.76.120
|
88.163.76.254 scope link src 88.163.76.120
|
||||||
"""
|
"""
|
||||||
GW = re.compile(r'default via (?P<gateway>\d+.\d+.\d+.\d+)\s+')
|
GW = re.compile(r'default via (?P<gateway>\d+.\d+.\d+.\d+)\s+')
|
||||||
gw = GW.search(output)
|
gw = GW.search(output)
|
||||||
if gw:
|
if gw:
|
||||||
|
|||||||
Reference in New Issue
Block a user