version 2
This commit is contained in:
14
data/srv-rhel-prod-01/httpd_conf.txt
Normal file
14
data/srv-rhel-prod-01/httpd_conf.txt
Normal file
@ -0,0 +1,14 @@
|
||||
SERVICE: httpd
|
||||
FILES_COLLECTED: /etc/httpd/conf/httpd.conf, /etc/httpd/conf.d/ssl.conf
|
||||
--- FILE: /etc/httpd/conf/httpd.conf ---
|
||||
ServerRoot "/etc/httpd"
|
||||
Listen 80
|
||||
Include conf.modules.d/*.conf
|
||||
DocumentRoot "/var/www/html"
|
||||
|
||||
--- FILE: /etc/httpd/conf.d/ssl.conf ---
|
||||
Listen 443 https
|
||||
<VirtualHost _default_:443>
|
||||
DocumentRoot "/var/www/html"
|
||||
SSLEngine on
|
||||
</VirtualHost>
|
||||
5
data/srv-rhel-prod-01/metrics_vm.txt
Normal file
5
data/srv-rhel-prod-01/metrics_vm.txt
Normal file
@ -0,0 +1,5 @@
|
||||
METRICS_SNAPSHOT:
|
||||
cpu_usage_idle: 94.2%
|
||||
load_average_1m: 0.15
|
||||
mem_available_bytes: 4294967296
|
||||
disk_io_wait: 0.01
|
||||
4
data/srv-rhel-prod-01/network_ss.txt
Normal file
4
data/srv-rhel-prod-01/network_ss.txt
Normal file
@ -0,0 +1,4 @@
|
||||
NETWORK_STATE (ss -ntulop):
|
||||
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
|
||||
tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=842,fd=6))
|
||||
tcp LISTEN 0 128 0.0.0.0:443 0.0.0.0:* users:(("nginx",pid=842,fd=7))
|
||||
7
data/srv-rhel-prod-01/rpm_inventory.txt
Normal file
7
data/srv-rhel-prod-01/rpm_inventory.txt
Normal file
@ -0,0 +1,7 @@
|
||||
ID: srv-rhel-prod-01
|
||||
OS: Red Hat Enterprise Linux 9.3 (Plow)
|
||||
KERNEL: 5.14.0-362.8.1.el9_3.x86_64
|
||||
INSTALLED_PACKAGES:
|
||||
- httpd-2.4.57-5.el9.x86_64
|
||||
- nginx-1.20.1-14.el9.x86_64
|
||||
- mod_ssl-2.4.57-5.el9.x86_64
|
||||
@ -17,3 +17,12 @@ services:
|
||||
- chroma-db
|
||||
ports:
|
||||
- "8080:8080"
|
||||
|
||||
# Simulateur MCP pour l'Inventaire & Config
|
||||
mcp-inventory:
|
||||
build: ./mcp-simulator
|
||||
container_name: ops-gpt-mcp
|
||||
volumes:
|
||||
- ./data:/app/data:ro
|
||||
ports:
|
||||
- "8081:8080"
|
||||
|
||||
17
mcp-simulator/Dockerfile
Normal file
17
mcp-simulator/Dockerfile
Normal file
@ -0,0 +1,17 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Installation des dépendances via le fichier requirements
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copie du code source
|
||||
COPY main.py .
|
||||
|
||||
# Création du point de montage pour les données des hôtes
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["python", "main.py"]
|
||||
87
mcp-simulator/main.py
Normal file
87
mcp-simulator/main.py
Normal file
@ -0,0 +1,87 @@
|
||||
import os
|
||||
import logging
|
||||
from mcp.server.fastmcp import FastMCP
|
||||
|
||||
# --- CONFIGURATION LOGGING ---
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger("ops-gpt-mcp")
|
||||
|
||||
# --- INITIALISATION ---
|
||||
# On utilise FastMCP pour gérer nativement le transport SSE et les routes /sse /messages
|
||||
mcp = FastMCP("Ops-GPT-Unified-Diagnostics", host="0.0.0.0", port=8080)
|
||||
|
||||
BASE_DATA_PATH = "/app/data"
|
||||
|
||||
# --- CATALOGUE D'OUTILS SRE (INTEGRAL) ---
|
||||
|
||||
@mcp.tool()
|
||||
async def list_services_with_config(hostname: str):
|
||||
"""
|
||||
RECOGNITION: Identifie les middlewares (Nginx, Apache, etc.) avec fichiers de configuration agrégés.
|
||||
Indispensable pour la découverte initiale des composants actifs sur l'hôte.
|
||||
"""
|
||||
try:
|
||||
host_path = os.path.join(BASE_DATA_PATH, hostname)
|
||||
if not os.path.exists(host_path):
|
||||
return f"FATAL_ERROR: Host directory {hostname} not found."
|
||||
|
||||
services = [f.replace("_conf.txt", "") for f in os.listdir(host_path) if f.endswith("_conf.txt")]
|
||||
return f"STATUS_SUCCESS: Services found: {', '.join(services) if services else 'NONE'}"
|
||||
except Exception as e:
|
||||
return f"SYSTEM_EXCEPTION: {str(e)}"
|
||||
|
||||
@mcp.tool()
|
||||
async def get_rpm_inventory(hostname: str):
|
||||
"""
|
||||
AUDIT: Récupère l'inventaire complet des paquets RPM et la version du noyau.
|
||||
Utile pour identifier les dérives de configuration OS.
|
||||
"""
|
||||
try:
|
||||
path = os.path.join(BASE_DATA_PATH, hostname, "rpm_inventory.txt")
|
||||
with open(path, "r", encoding='utf-8') as f:
|
||||
return f"--- RPM_INVENTORY | {hostname} ---\n{f.read()}"
|
||||
except FileNotFoundError:
|
||||
return f"DATA_ERROR: rpm_inventory.txt not found for {hostname}."
|
||||
|
||||
@mcp.tool()
|
||||
async def get_network_sockets(hostname: str):
|
||||
"""
|
||||
NETWORKING: Exécute 'ss -ntulop'. Fournit l'état des sockets et le mapping PID/Processus.
|
||||
"""
|
||||
try:
|
||||
path = os.path.join(BASE_DATA_PATH, hostname, "network_ss.txt")
|
||||
with open(path, "r", encoding='utf-8') as f:
|
||||
return f"--- NETWORK_SOCKETS | {hostname} ---\n{f.read()}"
|
||||
except FileNotFoundError:
|
||||
return f"DATA_ERROR: network_ss.txt not found for {hostname}."
|
||||
|
||||
@mcp.tool()
|
||||
async def get_system_metrics(hostname: str):
|
||||
"""
|
||||
MONITORING: Récupère les métriques CPU/RAM/IO (VictoriaMetrics) pour l'hôte spécifié.
|
||||
"""
|
||||
try:
|
||||
path = os.path.join(BASE_DATA_PATH, hostname, "metrics_vm.txt")
|
||||
with open(path, "r", encoding='utf-8') as f:
|
||||
return f"--- SYSTEM_METRICS | {hostname} ---\n{f.read()}"
|
||||
except FileNotFoundError:
|
||||
return f"DATA_ERROR: metrics_vm.txt not found for {hostname}."
|
||||
|
||||
@mcp.tool()
|
||||
async def get_live_config(hostname: str, service_name: str):
|
||||
"""
|
||||
DEEP ANALYSIS: Extrait le contenu brut du fichier [service]_conf.txt agrégé.
|
||||
"""
|
||||
try:
|
||||
target_file = f"{service_name}_conf.txt"
|
||||
path = os.path.join(BASE_DATA_PATH, hostname, target_file)
|
||||
with open(path, "r", encoding='utf-8') as f:
|
||||
return f"--- CONFIG_FILE: {target_file} | {hostname} ---\n{f.read()}"
|
||||
except FileNotFoundError:
|
||||
return f"DATA_ERROR: Config for '{service_name}' not found for {hostname}."
|
||||
|
||||
# --- LANCEMENT DU SERVEUR ---
|
||||
if __name__ == "__main__":
|
||||
logger.info("Starting Ops-GPT MCP Engine via FastMCP on port 8080")
|
||||
# FastMCP gère lui-même la boucle uvicorn et le transport SSE
|
||||
mcp.run(transport="sse")
|
||||
4
mcp-simulator/requirements.txt
Normal file
4
mcp-simulator/requirements.txt
Normal file
@ -0,0 +1,4 @@
|
||||
mcp>=1.0.0
|
||||
fastapi>=0.100.0
|
||||
uvicorn>=0.23.0
|
||||
starlette>=0.27.0
|
||||
Reference in New Issue
Block a user