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/check_ping_ed.py
import subprocess
import re


def run_ping(host, count):
    command = "/bin/ping -f -q -c {0} -n {1}".format(count, host)
    process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    ping = process.communicate()
    return(ping)


def get_interface(interface):
    if interface:
        process = subprocess.Popen("/sbin/ifconfig", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        ifconfig = process.communicate()
        hasinterface = [x for x in ifconfig[0].split() if x == interface]
        return(hasinterface)


def __run__(params):
    try:
        intout = params.get("interface", False)
        remoteaddr = params.get("ip", False)
        maxloss = params.get("maxloss", 50)
        maxtime = params.get("maxtime", 3000)
        interface = get_interface(intout) if intout else False

        if not remoteaddr:
            return([2, "Verifique o YAML e informe os valores para IP/HOST?"])

        elif not interface:
            return([0, "Interface desconhecida - Servidor Stand-by."])

        else:
            ping = run_ping(remoteaddr, 10)
            loss = re.search(r"\d%", ping[0])
            time = re.search(r"\dms", ping[0])

            if int(loss.group().replace("%", "")) <= maxloss and int(time.group().replace("ms", "")) <= maxtime:
                return([0, "OK - Perda de Pacotes: {0} - Latencia: {1}".format(loss.group(), time.group())])
            else:
                return([2, "Perda de Pacotes: {0} - Latencia: {1}".format(loss.group(), time.group())])

    except Exception, err:
        return([2, err])