]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricatasc: handle exceptions interactive mode
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 22 Jun 2023 08:17:37 +0000 (13:47 +0530)
committerVictor Julien <vjulien@oisf.net>
Tue, 27 Jun 2023 07:33:49 +0000 (09:33 +0200)
python/suricata/sc/suricatasc.py

index d4f15fdd45a07ee64ba6c138b2215a2d4685e36e..b1a8d7f41eaf44b536f960a42b9d15ee4da18ab6 100644 (file)
@@ -1,5 +1,5 @@
 #!/usr/bin/python
-# Copyright(C) 2012-2020 Open Information Security Foundation
+# Copyright(C) 2012-2023 Open Information Security Foundation
 
 # 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
@@ -237,7 +237,7 @@ class SuricataSC:
             if cmd in self.fn_commands:
                 cmd, arguments = getattr(self, "execute")(command=command)
         else:
-            raise SuricataCommandException("Unknown command {}".format(command))
+            raise SuricataCommandException("Unknown command: {}".format(command))
         return cmd, arguments
 
     def interactive(self):
@@ -266,10 +266,13 @@ class SuricataSC:
                     try:
                         self.close()
                         self.connect()
-                    except SuricataNetException as err:
-                        print("Can't reconnect to suricata socket, discarding command")
+                    except (SuricataNetException, SuricataReturnException) as err:
+                        print(err.value)
                         continue
                     cmdret = self.send_command(cmd, arguments)
+                except (SuricataCommandException, SuricataReturnException) as err:
+                    print("An exception occured: " + str(err.value))
+                    continue
                 #decode json message
                 if cmdret["return"] == "NOK":
                     print("Error:")