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_fortigate.py
import json
from FgSNMP import FortiGet, SimpleSNMP

def bytes_to_human(value, suffix='B'):
    for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
        if abs(value) < 1024.0:
            return "%3.1f%s%s" % (value, unit, suffix)
        value /= 1024.0
    return "%.1f%s%s" % (value, 'Yi', suffix)

def __run__(params):
    vdom = params.get("vdom")
    vpn = params.get("vpn")
    user = params.get("snmp_user")
    host = params.get("fortigate")
    password = params.get("snmp_password")

    fortigate = FortiGet()
    mysnmp = SimpleSNMP()
    failed = []

    if not all([vdom, vdom, user, host, host, host]):
        return([2, "Check your YAML file"])

    try:
        with open("/tmp/vpns.json") as temp:
            history = json.load(temp)

        for phase, infos in history.get(vdom).get(vpn).iteritems():
            vpnid = infos.get("id")
            outdata = infos.get("outdata")
            indata = infos.get("indata")
            status = fortigate.get_vpn_status(vpnid, mysnmp, user, password, host)

            if not "up" in status and phase:
                failed.append(str(phase))

        if failed:
            return([2, ', '.join(failed)])
        else:
            return([0, "Input Bytes: %s, Output Bytes: %s" % (bytes_to_human(int(indata)), bytes_to_human(int(outdata)))])

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