File: //usr/lib/python2.7/site-packages/lap/tac_flows_received.py
import os
import time
from lap import check_ha
def extract_info(line):
return((line.split(" ")[15]).replace(',',''))
def __run__(params):
iface = params.get("iface")
if not check_ha(iface):
return [0, "OK: This server is slave"]
tcpdump_file = params.get("tcpdump_file")
if not tcpdump_file:
return [3, "UNKNOWN: tcpdump_file is not given"]
delay = int(params.get("delay", 300))
if not (time.time() - os.path.getmtime(tcpdump_file)) > delay:
with open(tcpdump_file, "r") as fh:
switches_ips = params.get("switches_ips")
check = dict([(x, False) for x in switches_ips])
for line in fh:
ip = extract_info(line)
if (ip in switches_ips):
check[ip] = True
else:
check[ip] = "Unauthorized"
failed_ips = [k for k, v in check.items() if not v]
unauthorized_ips = [k for k, v in check.items() if v == "Unauthorized"]
if not len(failed_ips) and not len(unauthorized_ips) > 0:
return [0, "OK: All IP's are sending flows"]
elif len(failed_ips) and len(unauthorized_ips) > 0:
return [2, "CRITICAL: IP(s) %s didn't sent flows and IP(s) %s not authorized" % (failed_ips, unauthorized_ips)]
elif len(failed_ips) > 0:
return [2, "CRITICAL: IP(s) %s didn't sent flows" % failed_ips]
else:
return [2, "CRITICAL: IP(s) %s not authorized" % unauthorized_ips]
else:
return [1, "WARNING: TCPDUMP File is out of date"]