Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion osquery/table_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from abc import ABCMeta, abstractmethod
from collections import namedtuple
import json
import logging

from osquery.extensions.ttypes import ExtensionResponse, ExtensionStatus
from osquery.plugin import BasePlugin
Expand All @@ -38,13 +39,24 @@ def call(self, context):
ctx = {}
if "context" in context:
ctx = json.dumps(context["context"])
rows = self.generate(ctx)
for i, row in enumerate(rows):
for key, value in row.items():
if not isinstance(value, basestring):
try:
rows[i][key] = str(value)
except ValueError as e:
rows[i][key] = ''
logging.error("Cannot convert key %s: %s" % (
i, key, str(e)))
return ExtensionResponse(
status=ExtensionStatus(code=0, message="OK",),
response=self.generate(ctx),)
response=rows)
elif context["action"] == "columns":
return ExtensionResponse(
status=ExtensionStatus(code=0, message="OK",),
response=self.routes(),)
return ExtensionResponse(code=1, message="Unknown action",)

def registry_name(self):
"""The name of the registry type for table plugins.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_table_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def columns(self):
return [
osquery.TableColumn(name="foo", type=osquery.STRING),
osquery.TableColumn(name="baz", type=osquery.STRING),
osquery.TableColumn(name="int", type=osquery.INTEGER),
]

def generate(self, context):
Expand All @@ -35,6 +36,7 @@ def generate(self, context):
row = {}
row["foo"] = "bar"
row["baz"] = "baz"
row["int"] = 42
query_data.append(row)

return query_data
Expand Down Expand Up @@ -64,6 +66,12 @@ def test_routes_are_correct(self):
"type": "TEXT",
"name": "baz",
},
{
"id": "column",
"op": "0",
"type": "INTEGER",
"name": "int",
},
]
osquery.ExtensionManager().add_plugin(MockTablePlugin)
mtp = MockTablePlugin()
Expand All @@ -77,10 +85,12 @@ def test_simple_call(self):
{
"foo": "bar",
"baz": "baz",
"int": "42",
},
{
"foo": "bar",
"baz": "baz",
"int": "42",
},
]
self.assertEqual(results.response, expected)
Expand Down