From: Eric Leblond Date: Sat, 6 Sep 2014 09:46:21 +0000 (+0200) Subject: suricatasc: add -c flag to run command X-Git-Tag: suricata-2.1beta2~111 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7f68a255357a00355566c66fb381caceab14209b;p=thirdparty%2Fsuricata.git suricatasc: add -c flag to run command Add -c flag to run command given as argument and return the raw JSON result. For example, it is possible to run something like. $ suricatasc -c "iface-stat eth0" {'message': {'pkts': 17838352, 'drop': 0, 'invalid-checksums': 1}, 'return': 'OK'} --- diff --git a/scripts/suricatasc/suricatasc.in b/scripts/suricatasc/suricatasc.in index 459e6fead1..30d482dcd2 100755 --- a/scripts/suricatasc/suricatasc.in +++ b/scripts/suricatasc/suricatasc.in @@ -20,6 +20,7 @@ from suricatasc import * parser = argparse.ArgumentParser(prog='suricatasc', description='Client for Suricata unix socket') parser.add_argument('-v', '--verbose', action='store_const', const=True, help='verbose output (including JSON dump)') +parser.add_argument('-c', '--command', default=None, help='execute on single command and return JSON') parser.add_argument('socket', metavar='socket', nargs='?', help='socket file to connnect to', default=None) args = parser.parse_args() @@ -37,6 +38,13 @@ except SuricataNetException, err: except SuricataReturnException, err: print "Unable to negotiate version with server: %s" % (err) sys.exit(1) + +if args.command: + (command, arguments) = sc.parse_command(args.command) + print sc.send_command(command, arguments) + sc.close() + sys.exit(0) + try: sc.interactive() except SuricataNetException, err: