File: //proc/self/root/lib/python2.7/site-packages/lap/check_multiple_default_gateways.py
#!/usr/bin/python
def __run__(params):
file = '/etc/network/interfaces'
string = 'gateway'
count_file = open(file, 'r').read().count(string)
count_gw = 0
# Python's 'netifaces' module only has the concept of
# 'gateways' on newer versions. Read /proc/net/route instead
with open('/proc/net/route') as f:
for line in f:
fields = line.strip().split()
if fields[1] == '00000000':
count_gw = count_gw + 1
if count_file > 1:
return [2, "CRITICAL - More than 1 '%s' on '%s'" % (string, file)]
if count_gw > 1:
return [2, "CRITICAL - More than 1 gateway configured"]
else:
return [0, "OK - No duplicated gateway found"]