Files
hose-use/scripts/find_http_nodes.py
T
gitea 760c04be00 feat(platform): 服务层跨应用聚合查询,新增按节点类型筛选工作流
- 新增 list_all_workflows / find_workflows_by_task_type 及其 _cmd 变体
- CLI 新增 workflow-search <task_type> 命令(--all 含停用)
- HTTP 新增 GET /platforms/workflows?task_type=http&enabled_only=true
- 修复 workflow_service.py 中重复定义的函数
2026-04-20 16:50:56 +08:00

124 lines
4.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""临时脚本:扫描所有自建应用下含 HTTP 节点的工作流并输出汇总表格。
用法:
.venv/bin/python scripts/find_http_nodes.py
说明:
- 复用单个 EasoClient 扫所有平台,减少认证请求次数
- 工作流列表接口已包含完整 tasks,无需逐一调详情接口
- 自动处理分页(page_size=100)
"""
from rich.console import Console
from rich.table import Table
from rich import print as rprint
from ekb_cli.api.platform.easo_client import get_easo_client
from ekb_cli.api.platform.platform_api import list_platforms
from ekb_cli.api.platform.workflow_api import list_workflows
from ekb_cli.api import get_client
console = Console()
def collect_http_tasks(tasks: list) -> list:
"""递归收集所有层级中 type='http' 的节点(含控制节点内的嵌套节点)"""
result = []
for t in tasks:
if t.get("type") == "http":
result.append(t)
# 控制节点(every / condition 等)内部可嵌套子节点
nested = t.get("tasks")
if nested and isinstance(nested, list):
result.extend(collect_http_tasks(nested))
return result
def main():
console.print("[bold]扫描所有自建应用下含 HTTP 节点的工作流...[/bold]\n")
# 获取所有自建应用
with get_client() as ekb_client:
platforms = list_platforms(ekb_client)
console.print(f"共 {len(platforms)} 个自建应用,开始扫描工作流...\n")
rows = [] # (platform_name, platform_id, wf_name, wf_id, http_count, http_urls)
with get_easo_client() as easo_client:
for p in platforms:
console.print(f" 扫描 [cyan]{p.name}[/cyan] ({p.id}) ...", end=" ")
# 一次拉完(应用内工作流数量有限,page_size=100 足够覆盖)
result = list_workflows(easo_client, p.id, page=1, page_size=100)
all_workflows = result.pipelineList
console.print(f"{len(all_workflows)} 个工作流")
for wf in all_workflows:
if wf.state != 1: # 只看启用的工作流
continue
http_tasks = collect_http_tasks(wf.tasks)
if not http_tasks:
continue
# 提取 HTTP 节点的 URL(如有)
urls = [t.get("url", "") for t in http_tasks]
rows.append((p.name, p.id, wf.pipelineName, wf.id, len(http_tasks), urls))
console.print()
if not rows:
rprint("[yellow]未找到含 HTTP 节点的工作流[/yellow]")
return
# 汇总表格
table = Table(
title=f"含 HTTP 节点的工作流(共 {len(rows)} 个)",
show_lines=True,
)
table.add_column("自建应用", style="cyan")
table.add_column("工作流名称")
table.add_column("工作流 ID", style="dim")
table.add_column("HTTP 节点数", justify="center", style="bold yellow")
table.add_column("HTTP URL(节点顺序)")
for platform_name, _, wf_name, wf_id, http_count, urls in rows:
table.add_row(
platform_name,
wf_name,
wf_id,
str(http_count),
"\n".join(u if u else "(未配置 URL)" for u in urls),
)
console.print(table)
# 按应用汇总
console.print()
summary = {}
for platform_name, _, _, _, http_count, _ in rows:
summary[platform_name] = summary.get(platform_name, 0) + http_count
summary_table = Table(title="按自建应用汇总(HTTP 节点总数)")
summary_table.add_column("自建应用", style="cyan")
summary_table.add_column("涉及工作流数", justify="center")
summary_table.add_column("HTTP 节点总数", justify="center", style="bold")
wf_count_by_platform = {}
for platform_name, _, _, _, _, _ in rows:
wf_count_by_platform[platform_name] = wf_count_by_platform.get(platform_name, 0) + 1
for platform_name, total_http in sorted(summary.items(), key=lambda x: -x[1]):
summary_table.add_row(
platform_name,
str(wf_count_by_platform[platform_name]),
str(total_http),
)
console.print(summary_table)
if __name__ == "__main__":
main()