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/np_upstream.py
import requests
import socket
import memcache

def count_req(upstream,code,val):
    mc = memcache.Client(['127.0.0.1:11211'], debug=0)

    key = '%s-%s' % (upstream, code)

    old = mc.get(key)

    if not old or old > val:
        old = 0

    result = val - old

    mc.set(key,val)

    return result


def __run__(params):
    try:
        host = params.get('host')
        upstream = params.get('upstream')
        critical = params.get('critical')
        warning = params.get('warning')
    except Exception, e:
        return [2, "CRITICAL - Error %s" % repr(e)]

    try:
        r = requests.get('http://%s/status' % host)
        if r.status_code == 200:
            data = r.json()
            error = []
            for server in data['upstreams'][upstream]['peers']:
                m = socket.gethostbyaddr(
                    server['server'].split(':')[0])[0].split('.')[0]
                s = server['state']
                if s == 'unhealthy' or s == 'down':
                    error.append(m)

                if len(error):
                    return [2, "CRITICAL - Servers with possibles problems: %s  " % '|'.join(error)]

            err = {}
            for e in range(1,6):
                err[ '%dxx' % e ] = int(data['server_zones'][upstream]['responses']['%dxx' % e])

            perfdata = '|'.join([ '%s=%d' % (x, count_req(upstream,x,err[x])  ) for x in err])

            if err['5xx'] >= critical:
                return [2, "CRITICAL - Servers with more than %d  5xx Errors" % err['5xx'], perfdata ]
            elif err['5xx'] >= warning:
                return [1, "WARNING - Servers with more than %d  5xx Errors" % err['5xx'], perfdata ]

            return [0, "OK - All servers are OK ", perfdata]

        else:
            return [2, "CRITICAL - Erro: server sent a response code %s " % str(r.status_code)]

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