File: //usr/lib/python2.7/site-packages/lap/pmta.py
from subprocess import Popen, PIPE
import yaml
def __run__(params):
try:
thresholds = yaml.load(params.get('thresholds'))
except Exception, e:
return [2, "CRITICAL - Error: %s" % repr(e)]
# infos = Popen(['sudo', 'pmta', 'show', 'status'], shell=False, stdout=PIPE, stderr=PIPE)
infos = Popen(['pmta', 'show', 'status'], shell=False, stdout=PIPE, stderr=PIPE)
error = ' '.join(infos.stderr.readlines()).strip('\n')
result = [ line.split() for line in infos.stdout.readlines() if line.strip() ]
if error:
return [2, 'CRITICAL - %s' % repr(error)]
if result:
status = {}
for line in result:
if 'PowerMTA' in line or 'Inbound' in line:
if 'PowerMTA' in line:
status['version'] = line[1]
elif 'Inbound' in line:
status['cur'] = line[1]
status['max'] = line[3]
percent = (float(status['cur']) / float(status['max']) * 100)
if percent > thresholds['critical']:
return [2, 'CRITICAL: {0}% of connections in use' % format(percent)]
elif percent > thresholds['warning']:
return [1, 'WARNING: {0}% of connections in use' % format(percent)]
else:
return [0, 'OK - PowerMTA version: %(version)s, %(cur)s of %(max)s connections' % status]