安全与风控
需要操作 Datadog 资源时用 pup CLI…
在已安装并认证 Datadog pup CLI 的环境中,通过命令行处理日志、指标、APM、监控器、事故、仪表盘、SLO、安全、审计与成本等 Datadog API 操作。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
需要操作 Datadog 资源时用 pu特定
解决思路
- 安装 pup:按设置说明安装,链接:https://github.com/datadog-labs/agent-skills/tree/main?tab=readme-ov-file#setup-pup。
- 验证安装:运行 `which pup`;运行 `pup --version`。
- 对需要特定 scope 值(`<env>`、`<service-name>`、`<team-id>`、资源 ID)的命令,先检查上下文(对话历史、先前命令输出、保存变量)。
- 如果缺失 scope 值,先运行发现命令(list/search)获取有效值。
- 如果仍缺失或歧义,向用户确认确切值。
- 然后运行目标命令。
- 绝不要用未解析占位符(如 `<env>`、`<monitor-id>`)运行命令。
- 运行 `pup auth login` 进行 OAuth2 浏览器登录(推荐)。
- 运行 `pup auth status` 检查 token 有效性。
- 运行 `pup auth status` 查看 token 剩余过期时间。
- 运行 `pup auth refresh` 刷新过期 token(无需浏览器)。
- 运行 `pup auth logout` 清除凭据。
- Token 约 1 小时过期;若命令在对话中因 401/403 失败,先运行 `pup auth refresh`,若刷新失败再运行 `pup auth login` 完整重新认证。
- 若 Chrome 打开错误的 profile/window,使用 `pup auth login` 打印的一次性 OAuth URL(`If the browser doesn't open, visit: ...`),在正确账号会话中手动打开该链接。
- Headless/CI 无浏览器时,设置 `export DD_API_KEY=your-api-key`、`export DD_APP_KEY=your-app-key`、`export DD_SITE=datadoghq.com`(或 `datadoghq.eu` 等),或使用环境变量认证。
- 列出 monitors:`pup monitors list --limit 10`。
- 按 tags 列出 monitors:`pup monitors list --tags "env:<env>"`。
- 获取 monitor:`pup monitors get <monitor-id>`。
- 搜索 monitor:`pup monitors search --query "<monitor-name>"`。
- 创建 monitor:`pup monitors create --file monitor.json`。
- 更新 monitor:`pup monitors update <monitor-id> --file monitor.json`。
- 对比 monitor 定义:`pup monitors diff <monitor-id> monitor.json`。
- 删除 monitor:`pup monitors delete <monitor-id>`。
- 没有 `pup monitors mute/unmute` 命令;改用 downtime payload:`pup downtime create --file downtime.json`。
- 搜索错误日志:`pup logs search --query "status:error" --from 1h`。
- 按 service 搜索日志:`pup logs search --query "service:<service-name>" --from 1h --limit 100`。
- 搜索 5xx HTTP 状态日志:`pup logs search --query "@http.status_code:5*" --from 24h`。
- 按 env 和 level 搜索日志:`pup logs search --query "env:<env> level:error" --from 1h`。
- 聚合日志:`pup logs aggregate --query "service:<service-name>" --compute count --from 1h`。
- 查询 metrics:`pup metrics query --query "avg:system.cpu.user{*}" --from 1h --to now`。
- 查询 trace 指标:`pup metrics query --query "sum:trace.express.request.hits{service:<service-name>}" --from 1h --to now`。
- 列出 metrics:`pup metrics list --filter "system.*"`。
- 先与用户确认 env tag,不要假设 production/prod/prd。
- 列出 APM services:`pup apm services list --env <env> --from 1h --to now`。
- 按 service 搜索 traces:`pup traces search --query "service:<service-name>" --from 1h`。
- 搜索慢 traces:`pup traces search --query "service:<service-name> @duration:>500ms" --from 1h`。
- 搜索错误 traces:`pup traces search --query "service:<service-name> status:error" --from 1h`。
- 列出 incidents:`pup incidents list --limit 50`。
- 获取 incident:`pup incidents get <incident-id>`。
- 导入 incident payload:`pup incidents import --file incident.json`。
- 列出 dashboards:`pup dashboards list`。
- 只读获取 dashboard:`pup dashboards get <dashboard-id> --read-only`。
- 生成 live 时间窗口 dashboard URL:`pup dashboards url <dashboard-id> --from now-1h --to now --live true`。
- 创建 dashboard:`pup dashboards create --file dashboard.json`。
- 更新 dashboard:`pup dashboards update <dashboard-id> --file dashboard.json`。
- 删除 dashboard:`pup dashboards delete <dashboard-id>`。
- 安全 dashboard 创建、克隆和更新工作流:用 `--read-only` 获取源或更新目标并保存为不可变快照:`pup dashboards get <dashboard-id> --read-only -o json > dashboard-source.json`;绝不用转换后的 JSON 覆盖该文件。
- 安全 dashboard 工作流第 2 步:构建单独的 mutation payload,在 create/update 前用 jq 删除 response-only 字段:`jq 'del(.author_handle, .author_name, .created_at, .id, .modified_at, .url)' dashboard-source.json > dashboard-payload.json`。
- 安全 dashboard 工作流第 3 步:备份或克隆时保持源 dashboard 不变,只改明确请求的字段(通常是 `title` 或 `description`);保留 `layout_type`、`reflow_type`、widget 顺序及每个递归 widget `layout` 对象(`x`、`y`、`width`、`height`、`is_column_break`);不要重排或压缩坐标。
- 安全 dashboard 工作流第 4 步:从 `dashboard-payload.json` create 或 update,然后把目标获取到新文件:`pup dashboards create --file dashboard-payload.json`;`pup dashboards get <destination-id> --read-only -o json > dashboard-destination.json`。
- 安全 dashboard 工作流第 5 步:归一化掉 response-only 字段并比较完整定义;差异应仅为有意修改字段。
- 安全 dashboard 工作流第 6 步:单独比较 layout projections,防止 placement 回归隐藏在大 widget diff 中:`jq '{layout_type, reflow_type, layouts: [.. | objects | .layout? // empty]}' dashboard-source.json`;`jq '{layout_type, reflow_type, layouts: [.. | objects | .layout? // empty]}' dashboard-destination.json`。
- Pup 1.6.3 不暴露 dashboard version history;若需要精确历史版本且没有不可变快照,先在 Datadog UI 检查版本历史再修改 dashboard。
- 列出 SLOs:`pup slos list`。
- 获取 SLO:`pup slos get <slo-id>`。
- 查看 SLO status:`pup slos status <slo-id> --from 30d --to now`。
- 创建 SLO:`pup slos create --file slo.json`。
- 列出 synthetic tests:`pup synthetics tests list`。
- 获取 synthetic test:`pup synthetics tests get <test-id>`。
- 搜索 synthetic tests:`pup synthetics tests search --text "login"`。
- 列出 synthetic locations:`pup synthetics locations list`。
- 列出 on-call teams:`pup on-call teams list`。
- 从 `pup on-call teams list` 输出中选择真实 team id。
- 获取 team:`pup on-call teams get <team-id>`。
- 列出 team memberships:`pup on-call teams memberships list <team-id>`。
- 列出 hosts:`pup infrastructure hosts list --count 50`。
- 按 env 过滤 hosts:`pup infrastructure hosts list --filter "env:<env>"`。
- 获取 host:`pup infrastructure hosts get <host-name>`。
- 列出 recent events:`pup events list --from 24h`。
- 按 tags 列出 events:`pup events list --tags "source:deploy"`。
- 搜索 events:`pup events search --query "deploy" --from 24h --limit 50`。
- 获取 event:`pup events get <event-id>`。
- 列出 downtimes:`pup downtime list`。
- 创建 downtime:`pup downtime create --file downtime.json`。
- 取消 downtime:`pup downtime cancel <downtime-id>`。
- 列出 users:`pup users list`。
- 获取 user:`pup users get <user-id>`。
- 列出 security signals:`pup security signals list --query "*" --from 1h --limit 100`。
- triage open critical security signals:`pup security signals list --query "status:open severity:critical" --from 1h --limit 100`。
- 历史 triage 用更大回溯:`pup security signals list --query "severity:critical" --from 24h --limit 100`。
- 列出 recent audit logs:`pup audit-logs list --from 1h --limit 100`。
- 用 Lucene 语法搜索 audit logs(与 Log Explorer 相同):`pup audit-logs search --query "@action:deleted" --from 24h`。
- 按用户搜索 audit logs:`pup audit-logs search --query "@usr.email:user@example.com" --from 7d`。
- 搜索认证登录事件:`pup audit-logs search --query "@evt.name:Authentication @action:login" --from 7d`。
- 调查 API key:`pup audit-logs search --query "@metadata.api_key.id:KEY_ID" --from 90d --limit 200`。
- 输出 JSON 供 jq 管道处理:`pup audit-logs search --query "@action:deleted" --from 24h -o json | jq '.data[].attributes'`。
- 搜索 monitor 修改事件:`pup audit-logs search --query "@evt.name:Monitor @action:modified" --from 7d`。
- `audit-logs` 是长形式,长/短形式都可用。
- 列出 service catalog:`pup service-catalog list`。
- 获取 service:`pup service-catalog get <service-name>`。
- 列出 notebooks:`pup notebooks list`。
- 获取 notebook:`pup notebooks get <notebook-id>`。
- 获取 workflow:`pup workflows get <workflow-id>`。
- 运行 workflow:`pup workflows run <workflow-id> --payload '{"key":"value"}'`。
- 列出 workflow instances:`pup workflows instances list <workflow-id>`。
- 列出 obs pipelines:`pup obs-pipelines list --limit 50`。
- 获取 pipeline:`pup obs-pipelines get <pipeline-id>`。
- 创建 pipeline:`pup obs-pipelines create --file pipeline.json`。
- 更新 pipeline:`pup obs-pipelines update <pipeline-id> --file pipeline.json`。
- 删除 pipeline:`pup obs-pipelines delete <pipeline-id>`。
- 验证 pipeline:`pup obs-pipelines validate --file pipeline.json`。
- 列出 LLM obs projects:`pup llm-obs projects list`。
- 创建 LLM obs project:`pup llm-obs projects create --file project.json`。
- 列出 experiments:`pup llm-obs experiments list`。
- 按 project 过滤 experiments:`pup llm-obs experiments list --filter-project-id <project-id>`。
- 按 dataset 过滤 experiments:`pup llm-obs experiments list --filter-dataset-id <dataset-id>`。
- 创建 experiment:`pup llm-obs experiments create --file experiment.json`。
- 更新 experiment:`pup llm-obs experiments update <experiment-id> --file experiment.json`。
- 删除 experiment:`pup llm-obs experiments delete --file delete-request.json`。
- 列出 datasets:`pup llm-obs datasets list --project-id <project-id>`。
- 创建 dataset:`pup llm-obs datasets create --project-id <project-id> --file dataset.json`。
- 搜索 spans:`pup llm-obs spans search --ml-app <ml-app-name> --from 1h --limit 20`。
- 列出 reference tables:`pup reference-tables list --limit 50`。
- 获取 reference table:`pup reference-tables get <table-id>`。
- 创建 reference table:`pup reference-tables create --file table.json`。
- 批量查询 reference table:`pup reference-tables batch-query --file query.json`。
- 列出 AWS CUR configs:`pup cost aws-config list`。
- 获取 AWS config:`pup cost aws-config get <account-id>`。
- 创建 AWS config:`pup cost aws-config create --file config.json`。
- 删除 AWS config:`pup cost aws-config delete <account-id>`。
- 列出 Azure UC configs:`pup cost azure-config list`。
- 获取 Azure config:`pup cost azure-config get <account-id>`。
- 创建 Azure config:`pup cost azure-config create --file config.json`。
- 删除 Azure config:`pup cost azure-config delete <account-id>`。
- 列出 GCP usage cost configs:`pup cost gcp-config list`。
- 获取 GCP config:`pup cost gcp-config get <account-id>`。
- 创建 GCP config:`pup cost gcp-config create --file config.json`。
- 删除 GCP config:`pup cost gcp-config delete <account-id>`。
- 确认安装版本:`pup --version`。
- 列出所有命令:`pup --help`。
- 查看命令帮助:`pup <command> --help`。
- 过滤输出再格式化:`pup dashboards get <dashboard-id> --jq '{title, layout_type}'`。
- 如果本地 help 与本技能不同,在发明 workaround 前比较 `pup --version` 与最新稳定版。
- 401 Unauthorized:token 过期,运行 `pup auth refresh`。
- 403 Forbidden:缺少 scope,检查 app key 权限。
- 404 Not Found:ID/资源错误,验证资源存在。
- Rate limited:请求过多,在调用之间加入延迟。
- US1 (default):设置 `DD_SITE=datadoghq.com`。
- US3:设置 `DD_SITE=us3.datadoghq.com`。
- US5:设置 `DD_SITE=us5.datadoghq.com`。
- EU1:设置 `DD_SITE=datadoghq.eu`。
- AP1:设置 `DD_SITE=ap1.datadoghq.com`。
- AP2:设置 `DD_SITE=ap2.datadoghq.com`。
- US1-FED:设置 `DD_SITE=ddog-gov.com`。
适用边界 · 注意事项
- 未安装 pup、没有 Datadog 账号,或没有对应 Datadog API/app key 权限/scope 时不适用。
- 需要 Datadog UI 专属 dashboard 版本历史且没有不可变快照时不适用(pup 1.6.3 不暴露版本历史)。
- 非 Datadog 可观测性、监控、审计或成本管理场景不适用。