aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/suricata/qa/sock_to_gzip_file.py
diff options
context:
space:
mode:
authorAshlee Young <ashlee@onosfw.com>2015-09-09 22:21:41 -0700
committerAshlee Young <ashlee@onosfw.com>2015-09-09 22:21:41 -0700
commit8879b125d26e8db1a5633de5a9c692eb2d1c4f83 (patch)
treec7259d85a991b83dfa85ab2e339360669fc1f58e /framework/src/suricata/qa/sock_to_gzip_file.py
parent13d05bc8458758ee39cb829098241e89616717ee (diff)
suricata checkin based on commit id a4bce14770beee46a537eda3c3f6e8e8565d5d0a
Change-Id: I9a214fa0ee95e58fc640e50bd604dac7f42db48f
Diffstat (limited to 'framework/src/suricata/qa/sock_to_gzip_file.py')
-rwxr-xr-xframework/src/suricata/qa/sock_to_gzip_file.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/framework/src/suricata/qa/sock_to_gzip_file.py b/framework/src/suricata/qa/sock_to_gzip_file.py
new file mode 100755
index 00000000..4c51782e
--- /dev/null
+++ b/framework/src/suricata/qa/sock_to_gzip_file.py
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+#I love the python Power Glove. It's so bad!
+#Usage: sudo -u suricata ./sock_to_gzip_file.py --output-file="http.log.gz" --listen-sock="http.log.sock"
+
+import socket,os
+import gzip
+import sys
+from optparse import OptionParser
+
+if __name__ == "__main__":
+ parser = OptionParser()
+ #Path to the socket
+ parser.add_option("--listen-sock", dest="lsock", type="string", help="Path to the socket we will listen on.")
+ #Path to gzip file we will write
+ parser.add_option("--output-file", dest="output", type="string", help="Path to file name to output gzip file we will write to.")
+
+ #parse the opts
+ (options, args) = parser.parse_args()
+
+ options.usage = "example: sudo -u suricata ./sock_to_gzip_file.py --output-file=\"http.log.gz\" --listen-sock=\"http.log.sock\"\n"
+ #Open the output file
+ if options.output:
+ try:
+ f = gzip.open(options.output, 'wb')
+ except Exception,e:
+ print("Error: could not open output file %s:\n%s\n", options.output, e)
+ sys.exit(-1)
+ else:
+ print("Error: --output-file option required and was not specified\n%s" % (options.usage))
+ sys.exit(-1)
+
+ #Open our socket and bind
+ if options.lsock:
+ if os.path.exists(options.lsock):
+ try:
+ os.remove(options.lsock)
+ except OSError:
+ pass
+ try:
+ s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ s.bind(options.lsock)
+ s.listen(1)
+ conn, addr = s.accept()
+ except Exception,e:
+ print("Error: Failed to bind socket %s\n%s\n", options.lsock, e)
+ sys.exit(-1)
+ else:
+ print("Error: --listen-sock option required and was not specified\n%s" % (options.usage))
+ sys.exit(-1)
+
+ #Read data from the socket and write to the file
+ while 1:
+ data = conn.recv(1024)
+ if not data: break
+ f.write(data)
+ conn.close()
+ f.close()