File: //usr/lib/python2.7/site-packages/lap/check_pmta_fila.py
#!/usr/bin/env python
# encoding: utf-8
import yaml
import urllib2
import xml.dom.minidom
from urlparse import urlparse
from xml.dom.minidom import parseString
def __run__(params):
try:
theurl = 'http://localhost:8080/status?format=xml'
req = urllib2.Request(theurl)
try:
thresolds = yaml.load(params.get('thresholds'))
handle = urllib2.urlopen(req)
except IOError, e:
if hasattr(e, 'code'):
if e.code != 401:
return [2, 'CRITICAL: {0}'.format(str(e.code))]
else:
print e.headers
return [2, 'CRITICAL: {0}'.format(str(e.code))]
theurl = handle.read()
doc = parseString(theurl)
for queue in doc.getElementsByTagName("smtp"):
rcp = queue.getElementsByTagName("rcp")
AlertInfo = rcp[0].toxml().replace("<rcp>","")
queue_n = int(AlertInfo.replace("</rcp>",""))
if queue_n > thresolds['critical']:
return [2, 'CRITICAL - {0} in queue'.format(str(queue_n)), "queue=%s" % (queue_n)]
elif queue_n > thresolds['warning']:
return [1, 'WARNING - {0} in queue'.format(str(queue_n)), "queue=%s" % (queue_n)]
else:
return [0, 'OK - {0} in queue'.format(str(queue_n)), "queue=%s" % (queue_n)]
except Exception as e:
return [2, 'CRITICAL: {0}'.format(str(e))]