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/influxdata.py
import requests
import getpass
import socket
import numpy

def format_default(data):
    return str(data)

def format_seconds(data):
    return str(data) + " seconds"

def __run__(params):

    socket.setdefaulttimeout(10)

    query = {
        "db": params.get("database", getpass.getuser()),
        "q": params["query"],
    }

    try:
        response = requests.get("%s/query" % params.get("endpoint", "http://influxdb-ha.locaweb.com.br"), params=query).json()
    except Exception, e:
        return [2, "CRITICAL - Error: %s" % repr(e)]

    data = []
    for result in response["results"]:
        for serie in result["series"]:
            for timestamp, value in serie["values"]:
                try:
                    data.append(float(value))
                except:
                    continue

    data = numpy.percentile(data, params.get("percentile", 50))

    prio = 6
    alert = False
    for priority, threshold in params.get('thresholds', {}).iteritems():
        if priority <= prio and data > threshold:
            prio = priority
            alert = True


    format_function = eval(params.get("format_function", "format_default"))

    if alert:
        return [2, "CRIT,Priority:%s - Current value is %s" % (prio, format_function(data))]
    else:
        return [0, "OK - Current value is %s" % format_function(data)]

if __name__ == '__main__':
    print __run__({
        "query": """SELECT percentile("delivery_delay_percentil", 95) FROM "isrcd" WHERE "cluster" = 'simpsons0035' AND time > now() - 10m GROUP BY time(1m) fill(null)""",
        "database": "ft_email",
        "percentile": 95,
        "thresholds": {
            2: 30,
            3: 20
        },
        "format_function": "format_seconds",
    })