-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproc2json
More file actions
executable file
·56 lines (39 loc) · 959 Bytes
/
proc2json
File metadata and controls
executable file
·56 lines (39 loc) · 959 Bytes
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
#!/usr/bin/env python
"""Convert logical records from the indicated /proc/net file to JSON format"""
import sys
import ProcHandlers
import json
if sys.platform == "darwin":
print "MacOS doesn't have a '/proc' filesystem, quitting."
sys.exit(0)
QUALIFY = ""
if len(sys.argv) > 1:
TARGET = sys.argv[1]
else:
TARGET = "/proc/net/tcp"
if len(sys.argv) > 2:
CNAME = sys.argv[2]
else:
CNAME = TARGET
HANDLER = ProcHandlers.GET_HANDLER(CNAME)
ACTIVE = HANDLER(TARGET)
REC = 0
FIELD_LIST = dict()
FIELD_LIST[0] = { 'source' : TARGET }
for srec in ACTIVE:
if len(ACTIVE.field) > 0:
REC += 1
FIELD_LIST[REC] = dict()
for fname in ACTIVE.field:
FIELD_LIST[REC][fname] = ACTIVE.field[fname]
print json.dumps(FIELD_LIST, sort_keys=True, indent=4, separators=(',', ': '))
# ---
# pylint: disable=W0702
try:
sys.stdout.close()
except:
pass
try:
sys.stderr.close()
except:
pass