Skip to main content
Glama

check_service_status

Monitor and verify the operational status of specific services on remote servers using hostname, credentials, and service names provided. Supports custom timeout and port settings.

Instructions

检查指定服务的运行状态

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostnameYes
passwordNo
portNo
servicesNo
timeoutNo
usernameYes

Implementation Reference

  • Core handler function implementing the check_service_status tool. Connects via SSH and uses systemctl to check specified or all running services' status, parsing output for active, enabled states.
    @handle_exceptions def check_service_status( hostname: str, username: str, password: str = "", port: int = 22, services: list[str] = [], timeout: int = 30 ) -> dict: """检查指定服务的运行状态""" result = {"status": "unknown", "services": [], "error": ""} try: with SSHManager(hostname, username, password, port, timeout) as ssh: if services: # 检查特定服务 service_statuses = [] for service in services: command = f"systemctl status {service}" stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout) output = stdout.read().decode().strip() # 分析输出判断服务状态 service_status = { "name": service, "status": "unknown", "active": False, "enabled": False } if "Active: active" in output: service_status["status"] = "running" service_status["active"] = True elif "Active: inactive" in output: service_status["status"] = "stopped" elif "not-found" in output or "could not be found" in output: service_status["status"] = "not found" # 检查是否开机启动 enabled_command = f"systemctl is-enabled {service}" stdin, stdout, stderr = ssh.exec_command(enabled_command, timeout=timeout) enabled_output = stdout.read().decode().strip() service_status["enabled"] = enabled_output == "enabled" service_statuses.append(service_status) result["services"] = service_statuses else: # 列出所有活跃的服务 command = "systemctl list-units --type=service --state=running" stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout) raw_output = stdout.read().decode().strip() # 解析服务状态 result["services"] = ServerInspector.parse_services(raw_output) result["status"] = "success" except Exception as e: result["status"] = "error" result["error"] = str(e) return result
  • Registration of the check_service_status tool in the MCP server via FastMCP, including it in tools_dict and applying mcp.tool() decorator.
    def init_mcp(): """初始化MCP服务""" # 初始化MCP服务 mcp = FastMCP("ServerMonitor") # 注册所有工具函数 tools_dict = { '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
  • Tool schema definition including name, description, and parameter types/defaults for check_service_status.
    {"name": "check_service_status", "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": "services", "type": "list[str]", "default": []}, {"name": "timeout", "type": "int", "default": 30} ]},
  • Enum constant defining the tool name SERVICE_STATUS as 'check_service_status' in ServerTools.
    SERVICE_STATUS = "check_service_status" # 服务状态检查 NETWORK_INSPECTION = "inspect_network" # 网络检查
  • Export of check_service_status in the tools package __all__ list, making it available for import.
    __all__ = [ 'get_memory_info', 'remote_server_inspection', 'get_system_load', 'monitor_processes', 'check_service_status', 'get_os_details', 'check_ssh_risk_logins', 'check_firewall_config', 'security_vulnerability_scan', 'backup_critical_files', 'inspect_network', 'analyze_logs', 'list_docker_containers', 'list_docker_images', 'list_docker_volumes', 'get_container_logs', 'monitor_container_stats', 'check_docker_health', 'list_available_tools' ]

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Heht571/ops-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server