better detection
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
from .os_detector import create_os_detector_worker
|
||||
from .logs_analyzer import create_logs_analyzer_worker
|
||||
from .performance_analyzer import create_performance_analyzer_worker
|
||||
from .service_discovery import create_service_discovery_worker
|
||||
|
||||
__all__ = [
|
||||
"create_os_detector_worker",
|
||||
"create_logs_analyzer_worker",
|
||||
"create_performance_analyzer_worker"
|
||||
"create_performance_analyzer_worker",
|
||||
"create_service_discovery_worker"
|
||||
]
|
||||
|
@@ -18,9 +18,9 @@ def create_os_detector_worker():
|
||||
|
||||
Your capabilities:
|
||||
1. **System Identification**: Detect OS type, version, kernel, and architecture
|
||||
2. **Environment Analysis**: Identify running services, installed packages, and system configuration
|
||||
2. **Environment Analysis**: Identify virtualization, containerization platforms
|
||||
3. **Hardware Detection**: Gather CPU, memory, disk, and network interface information
|
||||
4. **Security Assessment**: Check for security tools, firewall status, and platform-specific security features
|
||||
4. **Platform Detection**: Identify container runtimes and orchestration tools
|
||||
|
||||
OS-Specific Commands:
|
||||
**Universal:**
|
||||
@@ -30,37 +30,42 @@ OS-Specific Commands:
|
||||
**Linux:**
|
||||
- `/etc/os-release`, `lsb_release -a` - OS version details
|
||||
- `systemctl list-units --type=service` - Active services
|
||||
- `dpkg -l` (Debian/Ubuntu) or `rpm -qa` (RHEL/CentOS) - Installed packages
|
||||
- Check SELinux/AppArmor status
|
||||
- Container detection: `which docker podman lxc lxd incus kubectl`
|
||||
- Virtualization: `systemd-detect-virt`
|
||||
|
||||
**Container Platform Detection:**
|
||||
- Docker: `docker version`
|
||||
- Podman: `podman version`
|
||||
- LXC/LXD: `lxc version` or `lxd version`
|
||||
- Incus: `incus version` (important: newer systems use Incus instead of LXD)
|
||||
- Kubernetes: `kubectl version`
|
||||
|
||||
**macOS:**
|
||||
- `sw_vers` - macOS version information
|
||||
- `system_profiler SPSoftwareDataType` - Detailed system info
|
||||
- `launchctl list` - Running services (not systemctl!)
|
||||
- `pkgutil --pkgs` - Installed packages
|
||||
- `csrutil status` - System Integrity Protection status
|
||||
- `spctl --status` - Gatekeeper status
|
||||
|
||||
**Windows (if applicable):**
|
||||
- `systeminfo` - System information
|
||||
- `Get-ComputerInfo` (PowerShell) - Detailed system info
|
||||
- `Get-Service` - Running services
|
||||
- Container detection: `which docker podman`
|
||||
|
||||
Detection Strategy:
|
||||
1. Start with `uname -s` to identify the kernel/OS type
|
||||
2. Use OS-specific commands based on the result:
|
||||
- Linux: Check `/etc/os-release` or `/etc/*release` files
|
||||
- macOS: Use `sw_vers` and `system_profiler`
|
||||
- Windows: Use `systeminfo` or PowerShell cmdlets
|
||||
3. Adapt service and package detection commands accordingly
|
||||
4. Check for containerization (Docker, Kubernetes, LXC) and virtualization
|
||||
2. Detect container/virtualization platforms available
|
||||
3. Note which commands are available for the Service Discovery agent
|
||||
4. Check for containerization (Docker, Incus, Kubernetes)
|
||||
5. Identify any special project/namespace configurations
|
||||
|
||||
Safety guidelines:
|
||||
- Only run read-only commands for detection
|
||||
- Never modify system configurations
|
||||
- Avoid commands that could impact performance
|
||||
- Always check OS type before running OS-specific commands
|
||||
IMPORTANT for Service Discovery coordination:
|
||||
When detecting container platforms, note:
|
||||
- If Incus is present (common on modern systems)
|
||||
- If there are multiple projects (e.g., "default", "gta", etc.)
|
||||
- Authentication requirements (sudo needed?)
|
||||
- Available commands and their exact syntax
|
||||
|
||||
Remember: You can also use the poem tool to boost morale when the debugging gets tough!""",
|
||||
Output should include:
|
||||
- OS details
|
||||
- Available container platforms
|
||||
- Command availability (docker, incus, lxc, kubectl, etc.)
|
||||
- Any special configurations or project structures
|
||||
|
||||
Remember: Your findings help the Service Discovery agent know which commands to use!""",
|
||||
name="os_detector"
|
||||
)
|
152
multi-agent-supervisor/agents/service_discovery.py
Normal file
152
multi-agent-supervisor/agents/service_discovery.py
Normal file
@@ -0,0 +1,152 @@
|
||||
"""Service Discovery Agent for comprehensive service enumeration across platforms."""
|
||||
|
||||
from langchain_openai import ChatOpenAI
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
from langchain_community.tools.shell.tool import ShellTool
|
||||
from custom_tools import configured_remote_server
|
||||
import json
|
||||
|
||||
|
||||
def create_service_discovery_worker():
|
||||
"""Create a service discovery agent that finds all services across different platforms."""
|
||||
|
||||
tools = [configured_remote_server]
|
||||
|
||||
return create_react_agent(
|
||||
model=ChatOpenAI(model="gpt-4o-mini", temperature=0),
|
||||
tools=tools,
|
||||
prompt="""You are an expert Service Discovery Agent specialized in finding ALL services running on a system, regardless of their deployment method.
|
||||
|
||||
Your mission: Discover and catalog EVERY service running on the system, including:
|
||||
- System services (systemd, init.d, launchd, etc.)
|
||||
- Containerized services (Docker, Podman, LXC, LXD, Incus)
|
||||
- Virtual machines (KVM, VirtualBox, VMware)
|
||||
- Process-based services (standalone binaries)
|
||||
- Kubernetes pods/deployments
|
||||
- Snap packages
|
||||
- AppImage applications
|
||||
|
||||
DISCOVERY STRATEGY:
|
||||
|
||||
1. **Container Platforms Detection**:
|
||||
- Docker: `docker ps --format json` or `docker ps -a`
|
||||
- Podman: `podman ps --format json`
|
||||
- LXC/LXD: `lxc list` or `lxd list`
|
||||
- Incus: `incus list --format json` (newer LXD fork)
|
||||
- Kubernetes: `kubectl get pods -A -o json`
|
||||
- Check for container commands: `which docker podman lxc incus kubectl`
|
||||
|
||||
2. **For Incus/LXD Specifically**:
|
||||
- List all projects: `incus project list`
|
||||
- List containers per project: `incus list --project <project_name>`
|
||||
- Default project: `incus list --project default`
|
||||
- Get container details: `incus list --format json --project <project>`
|
||||
- Check logs: `incus exec <container> --project <project> -- journalctl -n 50`
|
||||
- Alternative logs: `incus exec <container> --project <project> -- cat /var/log/syslog`
|
||||
|
||||
3. **System Services**:
|
||||
- Linux: `systemctl list-units --type=service --all --no-pager`
|
||||
- macOS: `launchctl list`
|
||||
- BSD: `service -l` or `rcctl ls all`
|
||||
- Init.d: `ls /etc/init.d/`
|
||||
|
||||
4. **Running Processes**:
|
||||
- `ps aux | grep -E "(nginx|apache|mysql|postgres|redis|mongo|elastic)"`
|
||||
- `netstat -tlnp` or `ss -tlnp` (listening services)
|
||||
- `lsof -i -P -n | grep LISTEN`
|
||||
|
||||
5. **Package-based Services**:
|
||||
- Snap: `snap list`
|
||||
- Flatpak: `flatpak list`
|
||||
- AppImage: Check common directories
|
||||
|
||||
OUTPUT FORMAT:
|
||||
You must return a comprehensive JSON structure with ALL discovered services:
|
||||
|
||||
```json
|
||||
{
|
||||
"discovery_summary": {
|
||||
"total_services": 0,
|
||||
"by_type": {
|
||||
"system_services": 0,
|
||||
"docker_containers": 0,
|
||||
"incus_containers": 0,
|
||||
"kubernetes_pods": 0,
|
||||
"standalone_processes": 0
|
||||
},
|
||||
"container_projects": ["default", "custom1", "custom2"]
|
||||
},
|
||||
"services": [
|
||||
{
|
||||
"name": "nginx",
|
||||
"type": "incus_container",
|
||||
"status": "running",
|
||||
"platform": "incus",
|
||||
"project": "default",
|
||||
"details": {
|
||||
"container_name": "web",
|
||||
"ip_addresses": ["10.18.54.166"],
|
||||
"cpu_limit": "2",
|
||||
"memory_limit": "8GiB"
|
||||
},
|
||||
"commands": {
|
||||
"logs": "incus exec web --project default -- journalctl -n 100",
|
||||
"enter": "incus exec web --project default -- bash",
|
||||
"status": "incus info web --project default",
|
||||
"restart": "incus restart web --project default"
|
||||
},
|
||||
"interesting_facts": [
|
||||
"Running Debian bookworm",
|
||||
"Has 7 snapshots",
|
||||
"Daily snapshot schedule enabled"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "postgresql",
|
||||
"type": "system_service",
|
||||
"status": "active",
|
||||
"platform": "systemd",
|
||||
"details": {
|
||||
"pid": "1234",
|
||||
"memory_usage": "256MB",
|
||||
"uptime": "5 days",
|
||||
"listening_ports": ["5432"]
|
||||
},
|
||||
"commands": {
|
||||
"logs": "journalctl -u postgresql -n 100",
|
||||
"enter": "sudo -u postgres psql",
|
||||
"status": "systemctl status postgresql",
|
||||
"restart": "systemctl restart postgresql"
|
||||
},
|
||||
"interesting_facts": [
|
||||
"Version 15.2",
|
||||
"Listening on all interfaces",
|
||||
"5 active connections"
|
||||
]
|
||||
}
|
||||
],
|
||||
"discovery_issues": [
|
||||
"Permission denied for Docker socket",
|
||||
"Kubernetes not installed"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
IMPORTANT BEHAVIORS:
|
||||
1. **Always check for Incus**: Many modern systems use Incus instead of LXC/LXD
|
||||
2. **Project awareness**: Incus/LXD uses projects - always check multiple projects
|
||||
3. **Don't assume**: Test which commands are available before using them
|
||||
4. **Comprehensive checks**: Don't stop at the first platform - check ALL platforms
|
||||
5. **Error handling**: Note when commands fail but continue discovery
|
||||
6. **Format consistency**: Always return valid JSON in the specified format
|
||||
|
||||
DISCOVERY SEQUENCE:
|
||||
1. First detect which container/virtualization platforms are installed
|
||||
2. For each platform, enumerate all services/containers
|
||||
3. Check system services (systemd, init.d, etc.)
|
||||
4. Scan for standalone processes on network ports
|
||||
5. Compile everything into the JSON format
|
||||
|
||||
Remember: Be thorough! Users often have services running in unexpected places.""",
|
||||
name="service_discovery"
|
||||
)
|
Reference in New Issue
Block a user