HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //usr/lib/python2.7/site-packages/lap/app_monitoring.py
import socket
import sys
import os
import time
import json

def __run__(params):
    try:
        import requests
    except ImportError:
        return [2, "CRITICAL - Error: Please install python-requests"]

    try:
        os.environ['no_proxy'] = '127.0.0.1,localhost'
        use_cache = params.get("use_cache", 0)
        cache_time = params.get("cache_time", 180)
        timeout = int(params.get("timeout", 10))
        cache_file = '/var/cache/locaweb-plugins/app_monitoring_cache'
        url = params.get("url", "http://localhost/monitoring")
    except Exception, e:
        return [2, "CRITICAL - Error: %s" % repr(e)]

    if use_cache:
        if os.path.isfile(cache_file) and \
                (time.time() - os.stat(cache_file).st_mtime) < cache_time and \
                    os.stat(cache_file).st_size > 0:
            data = json.loads(open(cache_file).read())
        else:
            try:
                socket.setdefaulttimeout(10)
                data = requests.get(url, verify=False, timeout=timeout).json()
                with open(cache_file, 'w') as f:
                    f.write(json.dumps(data))
            except Exception, e:
                return [2, "CRITICAL - Error: %s" % repr(e)]
    else:
        try:
            socket.setdefaulttimeout(10)
            data = requests.get(url, verify=False, timeout=timeout).json()
        except:
            return [2, "CRITICAL - Error: the url cannot be opened"]

    infos = {}

    try:
        try:
            [ infos.update({key: value['message'][0]}) for key, value in data.iteritems() if not 'ok' in value['status']]
        except:
            for line in data:
                for key, value in line.items():
                    if type(value) is dict and value['status'] != 'ok':
                            infos.update({key: value['message'][0]})
        else:
            [ infos.update({key: value['message'][0]}) for key, value in [ line[1].iteritems() for line in data.items() if isinstance(line[1], dict) ] if not 'ok' in value['status'] ]
        finally:
            errors = []
            if infos:
                for key, value in infos.iteritems():
                    if type(infos) is dict:
                        errors.append("%s: %s," % (key, value['message']))
                        return [2, "CRITICAL - Error: %s" % ' '.join(errors).strip(',')]
                    elif type(infos) is str:
                        errors.append("%s: %s," % (key, value['message'][0]))
                        return [2, "CRITICAL - Error: %s" % ' '.join(errors).strip(',')]
            else:
               return [0, "OK"]

    except Exception, e:
        return [2, "CRITICAL - Error: %s" % repr(e)]