suricatasc: implement autoreconnect

Implement a basic autoreconnect support. It tries to reconnect once
when connection has been lost. If it fails, it discards the command
and try again to connect at next command.
pull/3209/head
Eric Leblond 10 years ago committed by Victor Julien
parent 3d0ba36ba8
commit 3c68a22092

@ -375,7 +375,17 @@ class SuricataSC:
except SuricataCommandException as err:
print(err)
continue
cmdret = self.send_command(cmd, arguments)
try:
cmdret = self.send_command(cmd, arguments)
except IOError as err:
# try to reconnect and resend command
print("Connection lost, trying to reconnect")
try:
self.connect()
except SuricataNetException as err:
print("Can't reconnect to suricata socket, discarding command")
continue
cmdret = self.send_command(cmd, arguments)
#decode json message
if cmdret["return"] == "NOK":
print("Error:")

Loading…
Cancel
Save