File: //lib/python2.7/site-packages/lap/findstring.py
import yaml
import time
def __run__(params):
try:
string = yaml.load(params.get('string'))
file = yaml.load(params.get('file'))
gracetime = int(params.get('gracetime'))
except Exception, e:
return [2, "CRITICAL - Error : %s" % repr(e)]
now = time.localtime()
if now.tm_hour < gracetime:
return [0, "OK - Free check until %dh" % gracetime]
fname = open(file)
check = 0
for line in fname:
if string in line:
return [0, "OK - string '%s' found on %s" % (string, file)]
check = 1
break
if not check:
return [2, "CRITICAL - string '%s' NOT found on %s" % (string, file)]
file.close()