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/functional_monitoring.py
import socket
import sys
import os
import time
import json
import urlparse

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

    try:
        url = params.get("url", "http://localhost/monitoring?functional=true")
        alarm = params.get("alarm")
        cache_time = int(params.get("cache_time", "60"))
        cache_file = '/var/cache/locaweb-plugins/functional_%s' % urlparse.urlparse(url).netloc
    except Exception, e:
        return [2, "CRITICAL - Error: %s" % repr(e)]

    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).json()
            with open(cache_file, 'w') as f:
                f.write(json.dumps(data))
        except:
            return [2, "CRITICAL - Error: the url cannot be opened"]

    infos = {}

    try:
        [ infos.update({key: value}) for key, value in 
            [ line.items()[0] for line in data ] if alarm == key ]
        for key, value in infos.iteritems():
            if not 'ok' in value['status']:
                return [2, "CRITICAL - %s" % value['message'][0]['message']]
            else:
                return [0, 'OK']
    except Exception, e:
        return [2, "CRITICAL - Error: %s" % repr(e)]