我正在使用osquery-go构建一个 osquery 扩展,该扩展为osqueryi提供了一个虚拟表。我的表在特定字段上需要一个WHERE
子句才能生成结果。我的桌子规格放在哪里?
如osquery的documentation所述,通常在specs source文件夹中提供specs。但是对于扩展,我不知道该怎么做。
我以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
答案 0 :(得分:0)
返回错误而不是nil。
(伪代码)之类的东西
cnstList, present := queryContext.Constraints["field1"]
if !present {
return nil, errors.New("Missing required field1")
}
...
举一个真实的例子,看看启动器中的一些自定义表。例如https://github.com/kolide/launcher/blob/ca2b2a48fb7ee7a13892b3f9940d4e67ccd9d6de/pkg/osquery/table/slack_config.go#L88-L101