Skip to content

Commit 33c1d31

Browse files
committed
Simple tool to run queries using the API
``` $ sudo python examples/run.py "select * from time" ================================================================================ hour => 12 seconds => 39 timestamp => Tue Aug 25 19:09:39 2015 UTC unix_time => 1440529779 month => 8 weekday => Tuesday year => 2015 iso_8601 => 2015-08-25T19:09:39Z minutes => 9 day => 25 ================================================================================ ```
1 parent b1304d0 commit 33c1d31

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

examples/run.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
"""
3+
simple script which runs a query from stdin
4+
"""
5+
6+
import sys
7+
import osquery
8+
9+
if __name__ == "__main__":
10+
if len(sys.argv) != 2:
11+
print("Usage: %s \"query\"" % sys.argv[0])
12+
sys.exit(1)
13+
CLIENT = osquery.ExtensionClient()
14+
CLIENT.open()
15+
RESULTS = CLIENT.extension_client().query(sys.argv[1])
16+
if RESULTS.status.code != 0:
17+
print("Error running the query: %s" % RESULTS.status.message)
18+
sys.exit(1)
19+
20+
for row in RESULTS.response:
21+
print("=" * 80)
22+
for key, val in row.iteritems():
23+
print("%s => %s" % (key, val))
24+
if len(RESULTS.response) > 0:
25+
print("=" * 80)

0 commit comments

Comments
 (0)