mirror of
https://github.com/dtzp555-max/network-mcp-server.git
synced 2026-07-21 21:15:08 +00:00
feat: Network MCP Server v0.1.0 — SNMP backend with 5 tools
MVP with zero-dependency SNMP backend for AI-powered network management: - get_snmp_value: query single OID - walk_snmp_tree: walk OID subtree - get_device_info: vendor auto-detection, uptime, location - get_interfaces: interface status with human-readable output - discover_devices: subnet SNMP discovery Tech: FastMCP + pysnmp-lextudio, Python 3.10+ Works with: Cisco, Juniper, Arista, UniFi, Fortinet, and any SNMP device 23 tests passing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"""Tests for configuration module."""
|
||||
|
||||
import os
|
||||
|
||||
from network_mcp.config import get_default_community, get_snmp_timeout
|
||||
|
||||
|
||||
def test_default_community_from_env(monkeypatch):
|
||||
monkeypatch.setenv("SNMP_COMMUNITY", "my_secret")
|
||||
assert get_default_community() == "my_secret"
|
||||
|
||||
|
||||
def test_default_community_fallback(monkeypatch):
|
||||
monkeypatch.delenv("SNMP_COMMUNITY", raising=False)
|
||||
# Without config file, should return "public"
|
||||
monkeypatch.setenv("NETWORK_MCP_CONFIG_DIR", "/tmp/nonexistent-mcp-test")
|
||||
assert get_default_community() == "public"
|
||||
|
||||
|
||||
def test_snmp_timeout_from_env(monkeypatch):
|
||||
monkeypatch.setenv("SNMP_TIMEOUT", "10.0")
|
||||
assert get_snmp_timeout() == 10.0
|
||||
|
||||
|
||||
def test_snmp_timeout_default(monkeypatch):
|
||||
monkeypatch.delenv("SNMP_TIMEOUT", raising=False)
|
||||
assert get_snmp_timeout() == 5.0
|
||||
@@ -0,0 +1,82 @@
|
||||
"""Tests for SNMP OID utilities."""
|
||||
|
||||
from network_mcp.snmp.oids import detect_vendor, format_bytes, format_speed, format_uptime
|
||||
|
||||
|
||||
def test_detect_vendor_cisco():
|
||||
assert detect_vendor("Cisco IOS Software, C2960 Software") == "Cisco"
|
||||
|
||||
|
||||
def test_detect_vendor_juniper():
|
||||
assert detect_vendor("Juniper Networks, Inc. ex4300") == "Juniper"
|
||||
|
||||
|
||||
def test_detect_vendor_ubiquiti():
|
||||
assert detect_vendor("Linux ubnt 4.14.0 UniFi Dream Machine") == "Ubiquiti"
|
||||
|
||||
|
||||
def test_detect_vendor_arista():
|
||||
assert detect_vendor("Arista Networks EOS version 4.28") == "Arista"
|
||||
|
||||
|
||||
def test_detect_vendor_fortinet():
|
||||
assert detect_vendor("FortiGate-60F v7.2.0") == "Fortinet"
|
||||
|
||||
|
||||
def test_detect_vendor_mikrotik():
|
||||
assert detect_vendor("RouterOS 7.12") == "MikroTik"
|
||||
|
||||
|
||||
def test_detect_vendor_unknown():
|
||||
assert detect_vendor("Some Unknown Device") == "Unknown"
|
||||
|
||||
|
||||
def test_detect_vendor_case_insensitive():
|
||||
assert detect_vendor("CISCO IOS XE") == "Cisco"
|
||||
|
||||
|
||||
def test_format_uptime_days():
|
||||
# 2 days, 3 hours, 4 minutes, 5 seconds = 183845 seconds * 100
|
||||
assert format_uptime(18384500) == "2d 3h 4m 5s"
|
||||
|
||||
|
||||
def test_format_uptime_hours():
|
||||
assert format_uptime(370500) == "1h 1m 45s"
|
||||
|
||||
|
||||
def test_format_uptime_minutes():
|
||||
assert format_uptime(12000) == "2m 0s"
|
||||
|
||||
|
||||
def test_format_speed_gbps():
|
||||
assert format_speed(1_000_000_000) == "1 Gbps"
|
||||
assert format_speed(10_000_000_000) == "10 Gbps"
|
||||
|
||||
|
||||
def test_format_speed_mbps():
|
||||
assert format_speed(100_000_000) == "100 Mbps"
|
||||
assert format_speed(1_000_000) == "1 Mbps"
|
||||
|
||||
|
||||
def test_format_speed_kbps():
|
||||
assert format_speed(64_000) == "64 Kbps"
|
||||
|
||||
|
||||
def test_format_bytes_tb():
|
||||
assert "TB" in format_bytes(2_000_000_000_000)
|
||||
|
||||
|
||||
def test_format_bytes_gb():
|
||||
assert "GB" in format_bytes(5_000_000_000)
|
||||
|
||||
|
||||
def test_format_bytes_mb():
|
||||
assert "MB" in format_bytes(50_000_000)
|
||||
|
||||
|
||||
def test_format_bytes_kb():
|
||||
assert "KB" in format_bytes(50_000)
|
||||
|
||||
|
||||
def test_format_bytes_bytes():
|
||||
assert format_bytes(500) == "500 B"
|
||||
Reference in New Issue
Block a user