创建实时查询 API
编辑创建实时查询 API
编辑[预览] 此功能为技术预览版,在未来的版本中可能会更改或删除。Elastic 将努力修复任何问题,但技术预览版中的功能不受官方 GA 功能的支持 SLA 的约束。 创建实时查询。
请求
编辑POST <kibana 主机>:<端口>/api/osquery/live_queries
POST <kibana 主机>:<端口>/s/<空间 ID>/api/osquery/live_queries
路径参数
编辑-
space_id
- (可选,字符串)空间的标识符。当 URL 中未提供
space_id
时,将使用默认空间。
请求体
编辑-
agent_ids
- (可选,数组)要在其上运行查询的代理 ID 列表。
-
agent_all
- (可选,布尔值)当
true
时,查询将在所有代理上运行。 -
agent_platforms
- (可选,数组)要在其上运行查询的代理平台列表。
-
agent_policy_ids
- (可选,数组)要在其上运行查询的代理策略 ID 列表。
-
query
- (可选,字符串)您要运行的 SQL 查询。
-
saved_query_id
- (可选,字符串)已保存查询的 ID。
-
ecs_mapping
- (可选,对象)将 osquery 结果列或静态值映射到 Elastic Common Schema (ECS) 字段。
-
pack_id
- (可选,字符串)您要运行的包的 ID。
-
alert_ids
- (可选,数组)与实时查询关联的警报 ID 列表。
-
case_ids
- (可选,数组)与实时查询关联的案例 ID 列表。
-
event_ids
- (可选,数组)与实时查询关联的事件 ID 列表。
-
metadata
- (可选,对象)与实时查询关联的自定义元数据对象。
-
timeout
- (可选,数字)超时时间,以秒为单位,在此时间后查询将停止运行。覆盖默认超时时间允许您支持需要更多时间才能完成的查询。默认和最小支持值为
60
。最大支持值为900
。
响应代码
编辑-
200
- 指示成功调用。
示例
编辑在所有受支持的代理上运行实时查询
TIP: `osquery_manager` integration has to be added to the agent policy.
$ curl -X POST api/osquery/live_queries \ { "query": "select * from uptime;", "ecs_mapping": { "host.uptime": { "field": "total_seconds" } }, "agent_all": true, "timeout": 120 }
API 返回实时查询对象
{ "data": { "action_id": "3c42c847-eb30-4452-80e0-728584042334", "@timestamp": "2022-07-26T09:59:32.220Z", "expiration": "2022-07-26T10:04:32.220Z", # after this time no more agents will run the query "type": "INPUT_ACTION", "input_type": "osquery", "agent_ids": [], "agent_all": true, "agent_platforms": [], "agent_policy_ids": [], "agents": ["16d7caf5-efd2-4212-9b62-73dafc91fa13"], # stores the actual queried agent IDs "user_id": "elastic", "metadata": { "execution_context": { "name": "osquery", "url": "/app/osquery/live_queries/new" } }, "queries": [ { "action_id": "609c4c66-ba3d-43fa-afdd-53e244577aa0", # unique ID of the query, use it when querying the live query API to get the single query results "id": "6724a474-cbba-41ef-a1aa-66aebf0879e2", # ID of the query, doesn't have to be unique "query": "select * from uptime;", "timeout": 120, "ecs_mapping": { "host.uptime": { "field": "total_seconds" } }, "agents": [ "16d7caf5-efd2-4212-9b62-73dafc91fa13" # stores the actual queried agent IDs ] } ] } }
在 Darwin 支持的代理上运行一个包
$ curl -X POST api/osquery/live_queries \ { "pack_id": "bbe5b070-0c51-11ed-b0f8-ad31b008e832" "agent_platforms": ["darwin"] }
API 返回实时查询对象
{ "data": { "action_id": "3c42c847-eb30-4452-80e0-728584042334", "@timestamp": "2022-07-26T09:59:32.220Z", "expiration": "2022-07-26T10:04:32.220Z", # after this time no more agents will run the query "type": "INPUT_ACTION", "input_type": "osquery", "agent_ids": [], "agent_all": false, "agent_platforms": ["darwin"], "agent_policy_ids": [], "agents": ["16d7caf5-efd2-4212-9b62-73dafc91fa13"], # stores the actual queried agent IDs "user_id": "elastic", "pack_id": "bbe5b070-0c51-11ed-b0f8-ad31b008e832", "pack_name": "test_pack", "pack_prebuilt": false, "metadata": { "execution_context": { "name": "osquery", "url": "/app/osquery/live_queries/new" } }, "queries": [ { "action_id": "609c4c66-ba3d-43fa-afdd-53e244577aa0", # unique ID of the query, use it when querying the live query API to get the single query results "id": "uptime", # ID of the query, doesn't have to be unique "query": "select * from uptime;", "ecs_mapping": { "host.uptime": { "field": "total_seconds" } }, "agents": [ "16d7caf5-efd2-4212-9b62-73dafc91fa13" # stores the actual queried agent IDs ] } ] } }