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
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
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
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
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
def python_get(): # noqa: E501 key = util.key() if key == 401: return 'Invalid key', 401 return platform.python_version()
def la_get(): # noqa: E501 key = util.key() if key == 401: return 'Invalid key', 401 load = json.dumps(os.getloadavg()) return load
def hostname_get(): # noqa: E501 key = util.key() if key == 401: return 'Invalid key', 401 fqdn = socket.getfqdn() return fqdn
def agent_get(): # noqa: E501 key = util.key() if key == 401: return 'Invalid key', 401 return config.ver
def key_get(): # noqa: E501 key = util.key() if key == 401: return 'Invalid key', 401 return 'Authorized', 200