# tools-dify **Repository Path**: comeyuan/tools-dify ## Basic Information - **Project Name**: tools-dify - **Description**: No description available - **Primary Language**: Python - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-03-22 - **Last Updated**: 2026-05-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Ops SSH Tools API 这是一个面向 **Dify + 远程 Linux 运维** 的 FastAPI Tool 项目。 ## 设计目标 - Dify 负责理解自然语言、提取参数、组织工作流 - FastAPI 负责通过 SSH 连接 **目标服务器** - Tool 返回结构化 JSON,方便 Agent / Workflow 继续使用 ## 当前能力 ### 远程 SSH 类 - get_host_identity - get_platform_info - get_uptime - get_cpu_status - get_memory_status - get_disk_status - get_host_metrics - check_service_status - check_process_exists - check_remote_port_listening - search_logs - count_keyword_in_logs - get_recent_errors - restart_service - exec_command ### 网络探测类 - tcp_probe - http_probe - dns_lookup ## 快速开始 ```bash python -m venv .venv source .venv/bin/activate # Windows 用 .venv\Scripts\activate pip install -r requirements.txt cp .env.example .env python scripts/generate_openapi.py uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload ``` 访问: - Swagger: http://127.0.0.1:8000/docs - OpenAPI: http://127.0.0.1:8000/openapi.json ## Dify 导入 使用 `openapi/dify_openapi.json` 作为自定义 API 工具导入文件。 如果 Dify 不在本机,请把 `.env` 中 `APP_BASE_URL` 改成 Dify 能访问到的实际地址,然后重新执行: ```bash python scripts/generate_openapi.py ``` ## 远程 SSH 请求体示例 ```json { "ssh": { "host": "192.168.1.20", "port": 22, "username": "root", "auth_type": "password", "password": "your_password" } } ``` ## 私钥方式示例 ```json { "ssh": { "host": "192.168.1.20", "port": 22, "username": "root", "auth_type": "key", "private_key_path": "/path/to/id_rsa" } } ``` ## 安全建议 1. 教学或测试阶段可先用密码认证。 2. 更建议在真实环境中使用 SSH 私钥。 3. 如需限制目标机器,可在 `.env` 中设置 `SSH_ALLOWED_HOSTS=192.168.1.20,192.168.1.21`。 4. `restart_service` 和 `exec_command` 有风险,建议只在测试环境使用。 5. `exec_command` 会拦截 `.env` 里 `SSH_BLOCKED_COMMANDS` 指定的高风险命令,但这不是完备安全方案。 ## 推荐先接入 Dify 的 Tool - get_memory_status - get_cpu_status - get_disk_status - check_service_status - search_logs - get_recent_errors ## 常见思路 - “查 192.168.1.20 的内存” -> get_memory_status - “查 192.168.1.20 的 nginx 状态” -> check_service_status - “查 /var/log/nginx/error.log 最近错误” -> get_recent_errors - “重启 nginx” -> restart_service