0

我正在使用 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
4

1 回答 1

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

于 2019-06-18T15:01:19.203 回答