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_site_24x7.py
import requests
import json
import time

def getcontent(endpoint, token):
    start = time.time()
    headers = {
        'Authorization': 'Zoho-authtoken {0}'.format(token),
        'Accept': 'application/json; version=2.0'
    }
    url = 'https://www.site24x7.com/api/{0}'.format(endpoint)
    response = requests.get(url, headers=headers)
    roundtrip = time.time() - start
    return(response)


def getallstatus(token):
    response = response = getcontent('current_status', token)

    if response.status_code == 200:
        data = response.json()
        if data:
            with open("/omd/sites/ft_ed/tmp/site_24x7.json", "w") as fh:
                fh.write(json.dumps(data.get('data', dict()).get('monitor_groups'), indent=2))
                return(True)

    return(False)

def getmonitor(item, token):
    with open("/omd/sites/ft_ed/tmp/site_24x7.json") as fh:
        monitors = json.load(fh)
        for monitor in monitors:
            site = [i for i in monitor.get('monitors') if i.get('name', '') == item]
            if site:
                return(site[0])
    return(False)

def getmoreinfo(monitor_id, token):
    #monitorinfo = getcontent('monitors/{0}'.format(monitor_id), token)
    monitorinfo = getcontent('current_status/{0}'.format(monitor_id), token)

    if monitorinfo.status_code == 200:
        data = monitorinfo.json()
        return(data)
    return(False)

def tracetoint(trace):
    try:
        return(int(trace))
    except ValueError:
        return(0)


def __run__(params):
    site = getmonitor(params.get("site"), params.get("token"))
    infos = getmoreinfo(site.get("monitor_id"), params.get("token"))
    response_time = [
        '{0} = {1} ms'.format(location.get('location_name'), tracetoint(location.get('attribute_value', 0)) / 1000) for location in infos.get('data').get('locations')
    ]

    if infos.get('data').get('status') == 1:
        return([0, ', '.join(response_time)])
    elif infos.get('data').get('status') == 0:
        return([2, ', '.join(response_time)])
    else:
        return([1, ', '.join(response_time)])


if __name__ == '__main__':
    params = {
       "site": "IPI - KMV",
       "token": "f1886e11ef6c5466c7a3ef129376ee06"
    }

    print __run__(params)