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-4/

SNMP Network Device Poller

Build a simple network device poller that retrieves system information from network devices using SNMPv1. The poller should query specific device metrics and handle common error scenarios.

Requirements

Your implementation should:

  1. Query a network device for system information using SNMPv1 protocol
  2. Retrieve the following standard MIB-II system variables:
    • sysDescr (1.3.6.1.2.1.1.1.0) - System description
    • sysUpTime (1.3.6.1.2.1.1.3.0) - System uptime
    • sysContact (1.3.6.1.2.1.1.4.0) - System contact
    • sysName (1.3.6.1.2.1.1.5.0) - System name
  3. Use community string-based authentication
  4. Handle timeout errors gracefully
  5. Handle authentication failures (wrong community string)
  6. Return results in a structured format

The poller should accept the following parameters:

  • Device IP address
  • Community string (for authentication)
  • Timeout value (in seconds)

Test Cases

  • Successfully retrieves all four system variables when given valid credentials @test
  • Returns a timeout error when the device is unreachable @test
  • Returns an authentication error when an invalid community string is used @test

Implementation

@generates

API

def poll_device(device_ip: str, community: str, timeout: int = 2) -> dict:
    """
    Poll a network device using SNMPv1 to retrieve system information.

    Args:
        device_ip: IP address of the target device
        community: SNMP community string for authentication
        timeout: Timeout in seconds (default: 2)

    Returns:
        A dictionary containing:
        - 'success': Boolean indicating if the poll succeeded
        - 'data': Dictionary with keys 'sysDescr', 'sysUpTime', 'sysContact', 'sysName'
                 (only present if success is True)
        - 'error': Error message string (only present if success is False)

    Example success response:
        {
            'success': True,
            'data': {
                'sysDescr': 'Linux device 5.4.0',
                'sysUpTime': '1234567',
                'sysContact': 'admin@example.com',
                'sysName': 'router-01'
            }
        }

    Example error response:
        {
            'success': False,
            'error': 'Authentication failed'
        }
    """
    pass

Dependencies { .dependencies }

pysnmp { .dependency }

Provides SNMP protocol implementation for querying network devices.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/pypi-pysnmp

tile.json