diff options
author | Daniil Baturin <daniil@baturin.org> | 2018-12-31 14:30:46 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2018-12-31 14:30:46 +0100 |
commit | 77d7e727faa5725735fd2b7742722a3f7f71d52f (patch) | |
tree | a29deba34f6ea07434886b2c86051cd45e40d04b /src/op_mode | |
parent | fc5f75c23fa3c7f93e982433705ab8971dbbabff (diff) | |
parent | d50524722819582cc1d7ad289d12e9f585f701de (diff) | |
download | vyos-1x-77d7e727faa5725735fd2b7742722a3f7f71d52f.tar.gz vyos-1x-77d7e727faa5725735fd2b7742722a3f7f71d52f.zip |
Merge branch 'current' into crux
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/show_ipsec_sa.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/op_mode/show_ipsec_sa.py b/src/op_mode/show_ipsec_sa.py index 3c8d678eb..117824632 100755 --- a/src/op_mode/show_ipsec_sa.py +++ b/src/op_mode/show_ipsec_sa.py @@ -1,14 +1,21 @@ #!/usr/bin/env python3 import re +import sys import subprocess import tabulate import hurry.filesize def parse_conn_spec(s): - # Example: ESTABLISHED 14 seconds ago, 10.0.0.2[foo]...10.0.0.1[10.0.0.1] - return re.search(r'.*ESTABLISHED\s+(.*)ago,\s(.*)\[(.*)\]\.\.\.(.*)\[(.*)\].*', s).groups() + try: + # Example: ESTABLISHED 14 seconds ago, 10.0.0.2[foo]...10.0.0.1[10.0.0.1] + return re.search(r'.*ESTABLISHED\s+(.*)ago,\s(.*)\[(.*)\]\.\.\.(.*)\[(.*)\].*', s).groups() + except AttributeError: + # No active SAs found, so we have nothing to display + print("No established security associations found.") + print("Use \"show vpn ipsec sa\" to view inactive and connecting tunnels.") + sys.exit(0) def parse_ike_line(s): try: @@ -42,8 +49,8 @@ for conn in connections: enc, hash, dh, bytes_in, bytes_out = parse_ike_line(status) # Convert bytes to human-readable units - bytes_in = hurry.filesize.size(bytes_in) - bytes_out = hurry.filesize.size(bytes_out) + bytes_in = hurry.filesize.size(int(bytes_in)) + bytes_out = hurry.filesize.size(int(bytes_out)) status_line = [conn, "up", time, "{0}/{1}".format(bytes_in, bytes_out), ip, id, "{0}/{1}/{2}".format(enc, hash, dh)] except Exception as e: |