File: //lib/python2.7/site-packages/lap/mclogmonitor.py
#!/usr/bin/python
import socket
import fcntl
import struct
import array
import glob
import re
import platform
import yaml
import commands
def __run__(params):
try:
thresholds = yaml.load(params.get('thresholds'))
maximalpolicytime = params.get('maximalpolicytime',10.0)
status,output = commands.getstatusoutput("tail -n 1000 /var/log/trex/traffic.log")
line_error = []
if "mcingress" in socket.gethostname():
for line in output.split("\n"):
line = line.strip()
if "Policy t=0,0" in line:
policytime=float(line.split("Policy t=")[1].split("|")[0].split(",")[-1])
if policytime > maximalpolicytime:
return [2,'CRITICAL: Policy is taking %s seconds' % policytime]
elif "mcegress" in socket.gethostname():
for line in output.split("\n"):
line = line.strip()
if "x-authuser" in line and "b=" not in line:
line_error.append(line)
if len(line_error) > thresholds['critical']:
return [2, 'CRITICAL: %d lines in trex logs without b=' % len(line_error)]
elif len(line_error) > thresholds['warning']:
return [1, 'WARNING: %d lines in trex logs without b=' % len(line_error)]
else:
return [0, 'OK']
return [0, 'OK']
except Exception as e:
return [2,'CRITICAL: %s' % e]