aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-01-09 00:47:53 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-01-09 00:47:53 +1300
commit40ae8895be108e14ec1673cfd88031f82b4cf6f4 (patch)
treebe08c3150fb047f2bcfb21fda0461699ae91ffca /tools
parent7b76fff97296de895541449a3a66665d4e0f65ad (diff)
downloadtraccar-server-40ae8895be108e14ec1673cfd88031f82b4cf6f4.tar.gz
traccar-server-40ae8895be108e14ec1673cfd88031f82b4cf6f4.tar.bz2
traccar-server-40ae8895be108e14ec1673cfd88031f82b4cf6f4.zip
Implement a script to re-send data from log
Diffstat (limited to 'tools')
-rwxr-xr-xtools/recover.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/recover.py b/tools/recover.py
new file mode 100755
index 000000000..01e01f92e
--- /dev/null
+++ b/tools/recover.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+import sys
+import re
+import socket
+import binascii
+
+if len(sys.argv) < 2:
+ sys.exit("log file is not provided")
+
+path = sys.argv[1]
+p = re.compile(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} DEBUG: \[([0-9a-fA-F]{8}): (\d+) < [\d.]+] HEX: ([0-9a-fA-F]+)")
+
+ports = {}
+messages = {}
+
+for line in open(path):
+ if "HEX:" in line:
+ m = p.match(line)
+ if m:
+ session = m.group(1)
+ port = m.group(2)
+ message = m.group(3)
+ ports[session] = port
+ if session not in messages:
+ messages[session] = []
+ messages[session].append(message)
+
+for session in ports:
+ port = ports[session]
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.connect(("localhost", int(port)))
+ for message in messages[session]:
+ s.send(binascii.unhexlify(message))
+ s.close()