Skip to content

Instantly share code, notes, and snippets.

@sughodke
Created September 24, 2017 19:17
Show Gist options
  • Select an option

  • Save sughodke/a50c427853dfbc53eca68da8a62af11c to your computer and use it in GitHub Desktop.

Select an option

Save sughodke/a50c427853dfbc53eca68da8a62af11c to your computer and use it in GitHub Desktop.
ActivityWatch plugin for osquery
#!/usr/bin/env python
import osquery
import requests
headers = {
'Accept': 'application/json',
}
URL = 'http://localhost:5600/api/0/' \
'buckets/aw-watcher-window_Beaker-2.local/events'
@osquery.register_plugin
class MyTablePlugin(osquery.TablePlugin):
def name(self):
return "aw_window"
def columns(self):
return [
osquery.TableColumn(name="timestamp", type=osquery.STRING),
osquery.TableColumn(name="title", type=osquery.STRING),
osquery.TableColumn(name="app", type=osquery.STRING),
osquery.TableColumn(name="duration", type=osquery.STRING),
]
def generate(self, context):
query_data = []
r = requests.get(URL, headers=headers)
for row in r.json():
row.update(row['data'])
row['duration'] = str(row['duration'])
del row['id']
del row['data']
query_data.append(row)
return query_data
if __name__ == "__main__":
osquery.start_extension(name="activitywatch-window",
version="1.0.0",)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment