suricatasc: handle exceptions in caller

(cherry picked from commit 46ce371d9c)
pull/9139/head
Shivani Bhardwaj 3 years ago committed by Victor Julien
parent 1ca730febe
commit 8ddbcb1f01

@ -1,6 +1,6 @@
#! /usr/bin/env python #! /usr/bin/env python
# #
# Copyright(C) 2013-2022 Open Information Security Foundation # Copyright(C) 2013-2023 Open Information Security Foundation
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -69,8 +69,16 @@ except SuricataReturnException as err:
sys.exit(1) sys.exit(1)
if args.command: if args.command:
(command, arguments) = sc.parse_command(args.command) try:
res = sc.send_command(command, arguments) (command, arguments) = sc.parse_command(args.command)
except SuricataCommandException as err:
print(err.value)
sys.exit(1)
try:
res = sc.send_command(command, arguments)
except (SuricataCommandException, SuricataReturnException) as err:
print(err.value)
sys.exit(1)
print(json.dumps(res)) print(json.dumps(res))
sc.close() sc.close()
if res['return'] == 'OK': if res['return'] == 'OK':

Loading…
Cancel
Save