dicemy's picture
Upload 655 files
e8c001c verified
|
Raw
History Blame Contribute Delete
2.84 kB
---
id: offline-compute_PrestoSQL_prestosql_010
name: IOC MTTD指标计算
category: offline-compute/PrestoSQL
timeout_seconds: 900
modality: pure-text
engine: prestosql
---
## Prompt
**任务目标**:从API指标表和威胁情报IOC表中,通过JSON解析提取IOC值,与IOC表关联计算MTTD(平均检测时间)指标,写入输出表。
**输入表**
- `internal_platform_db.t_app_ti_entity_api_metrics_prod_hi_prestosql_010`(API指标表)
- `timestamp` BIGINT — 时间戳
- `username` STRING — 用户名
- `appid` BIGINT — 应用ID
- `path` STRING — 路径
- `request` STRING — 请求体(JSON)
- `response` STRING — 响应体
- `ds` BIGINT — 分区字段
- `internal_platform_db.t_sh_threat_intel_lab_breakingti_soc_endpoint_security_format_output_prod_prestosql_010`(威胁情报IOC表)
- `ioctype` STRING — IOC类型
- `ioc` STRING — IOC值
- `port` STRING — 端口
- `producer` STRING — 生产者
- `stamp` STRING — 时间戳
- `category` STRING — 分类
- `family` STRING — 家族
- `apt_org` STRING — APT组织
- `weapon` STRING — 武器
- `usefor` STRING — 用途
- `ttps` STRING — TTPs
- `confidence` INT — 置信度
- `context` STRING — 上下文
- `intelligence_investigation` STRING — 情报调查
- `match_subdomains` INT — 匹配子域名
- `bdelete` INT — 删除标记
- `deleted_time` STRING — 删除时间
- `first_occur_time` STRING — 首次出现时间
- `last_occur_time` STRING — 最后出现时间
- `ds` BIGINT — 分区字段
**计算逻辑**
1. 从API指标表提取: json_extract_scalar(request, '$.entity_value') AS ioc_value, 按ioc_value分组取MIN(timestamp) AS earliest_timestamp, 过滤ds=20260608
2. 从IOC表过滤: ioctype='DOMAIN' AND bdelete=0, 过滤ds=20260608
3. JOIN条件: ioc = ioc_value
4. time_diff_days = GREATEST(0, (unix_timestamp(first_occur_time) - earliest_timestamp) / 86400.0)
**输出要求**
- 目标表: `internal_platform_db.t_app_breaking_ti_mttd_metric_cand_prestosql_010`
- 输出字段及顺序: `IOC` STRING, `IOCTYPE` STRING, `PORT` STRING, `first_occur_time` STRING, `earliest_timestamp` BIGINT, `family` STRING, `match_subdomains` INT, `time_diff_days` DOUBLE, `ds` BIGINT
- ds: 固定值 20260608
- 注意Presto中用json_extract_scalar代替get_json_object,用to_unixtime代替unix_timestamp(需配合FROM_UNIXTIME相关的转换)
- 如果目标表不存在,请先建表再写入数据
- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言
**环境与执行说明**
- Presto已启动,通过Hive catalog连接
- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`
- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据