Hinemos监控服务器

Hinemos MCP Server是一个与Hinemos监控系统集成的服务器,提供节点状态检查、事件获取和作业执行等功能。

  • by shida2022
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 shida2022/hinemos-mcp

使用说明

Hinemos MCP Server 使用指南

安装过程

1.环境构筑

# リポジトリクローン
git clone <your-repo>/hinemos-mcp-server
cd hinemos-mcp-server

# 依存関係インストール
pip install -r requirements.txt

# 設定ファイル作成
cp .env.example .env
# .envファイルを編集してHinemos接続情報を設定

2. Hinemos接続设定

.env在文件中设置:

HINEMOS_BASE_URL=http://your-hinemos-server:8080/HinemosWS/
HINEMOS_USERNAME=your_username
HINEMOS_PASSWORD=your_password

3. Claude Desktop 协作

Claude Desktop 的配置文件(claude_desktop_config.json)中添加以下内容:

{
  "mcpServers": {
    "hinemos": {
      "command": "python",
      "args": ["/path/to/hinemos_mcp_server.py"],
      "env": {
        "HINEMOS_BASE_URL": "http://your-hinemos-server:8080/HinemosWS/",
        "HINEMOS_USERNAME": "your_username",
        "HINEMOS_PASSWORD": "your_password"
      }
    }
  }
}

可用功能

Tools(工具)

  1. check_node_status(节点id:str)

    • 确认指定节点的监视状态
    • 例: check_node_status("WEB-SERVER-01")
  2. get_critical_events(小时数:int=24)

    • 获取重要事件
    • 例: get_critical_events(12) #过去12时间
  3. execute_hinemos_job(job_id:str,target_node:str)

    • Hinemos作业执行
    • 例: execute_hinemos_job("BACKUP_JOB", "DB-SERVER-01")
  4. list_managed_nodes()

    • 管理对象节点一览获取

Resources(资源)

  1. hinemos://monitor/status

    • 当前监视状态
  2. hinemos://events/recent

    • 最新事件信息

Prompts(提示

  1. 系统健康报告()

    • 整个系统运行状况报告生成
  2. 偶发事件调查(event_id:str)

    • 事故详细调查

使用例

Claude Desktop 使用示例

# ユーザー: システムの健全性レポートを作成してください

Claude: システム全体の健全性レポートを作成します。

[system_health_report() プロンプトを使用]
[check_node_status() で各ノードをチェック]
[get_critical_events() で重要なイベントを確認]

## システム健全性レポート

### 全体ステータス
- 総ノード数: 25台
- 正常稼働: 23台
- 警告状態: 2台
- エラー状態: 0台

### 重要なアラート
1. WEB-SERVER-02: CPU使用率 95% (警告)
2. DB-SERVER-01: ディスク使用率 88% (警告)

### 推奨アクション
1. WEB-SERVER-02のプロセス確認が必要
2. DB-SERVER-01のログクリーンアップ実行推奨

测试方法

1.连接测试

# test_connection.py
import asyncio
from hinemos_mcp_server import HinemosClient, HinemosConfig
import aiohttp

async def test_connection():
    config = HinemosConfig(
        base_url="http://localhost:8080/HinemosWS/",
        username="hinemos",
        password="hinemos123"
    )
    
    async with aiohttp.ClientSession() as session:
        client = HinemosClient(config, session)
        try:
            nodes = await client.get_node_list()
            print(f"接続成功: {len(nodes)} ノード取得")
        except Exception as e:
            print(f"接続エラー: {e}")

asyncio.run(test_connection())

2. MCP Inspector 测试

# MCP Inspectorを使用してサーバーをテスト
npx @modelcontextprotocol/inspector python hinemos_mcp_server.py

3.单体测试

# test_hinemos_mcp.py
import pytest
import asyncio
from unittest.mock import AsyncMock, MagicMock
from hinemos_mcp_server import HinemosClient, HinemosConfig

@pytest.fixture
def mock_session():
    session = AsyncMock()
    response = AsyncMock()
    response.text = AsyncMock(return_value='<soap:Envelope>...</soap:Envelope>')
    response.raise_for_status = MagicMock()
    session.post.return_value.__aenter__.return_value = response
    return session

@pytest.mark.asyncio
async def test_get_node_list(mock_session):
    config = HinemosConfig("http://test", "user", "pass")
    client = HinemosClient(config, mock_session)
    
    result = await client.get_node_list()
    assert result is not None
    mock_session.post.assert_called_once()

故障排除

常见问题

  1. 验证错误

    Error: 401 Unauthorized
    解決: HINEMOS_USERNAME と HINEMOS_PASSWORD を確認
    
  2. 连接超时

    Error: Connection timeout
    解決: HINEMOS_BASE_URL とネットワーク接続を確認
    
  3. SOAP 珀斯误差

    Error: XML parsing failed
    解決: Hinemosサーバーのレスポンス形式を確認
    

日志检查

# デバッグモードで実行
LOG_LEVEL=DEBUG python hinemos_mcp_server.py

Hinemos API 版本确认

# Hinemos WebService APIのWSDLを確認
curl http://your-hinemos-server:8080/HinemosWS/MonitorEndpoint?wsdl

自定义

添加新工具

@mcp.tool()
async def custom_monitoring_tool(parameter: str) -> List[TextContent]:
    """カスタム監視ツール"""
    ctx = mcp.get_context()
    client = HinemosClient(ctx.hinemos_config, ctx.session)
    
    # カスタムロジック実装
    result = await client.custom_api_call(parameter)
    
    return [TextContent(type="text", text=str(result))]

添加新资源

@mcp.resource("hinemos://custom/data")
async def get_custom_data() -> Resource:
    """カスタムデータリソース"""
    # カスタムデータ取得ロジック
    return Resource(
        uri="hinemos://custom/data",
        name="Custom Hinemos Data",
        description="Custom data from Hinemos",
        mimeType="application/```