CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pysnmp

A comprehensive Python SNMP library supporting v1/v2c/v3 with authentication and privacy protocols

84

0.94x
Overview
Eval results
Files

task.mdevals/scenario-5/

Network Device Monitor

Build a network device monitoring tool that retrieves system information from network devices using SNMP GET operations.

Requirements

Create a Python program that connects to a network device via SNMP and retrieves specific system information. The program should:

  1. Accept connection parameters (hostname, port, and community string)
  2. Retrieve the following system information using individual GET requests:
    • System description (OID: 1.3.6.1.2.1.1.1.0)
    • System uptime (OID: 1.3.6.1.2.1.1.3.0)
    • System contact (OID: 1.3.6.1.2.1.1.4.0)
    • System name (OID: 1.3.6.1.2.1.1.5.0)
  3. Handle errors gracefully (network errors, authentication failures, missing objects)
  4. Return the retrieved information as a dictionary with keys: description, uptime, contact, name

Implementation

@generates

API

import asyncio
from typing import Dict, Optional

async def get_device_info(hostname: str, port: int = 161, community: str = "public") -> Dict[str, Optional[str]]:
    """
    Retrieve system information from a network device using SNMP GET operations.

    Args:
        hostname: The hostname or IP address of the device
        port: The SNMP port (default: 161)
        community: The SNMP community string (default: "public")

    Returns:
        A dictionary containing:
        - description: System description string
        - uptime: System uptime value
        - contact: System contact information
        - name: System name

        If an error occurs retrieving a specific value, that key should contain None.

    Raises:
        Exception: If unable to establish SNMP connection or critical error occurs
    """
    pass

Test Cases

  • Given valid connection parameters and a reachable SNMP device, the function returns a dictionary with all four system information fields populated @test
  • Given an invalid hostname, the function raises an appropriate exception @test
  • Given valid connection but one OID is not available on the device, the function returns a dictionary with that field set to None while other fields are populated @test

Dependencies { .dependencies }

pysnmp { .dependency }

Provides SNMP protocol implementation for network device communication.

Install with Tessl CLI

npx tessl i tessl/pypi-pysnmp

tile.json