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

Network Interface Monitor

A command-line utility for monitoring SNMP agents on different network interfaces in a multi-homed system.

Background

In multi-homed systems (systems with multiple network interfaces), you may need to send SNMP requests from specific network interfaces. This is common when:

  • Different network interfaces connect to different network segments
  • You need to test connectivity through specific interfaces
  • Firewall rules or routing requires requests from specific source addresses

Your task is to build a monitoring utility that can query SNMP agents while specifying which local network interface to use for sending requests.

Requirements

Command-line Interface

The utility should accept the following command-line arguments:

  • --target: The SNMP agent address (IP or hostname)
  • --community: The SNMP community string (default: "public")
  • --local-addr: The local IP address/interface to bind to
  • --oid: The OID to query (default: "1.3.6.1.2.1.1.1.0" - sysDescr)

Core Functionality

The utility should:

  1. Configure SNMP transport to bind to the specified local interface address
  2. Send an SNMP GET request to retrieve the specified OID from the target agent
  3. Display the result in a readable format showing:
    • The queried OID
    • The returned value
    • Any errors that occurred

Output Format

On success, output should be:

OID: <oid>
Value: <value>

On error, output should be:

Error: <error description>

Test Cases

  • When binding to local address "127.0.0.1" and querying localhost agent on port 1161, it successfully retrieves the sysDescr OID and displays the result @test

  • When an invalid local address is provided (e.g., "999.999.999.999"), it displays an appropriate error message @test

  • When the target agent is unreachable or times out, it displays a timeout error message @test

Implementation

@generates

API

"""
Network interface monitor for SNMP queries on multi-homed systems.
"""

def query_snmp(target: str, community: str, local_addr: str, oid: str) -> tuple[str, str | None]:
    """
    Query an SNMP agent using a specific local network interface.

    Args:
        target: SNMP agent address (IP:port or hostname:port)
        community: SNMP community string
        local_addr: Local IP address to bind to
        oid: OID to query

    Returns:
        A tuple of (result_message, error_message).
        If successful, result_message contains the formatted output and error_message is None.
        If failed, result_message is None and error_message contains the error description.
    """
    pass

def main():
    """
    Main entry point for the command-line utility.
    Parses arguments and calls query_snmp().
    """
    pass

if __name__ == "__main__":
    main()

Dependencies { .dependencies }

pysnmp { .dependency }

Provides SNMP protocol implementation with support for local interface binding.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/pypi-pysnmp

tile.json