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/pmta.py
from subprocess import Popen, PIPE
import yaml

def __run__(params):
    try:
        thresholds = yaml.load(params.get('thresholds'))
    except Exception, e:
        return [2, "CRITICAL - Error: %s" % repr(e)]

#    infos = Popen(['sudo', 'pmta', 'show', 'status'], shell=False, stdout=PIPE, stderr=PIPE)
    infos = Popen(['pmta', 'show', 'status'], shell=False, stdout=PIPE, stderr=PIPE)

    error = ' '.join(infos.stderr.readlines()).strip('\n')
    result = [ line.split() for line in infos.stdout.readlines() if line.strip() ]

    if error:
        return [2, 'CRITICAL - %s' % repr(error)]

    if result:
        status = {}
        for line in result:
            if 'PowerMTA' in line or 'Inbound' in line:
                if 'PowerMTA' in line:
                    status['version'] = line[1]
                elif 'Inbound' in line:
                    status['cur'] = line[1]
                    status['max'] = line[3]

    percent = (float(status['cur']) / float(status['max']) * 100)

    if percent > thresholds['critical']:
        return [2, 'CRITICAL: {0}% of connections in use' % format(percent)]
    elif percent > thresholds['warning']:
        return [1, 'WARNING: {0}% of connections in use' % format(percent)]
    else:
        return [0, 'OK - PowerMTA version: %(version)s, %(cur)s of %(max)s connections' % status]