File: //lib/python2.7/site-packages/lap/resl_pleskcl.py
import re
# Temporary check for monitor resl number of pleskcl clients
def __run__(params):
try:
import pymongo
except (ImportError, IOError):
return [2, "CRITICAL - Error: python-pymongo not installed. Please install 'python-pymongo'"]
try:
from yaml import load
except (ImportError, IOError):
return [2, "CRITICAL - Error: python-yaml not installed. Please install 'python-yaml'"]
try:
warn = params.get("warn")
crit = params.get('crit')
if crit < warn:
raise Exception('critical is lower than warn threshold please fix it')
except Exception, e:
return [2, "CRITICAL - Error: %s" % repr(e)]
with open('/var/www/reseller-provisioning/config/mongo.yml', 'r') as stream:
servers = load(stream)['production']['servers']
try:
c = pymongo.Connection(servers)
except Exception, e:
return [2, 'CRITICAL - Problems connecting on MongoDB: %s' % repr(e)]
db = c['reseller_provisioning']
install_servers = db['shared_installation_servers']
results = install_servers.find()
for result in results:
if re.match('pleskcl', result['name']):
servers_col = db['servers']
result = servers_col.find_one( { 'name': result['name'] } )
resellers_col = db['resellers']
count = resellers_col.find( { '$and': [{'server_id': result['_id'] }, { 'status': { '$ne': 'deleted'}} ] }).count()
if count < warn:
return [0, 'OK - %d clients installed' % count]
elif count >= warn and count < crit:
return [1, 'WARN - %d clients installed' % count]
else:
return [2, 'CRIT: %d clients installed' % count]