summaryrefslogtreecommitdiff
path: root/haircontrol/inspectors.py
diff options
context:
space:
mode:
Diffstat (limited to 'haircontrol/inspectors.py')
-rw-r--r--haircontrol/inspectors.py40
1 files changed, 35 insertions, 5 deletions
diff --git a/haircontrol/inspectors.py b/haircontrol/inspectors.py
index 33bf360..f59287a 100644
--- a/haircontrol/inspectors.py
+++ b/haircontrol/inspectors.py
@@ -1,4 +1,5 @@
import re
+import json
import xml.etree.ElementTree
class Inspector():
@@ -68,7 +69,7 @@ class LinuxInspector(Inspector):
'ip-link': {
'cmd': 'ip -o link',
'kind': 'text',
- 're': re.compile("(?P<id>\d+):\s+(?P<ifname>[^:]*):.+\s+(?:link/ether\s+(?P<mac>[a-f0-9:]*)\s+brd|link/none)")
+ 're': re.compile("\d+:\s+(?P<ifname>[^:]*):.+\s+(?:link/ether\s+(?P<mac>[a-f0-9:]*)\s+brd|link/none)")
# 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default \ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
# 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000\ link/ether 8c:89:a5:c7:be:88 brd ff:ff:ff:ff:ff:ff
},
@@ -103,21 +104,50 @@ class LinuxInspector(Inspector):
class UbntInspector(Inspector):
+ def _parse_cgi_json(self, fd):
+ for cgi_headers in fd:
+ if cgi_headers == '\n':
+ break
+ js = {}
+ try:
+ js = json.load(fd)
+ except ValueError:
+ print("Warn : unparsable json")
+ fd.close()
+ return js
+
def parse_status_json(self, fd):
- return 'parse_status_json'
+ result = []
+ interfaces = self._parse_cgi_json(fd).get('interfaces')
+ # XXX dup parse_brmacs_json(fd) and many other cool info to get
+ if interfaces:
+ for line in interfaces:
+ if isinstance(line, dict):
+ ifname = line.get('ifname')
+ mac = line.get('hwaddr')
+ result.append( (ifname, mac) )
+ return result
def parse_brmacs_json(self, fd):
- return 'parse_brmacs_json'
+ result = []
+ brmacs = self._parse_cgi_json(fd).get('brmacs')
+ if brmacs:
+ for line in brmacs:
+ if isinstance(line, dict):
+ ifname = line.get('port')
+ mac = line.get('hwaddr')
+ result.append( (ifname, mac) )
+ return result
+
cmds = {
'status.cgi': {
'cmd':'..',
- 'kind': 'cgi-json',
'func': parse_status_json
},
'brmacs.cgi': {
'cmd':'..',
- 'kind': 'cgi-json',
'func': parse_brmacs_json
}
}
+