我正在使用 osquery-go 构建一个osquery扩展,它为 osqueryi 提供一个虚拟表。我的表需要WHERE
针对特定字段的子句来生成结果。我把桌子的规格放在哪里?
正如 osquery 的文档中所述,规范通常在规范源文件夹中提供。但是对于扩展,我不知道该怎么做。
我使用osquery-go上提供的示例作为起点,它运行良好。我也可以使用约束过滤输入,但我想得到一个警告,而不是没有结果:
func MyTableGenerate(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) {
if cnstList, present := queryContext.Constraints["field1"]; present {
// If 'field1' is present in queryContext.Contraints's keys
// translate: if 'field1' is in the WHERE clause
for _, cnst := range cnstList.Constraints {
if cnst.Operator == table.OperatorEquals {
out, err := SomeExternalFn(cnst.Expression)
return []map[string]string{
{
"field1": cnst.Expression,
"field2": out,
"field3": err,
},
}, nil
}
}
}
return nil, errors.New("Query to table MyTable must have a WHERE clause on 'field1'")
}
在 osqueryi 中:
osquery> select * from MyTable;
osquery> select * from MyTable where field1="foo";
+--------+--------+--------+
| field1 | field2 | field3 |
+--------+--------+--------+
| foo | foobar | foobaz |
+--------+--------+--------+
我所寻求的:
osquery> select * from file;
W0618 11:50:58.840874 7252 virtual_table.cpp:991] Table file was queried without a required column in the WHERE clause
W0618 11:50:58.841397 7252 virtual_table.cpp:1002] Please see the table documentation: https://osquery.io/schema/#file