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_vpn_ipsec.py
import subprocess
import yaml
import re


def ipsec():
    command = "/usr/bin/sudo /usr/sbin/ipsec auto --status"
    process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = process.communicate()
    return(out)


def get_ip_vip(ipvip):
    ifconfig = subprocess.Popen("/sbin/ifconfig", stdout=subprocess.PIPE)
    out, err = ifconfig.communicate()
    hasvip = re.search(r"(.*) addr:{0} (.*)".format(ipvip), out)
    return(True if hasvip else False)


def ping(ipvip):
    command = "/bin/ping -c 1 -W 1 {0}".format(ipvip)
    ping = subprocess.call(command.split(), stdout=subprocess.PIPE)
    return(True if ping == 0 else False)


def __run__(params):
    connection = params.get("connection")
    tunel = params.get("tunel")
    client = params.get("client")
    ipvip = params.get("ipvip")

    if not connection or not tunel or not client or not ipvip:
        return([2, "Parametros para monitoracao ausentes do YAML, por favor verifique!"])

    try:
        alive = ping(ipvip)
        ipesecstatus = ipsec()
        check = re.search(r'(.*): "{0}(.*)" (.*) {1}'.format(connection, tunel), ipesecstatus)

        if not get_ip_vip(ipvip):
            if not alive:
               return([2, "IP VIP Down"])
            else:
               return([0, "Servidor em Stand by."])

        if not check:
            return([2, "Error: Problema com o Tunel IPsec LWO x {0}".format(client)])
        else:
            return([0, "OK: Tunel IPsec LWO Unik x {0}".format(client)])
    except Exception, err:
        return([2, err])


if __name__ == "__main__":
    yamlfile = yaml.load(open("/etc/locaweb/monitoring/unk.yaml"))
    options = yamlfile.get("monitoring")[-1]
    status = __run__(options)
    print status