-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcommand_parser.py
62 lines (49 loc) · 1.78 KB
/
command_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'Jason/GeW'
import json
import time
import psutil
import platform
SYSTEM_CMD = []
APP_CMD = []
INIT = False
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S %z"
class BaseCommand(object):
key = ''
type = ''
request_type = ''
response_type = ''
def __init__(self) -> None:
super().__init__()
pass
def load_commands(path):
global SYSTEM_CMD, APP_CMD
with open(path, 'r') as cmd_file:
cmd = json.load(cmd_file)
SYSTEM_CMD = dict(cmd).get('system')
APP_CMD = dict(cmd).get('app')
def show_system_status():
status_info = {'os': platform.uname().system,
'core': psutil.cpu_count(),
'processor': platform.uname().processor,
'cpuUsage': psutil.cpu_percent(),
'hostname': platform.uname().node, # For Secure Purpose, May Need to Remove
'memoryUnit': "MB",
'totalMemory': int(psutil.virtual_memory().total / (1024 * 1024)),
'usedMemory': int(psutil.virtual_memory().used / (1024 * 1024)),
'memoryUsage': psutil.virtual_memory().percent,
'usageUnit': "%",
'offsetDateTime': time.strftime(DATETIME_FORMAT, time.localtime(time.time()))}
network_info = {}
addresses = psutil.net_if_addrs()
for interface_name, interface_addresses in addresses.items():
for address in interface_addresses:
if str(address.family) == 'AddressFamily.AF_INET':
network_info[interface_name] = address.address
status_info.update(network_info)
return status_info
# Test Only
if __name__ == '__main__':
load_commands('config/commands.json')
print(show_system_status())