File: //usr/lib/python2.7/site-packages/lap/app_status_monitoring.py
import socket
import sys
import os
def __run__(params):
status_code = { 'ok' : 0, 'warning' : 1, 'critical' : 2, 'unknown' : 3 }
try:
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
os.environ['no_proxy'] = '127.0.0.1,localhost'
except ImportError:
return [2, "CRITICAL - Error: Please install python-requests"]
try:
url = params.get("url", "http://localhost/monitoring")
except Exception, e:
return [ 2, "CRITICAL - Error %s" % repr(e) ]
try:
socket.setdefaulttimeout(10)
data = requests.get(url, verify=False).json()
except Exception, e:
return [ 2, "CRITICAL - Error: the url cannot be opened. %s" % repr(e) ]
try:
return [ status_code[ data['status'] ], data['message'] ]
except Exception, e:
return [ 2, "CRITICAL - Error %s" % repr(e) ]