Skip to content

[BUG] Improperly caught exception/error handling when checking device connectivity from SeedDB #2696

@hmpf

Description

@hmpf

Describe the bug

Attempt to add an ip-device in seeddb with a hostname/ip-address that does not exist.

To Reproduce

Steps to reproduce the behavior:

  1. Go to '/seeddb/netbox/add/'
  2. Click on 'Add new ip device'
  3. Fill in the form but use a non-existent ip-address or non-existent hostname in "Ip device"
  4. Click "Check Connectivity"
  5. Get the error-message "Error during SNMP-request" and the following exception in the logs:
[Tue Oct 31 10:34:15 2023] [ERROR] [pid=135 zen.pynetsnmp.netsnmp] b's: Unknown host (333.333.333.333:161)\n'
Internal Server Error: /seeddb/netbox/get-read-only-variables/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/python/nav/web/seeddb/page/netbox/edit.py", line 153, in get_read_only_variables
    response = get_snmp_read_only_variables(ip_address, profile)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/python/nav/web/seeddb/page/netbox/edit.py", line 183, in get_snmp_read_only_variables
    result["type"] = get_type_id(ip_address, profile)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/python/nav/web/seeddb/page/netbox/edit.py", line 259, in get_type_id
    netbox_type = snmp_type(
                  ^^^^^^^^^^
  File "/source/python/nav/web/seeddb/page/netbox/edit.py", line 268, in snmp_type
    snmp = Snmp(ip_addr, snmp_ro, snmp_version)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/python/nav/Snmp/pynetsnmp.py", line 110, in __init__
    self.handle.open()
  File "/usr/local/lib/python3.11/site-packages/pynetsnmp/netsnmp.py", line 574, in open
    raise SnmpError('snmp_open')
pynetsnmp.netsnmp.SnmpError: snmp_open
[Tue Oct 31 10:34:15 2023] [ERROR] [pid=135 django.request] Internal Server Error: /seeddb/netbox/get-read-only-variables/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/python/nav/web/seeddb/page/netbox/edit.py", line 153, in get_read_only_variables
    response = get_snmp_read_only_variables(ip_address, profile)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/python/nav/web/seeddb/page/netbox/edit.py", line 183, in get_snmp_read_only_variables
    result["type"] = get_type_id(ip_address, profile)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/python/nav/web/seeddb/page/netbox/edit.py", line 259, in get_type_id
    netbox_type = snmp_type(
                  ^^^^^^^^^^
  File "/source/python/nav/web/seeddb/page/netbox/edit.py", line 268, in snmp_type
    snmp = Snmp(ip_addr, snmp_ro, snmp_version)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/python/nav/Snmp/pynetsnmp.py", line 110, in __init__
    self.handle.open()
  File "/usr/local/lib/python3.11/site-packages/pynetsnmp/netsnmp.py", line 574, in open
    raise SnmpError('snmp_open')
pynetsnmp.netsnmp.SnmpError: snmp_open
[31/Oct/2023 10:34:15] "GET /seeddb/netbox/get-read-only-variables/?ip_address=333.333.333.333&profiles%5B%5D=1 HTTP/1.1" 500 88684

Expected behavior

I expect to get an error-message that something is wrong with the ip-address or hostname, that there is no exception in the logs, and that the attempt is not logged as a 500 Sever error in the access log.

Environment (please complete the following information):

  • "docker compose up"
  • debian bullseye
  • Nav is latest master

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions