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: //lib/python2.7/site-packages/lap/doveadm_stats.py
#!/usr/bin/python
import os
import time
import redis
import datetime
import commands

cache = '/var/cache/stats.dump'

def parse_data(data):
    headers = None
    info = {}
    for line in data:
        line = line.strip().split()
        if not headers:
            headers = line
            continue

        key = line[0]
        info[key] = {}
        for idx, val in enumerate(headers):
            info[key][val] = line[idx]
    return info

def load_from_cache():
    if os.path.isfile(cache):
        data = open(cache).readlines()
        return parse_data(data)
    return {}

def save_cache(data):
    open(cache, 'w').write(data)


def __run__(params):

    stats = commands.getstatusoutput('doveadm stats dump global')

    if stats[0] != 0:
        return [3, "UNKNOWN: %s" % stats[1] ]

    cached = load_from_cache()
    new = {}

    # get cache lifetime
    if os.path.isfile(cache):
        lifetime = (time.time() - os.stat(cache).st_mtime)
    else:
        lifetime = 0

    if lifetime > 0:
        for key, info in parse_data(stats[1].split('\n')).iteritems():
            # Check cached
            if key in cached:
                new[key] = {}
                for k, v in info.iteritems():
                    try:
                        new[key][k] = ((float(v) - float(cached[key][k])) / lifetime) * 60
                    except ValueError:
                        continue

    save_cache(stats[1])

    perfdata = []
    for i in new.values():
        [ perfdata.append((k, str(v))) for k, v in i.iteritems() ]
    perfdata = "|".join([ "=".join(x) for x in perfdata])

    return [0, "OK: Stats", perfdata]