Esempio n. 1
0
def distr_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    dist = platform.linux_distribution()
    distinfo = {'distname': dist[0], 'version': dist[1], 'id': dist[2]}
    return distinfo    
Esempio n. 2
0
def ports_get():
    data = []
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    for c in psutil.net_connections(kind='inet'):
        laddr = "%s %s" % (c.laddr)
        data.append(laddr.split()[1])
    return list(set(data))
def mem_detail_get(detail):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401

    if detail == 'virtual':
        result = psutil.virtual_memory()
    elif detail == 'swap':
        result = psutil.swap_memory()
    return result
def disk_detail_get(detail):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    if detail == 'partitions':
        result = disk_detail()
    elif detail == 'disk_io_counters':
        result = psutil.disk_io_counters(perdisk=True)
    elif detail == 'disk_rw':
        result = disk_rw()
    return result
def net_detail_get(detail):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401

    if detail == 'addr':
        result = address_info()

    if detail == 'counters':
        result = net_counters()

    return result
def service_service_get(service):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401

    service = service.encode()
    output = subprocess.check_output(['ps', '-A'])
    if service in output:
        result = 1
    else:
        result = 0

    return result
def cpu_detail_get(detail):  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401

    if detail == 'info':
        result = cpuinfo()
    elif detail == 'cpu_times':
        result = psutil.cpu_times()
    elif detail == 'cpu_percent':
        result = psutil.cpu_percent(interval=1, percpu=True)
    elif detail == 'cpu_percent_total':
        result = psutil.cpu_percent(interval=1)
    elif detail == 'cpu_stats':
        result = psutil.cpu_stats()
    elif detail == 'cpu_freq':
        result = psutil.cpu_freq(percpu=True)

    return result
Esempio n. 8
0
def boot_time_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    boot_time = (datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S"))
    return boot_time
Esempio n. 9
0
def top5mem_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    top_mem = ([(p.pid, p.info) for p in sorted(psutil.process_iter(attrs=['name', 'memory_percent']), key=lambda p: p.info['memory_percent'])][-5:])
    return top_mem
Esempio n. 10
0
def top5cpu_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    top_cpu = ([(p.pid, p.info['name'], sum(p.info['cpu_times'])) for p in sorted(psutil.process_iter(attrs=['name', 'cpu_times']), key=lambda p: sum(p.info['cpu_times'][:2]))][-5:])
    return top_cpu
Esempio n. 11
0
def python_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    return platform.python_version()
Esempio n. 12
0
def la_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    load = json.dumps(os.getloadavg())
    return load
Esempio n. 13
0
def hostname_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    fqdn = socket.getfqdn()
    return fqdn
Esempio n. 14
0
def agent_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    return config.ver
Esempio n. 15
0
def key_get():  # noqa: E501
    key = util.key()
    if key == 401:
        return 'Invalid key', 401
    return 'Authorized', 200