File: //usr/lib/python2.7/site-packages/lap/process_running_regex.py
import subprocess
import re
import types
def __run__(params):
try:
proc_name = params.get("proc_name")
proc_regex = params.get("proc_regex")
regexp = re.compile(proc_regex)
p = subprocess.Popen(["ps", "-auxfww"], stdout=subprocess.PIPE)
out, err = p.communicate()
r = regexp.search(out)
result = []
if not isinstance(r, types.NoneType):
result.append(r.group(0))
if len(result) > 0:
return [0,'OK: Process %s is running!' % proc_name]
else:
return [2, 'CRITICAL: Process %s is not running, check the service!' % proc_name]
except Exception, e:
return [2, 'CRITICAL: {0}'.format(str(e))]