Skip to content

Commit 4ebdea6

Browse files
authored
Added a label in OpenvpnParser output (#55)
Closes #50
1 parent a128b19 commit 4ebdea6

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

netdiff/parsers/openvpn.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def parse(self, data):
2828
# add clients in graph as nodes
2929
for client in data.client_list.values():
3030
client_properties = {
31+
'label': client.common_name,
3132
'real_address': str(client.real_address.host),
3233
'port': client.real_address.port,
3334
'connected_since': client.connected_since.strftime('%Y-%m-%dT%H:%M:%SZ'),

tests/static/openvpn-2-links.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
OpenVPN CLIENT LIST
22
Updated,Thu Jun 18 08:12:15 2015
33
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
4-
node1,87.18.10.87:49502,334948,1973012,Thu Jun 18 04:23:03 2015
5-
node2,93.40.230.50:64169,1817262,28981224,Thu Jun 18 04:08:39 2015
4+
nodeA,87.18.10.87:49502,334948,1973012,Thu Jun 18 04:23:03 2015
5+
nodeB,93.40.230.50:64169,1817262,28981224,Thu Jun 18 04:08:39 2015
66
ROUTING TABLE
77
Virtual Address,Common Name,Real Address,Last Ref
88
192.168.255.134,node1,87.18.10.87:49502,Thu Jun 18 08:12:09 2015

tests/static/openvpn-5-links-tap.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
OpenVPN CLIENT LIST
22
Updated,Fri Oct 20 12:52:38 2017
33
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
4-
Kali-Matera,2.226.154.66:45641,126345570,264437194,Sun Oct 15 11:03:54 2017
5-
Kali-Oppido,93.40.230.50:37394,3625584,7923472,Fri Oct 20 09:16:31 2017
6-
rosario,95.250.161.57:53084,5742,382894,Fri Oct 20 12:45:30 2017
7-
Syskrack,79.18.21.144:63859,481360,33208728,Fri Oct 20 00:20:32 2017
8-
pomezia,87.3.36.166:60485,395226,33194538,Fri Oct 20 00:20:27 2017
4+
nodeA,2.226.154.66:45641,126345570,264437194,Sun Oct 15 11:03:54 2017
5+
nodeB,93.40.230.50:37394,3625584,7923472,Fri Oct 20 09:16:31 2017
6+
nodeC,95.250.161.57:53084,5742,382894,Fri Oct 20 12:45:30 2017
7+
nodeD,79.18.21.144:63859,481360,33208728,Fri Oct 20 00:20:32 2017
8+
nodeE,87.3.36.166:60485,395226,33194538,Fri Oct 20 00:20:27 2017
99
ROUTING TABLE
1010
Virtual Address,Common Name,Real Address,Last Ref
11-
46:8a:69:e7:46:24,Kali-Matera,2.226.154.66:45641,Fri Oct 20 12:52:26 2017
12-
c0:4a:00:2d:05:fc,pomezia,87.3.36.166:60485,Fri Oct 20 12:52:26 2017
13-
aa:c5:99:28:91:a4,rosario,95.250.161.57:53084,Fri Oct 20 12:52:26 2017
14-
c4:6e:1f:ff:02:23,Kali-Oppido,93.40.230.50:37394,Fri Oct 20 12:52:26 2017
15-
9e:c2:f2:55:f4:33,Syskrack,79.18.21.144:63859,Fri Oct 20 12:52:26 2017
11+
46:8a:69:e7:46:24,nodeA,2.226.154.66:45641,Fri Oct 20 12:52:26 2017
12+
c0:4a:00:2d:05:fc,nodeE,87.3.36.166:60485,Fri Oct 20 12:52:26 2017
13+
aa:c5:99:28:91:a4,nodeC,95.250.161.57:53084,Fri Oct 20 12:52:26 2017
14+
c4:6e:1f:ff:02:23,nodeB,93.40.230.50:37394,Fri Oct 20 12:52:26 2017
15+
9e:c2:f2:55:f4:33,nodeD,79.18.21.144:63859,Fri Oct 20 12:52:26 2017
1616
GLOBAL STATS
1717
Max bcast/mcast queue length,6
1818
END

tests/test_openvpn.py

+18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ def test_json_dict(self):
3030
self.assertIsInstance(data['links'], list)
3131
self.assertEqual(len(data['nodes']), 3)
3232
self.assertEqual(len(data['links']), 2)
33+
# check presence of labels
34+
labels = []
35+
for node in data['nodes']:
36+
if 'label' in node:
37+
labels.append(node['label'])
38+
self.assertEqual(len(labels), 2)
39+
self.assertIn('nodeA', labels)
40+
self.assertIn('nodeB', labels)
3341

3442
def test_json_dict_tap(self):
3543
p = OpenvpnParser(links2_tap)
@@ -44,3 +52,13 @@ def test_json_dict_tap(self):
4452
self.assertIsInstance(data['links'], list)
4553
self.assertEqual(len(data['nodes']), 6)
4654
self.assertEqual(len(data['links']), 5)
55+
labels = []
56+
for node in data['nodes']:
57+
if 'label' in node:
58+
labels.append(node['label'])
59+
self.assertEqual(len(labels), 5)
60+
self.assertIn('nodeA', labels)
61+
self.assertIn('nodeB', labels)
62+
self.assertIn('nodeC', labels)
63+
self.assertIn('nodeD', labels)
64+
self.assertIn('nodeE', labels)

0 commit comments

Comments
 (0)