Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions netdiff/parsers/openvpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def parse(self, data):
# add clients in graph as nodes
for client in data.client_list.values():
client_properties = {
'label': client.common_name,
'real_address': str(client.real_address.host),
'port': client.real_address.port,
'connected_since': client.connected_since.strftime('%Y-%m-%dT%H:%M:%SZ'),
Expand Down
4 changes: 2 additions & 2 deletions tests/static/openvpn-2-links.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
OpenVPN CLIENT LIST
Updated,Thu Jun 18 08:12:15 2015
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
node1,87.18.10.87:49502,334948,1973012,Thu Jun 18 04:23:03 2015
node2,93.40.230.50:64169,1817262,28981224,Thu Jun 18 04:08:39 2015
nodeA,87.18.10.87:49502,334948,1973012,Thu Jun 18 04:23:03 2015
nodeB,93.40.230.50:64169,1817262,28981224,Thu Jun 18 04:08:39 2015
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
192.168.255.134,node1,87.18.10.87:49502,Thu Jun 18 08:12:09 2015
Expand Down
20 changes: 10 additions & 10 deletions tests/static/openvpn-5-links-tap.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
OpenVPN CLIENT LIST
Updated,Fri Oct 20 12:52:38 2017
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
Kali-Matera,2.226.154.66:45641,126345570,264437194,Sun Oct 15 11:03:54 2017
Kali-Oppido,93.40.230.50:37394,3625584,7923472,Fri Oct 20 09:16:31 2017
rosario,95.250.161.57:53084,5742,382894,Fri Oct 20 12:45:30 2017
Syskrack,79.18.21.144:63859,481360,33208728,Fri Oct 20 00:20:32 2017
pomezia,87.3.36.166:60485,395226,33194538,Fri Oct 20 00:20:27 2017
nodeA,2.226.154.66:45641,126345570,264437194,Sun Oct 15 11:03:54 2017
nodeB,93.40.230.50:37394,3625584,7923472,Fri Oct 20 09:16:31 2017
nodeC,95.250.161.57:53084,5742,382894,Fri Oct 20 12:45:30 2017
nodeD,79.18.21.144:63859,481360,33208728,Fri Oct 20 00:20:32 2017
nodeE,87.3.36.166:60485,395226,33194538,Fri Oct 20 00:20:27 2017
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
46:8a:69:e7:46:24,Kali-Matera,2.226.154.66:45641,Fri Oct 20 12:52:26 2017
c0:4a:00:2d:05:fc,pomezia,87.3.36.166:60485,Fri Oct 20 12:52:26 2017
aa:c5:99:28:91:a4,rosario,95.250.161.57:53084,Fri Oct 20 12:52:26 2017
c4:6e:1f:ff:02:23,Kali-Oppido,93.40.230.50:37394,Fri Oct 20 12:52:26 2017
9e:c2:f2:55:f4:33,Syskrack,79.18.21.144:63859,Fri Oct 20 12:52:26 2017
46:8a:69:e7:46:24,nodeA,2.226.154.66:45641,Fri Oct 20 12:52:26 2017
c0:4a:00:2d:05:fc,nodeE,87.3.36.166:60485,Fri Oct 20 12:52:26 2017
aa:c5:99:28:91:a4,nodeC,95.250.161.57:53084,Fri Oct 20 12:52:26 2017
c4:6e:1f:ff:02:23,nodeB,93.40.230.50:37394,Fri Oct 20 12:52:26 2017
9e:c2:f2:55:f4:33,nodeD,79.18.21.144:63859,Fri Oct 20 12:52:26 2017
GLOBAL STATS
Max bcast/mcast queue length,6
END
18 changes: 18 additions & 0 deletions tests/test_openvpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def test_json_dict(self):
self.assertIsInstance(data['links'], list)
self.assertEqual(len(data['nodes']), 3)
self.assertEqual(len(data['links']), 2)
# check presence of labels
labels = []
for node in data['nodes']:
if 'label' in node:
labels.append(node['label'])
self.assertEqual(len(labels), 2)
self.assertIn('nodeA', labels)
self.assertIn('nodeB', labels)

def test_json_dict_tap(self):
p = OpenvpnParser(links2_tap)
Expand All @@ -44,3 +52,13 @@ def test_json_dict_tap(self):
self.assertIsInstance(data['links'], list)
self.assertEqual(len(data['nodes']), 6)
self.assertEqual(len(data['links']), 5)
labels = []
for node in data['nodes']:
if 'label' in node:
labels.append(node['label'])
self.assertEqual(len(labels), 5)
self.assertIn('nodeA', labels)
self.assertIn('nodeB', labels)
self.assertIn('nodeC', labels)
self.assertIn('nodeD', labels)
self.assertIn('nodeE', labels)