get_os_details
Retrieve detailed operating system information remotely by specifying hostname, username, and optional credentials using this server monitoring utility from OPS MCP Server.
Instructions
获取操作系统详细信息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hostname | Yes | ||
| password | No | ||
| port | No | ||
| timeout | No | ||
| username | Yes |
Implementation Reference
- Primary handler implementation for get_os_details tool. Connects via SSH to remote server, executes commands to gather OS details including hostname, OS release, kernel, architecture, uptime, parses distro/version/virtualization, returns structured dict.def get_os_details( hostname: str, username: str, password: str = "", port: int = 22, timeout: int = 30 ) -> dict: """获取操作系统详细信息""" result = {"status": "unknown", "os_info": {}, "error": ""} try: with SSHManager(hostname, username, password, port, timeout) as ssh: # 收集各种系统信息 commands = { "hostname": "hostname", "os_release": "cat /etc/os-release || cat /etc/redhat-release || cat /etc/debian_version || uname -a", "kernel": "uname -r", "architecture": "uname -m", "uptime": "uptime -p", "last_boot": "who -b" } os_info = {} for key, command in commands.items(): stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout) output = stdout.read().decode().strip() os_info[key] = output # 解析OS分发版和版本 distro = "Unknown" version = "Unknown" if "NAME=" in os_info["os_release"]: distro_match = re.search(r'NAME="?(.*?)"?', os_info["os_release"], re.MULTILINE) if distro_match: distro = distro_match.group(1) version_match = re.search(r'VERSION="?(.*?)"?', os_info["os_release"], re.MULTILINE) if version_match: version = version_match.group(1) else: version_id_match = re.search(r'VERSION_ID="?(.*?)"?', os_info["os_release"], re.MULTILINE) if version_id_match: version = version_id_match.group(1) os_info["distro"] = distro os_info["version"] = version # 检查是否为虚拟机 vm_check_command = "systemd-detect-virt || dmesg | grep -i virtual || dmidecode | grep -i vmware || dmidecode | grep -i virtualbox || echo 'Unknown'" stdin, stdout, stderr = ssh.exec_command(vm_check_command, timeout=timeout) vm_output = stdout.read().decode().strip() os_info["virtualization"] = "Unknown" if vm_output != "Unknown": for vm_type in ["kvm", "vmware", "virtualbox", "xen", "docker", "lxc", "openvz", "parallels"]: if vm_type.lower() in vm_output.lower(): os_info["virtualization"] = vm_type break result["os_info"] = os_info result["status"] = "success" except Exception as e: result["status"] = "error" result["error"] = str(e) return result
- Secondary handler implementation for get_os_details in SSE version. Similar to primary but simpler, collects raw outputs without parsing distro/version/virtualization.def get_os_details( hostname: str, username: str, password: str = "", port: int = 22, timeout: int = 30 ) -> dict: """获取操作系统详细信息""" result = {"status": "unknown", "os_info": {}, "error": ""} try: with SSHManager(hostname, username, password, port, timeout) as ssh: # 收集各种系统信息 commands = { "hostname": "hostname", "os_release": "cat /etc/os-release || cat /etc/redhat-release || cat /etc/debian_version || uname -a", "kernel": "uname -r", "architecture": "uname -m", "uptime": "uptime -p", "last_boot": "who -b" } os_info = {} for key, command in commands.items(): stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout) output = stdout.read().decode().strip() os_info[key] = output result["os_info"] = os_info result["status"] = "success" except Exception as e: result["status"] = "error" result["error"] = str(e) return result
- server_monitor/main.py:43-72 (registration)Registration of get_os_details (line 48) in tools_dict and dynamic registration loop for MCP server.'get_memory_info': get_memory_info, 'remote_server_inspection': remote_server_inspection, 'get_system_load': get_system_load, 'monitor_processes': monitor_processes, 'check_service_status': check_service_status, 'get_os_details': get_os_details, 'check_ssh_risk_logins': check_ssh_risk_logins, 'check_firewall_config': check_firewall_config, 'security_vulnerability_scan': security_vulnerability_scan, 'backup_critical_files': backup_critical_files, 'inspect_network': inspect_network, 'analyze_logs': analyze_logs, 'list_docker_containers': list_docker_containers, 'list_docker_images': list_docker_images, 'list_docker_volumes': list_docker_volumes, 'get_container_logs': get_container_logs, 'monitor_container_stats': monitor_container_stats, 'check_docker_health': check_docker_health } # 使用装饰器动态注册所有工具 for name, func in tools_dict.items(): mcp.tool()(func) # 特殊处理list_available_tools,因为它需要mcp实例 @mcp.tool() def _list_available_tools(): return list_available_tools(mcp) return mcp
- server_monitor_sse/server.py:113-125 (registration)Dispatch/registration handler in SSE server that calls get_os_details with parsed arguments.elif name == "get_os_details": required_args = ["hostname", "username"] for arg in required_args: if arg not in arguments: raise ValueError(f"Missing required argument '{arg}'") result = get_os_details( hostname=arguments["hostname"], username=arguments["username"], password=arguments.get("password", ""), port=arguments.get("port", 22), timeout=arguments.get("timeout", 30) )
- Tool schema definition including name, description, and parameters for get_os_details.{"name": "get_os_details", "description": "获取操作系统详细信息", "parameters": [ {"name": "hostname", "type": "str", "default": None}, {"name": "username", "type": "str", "default": None}, {"name": "password", "type": "str", "default": ""}, {"name": "port", "type": "int", "default": 22}, {"name": "timeout", "type": "int", "default": 30} ]}