Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hmpf opened this issue Oct 31, 2023 · 2 comments · May be fixed by #2713
Open

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

hmpf opened this issue Oct 31, 2023 · 2 comments · May be fixed by #2713
Assignees
Labels

Comments

@hmpf
Copy link
Contributor

hmpf commented Oct 31, 2023

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
@johannaengland johannaengland self-assigned this Nov 3, 2023
@lunkwill42 lunkwill42 changed the title [BUG] Improperly caught exception/error handling when adding a new ip device [BUG] Improperly caught exception/error handling when checking device connectivity from SeedDB Nov 8, 2023
@lunkwill42
Copy link
Member

I changed the title, since this isn't actually a bug that comes from adding a device, but rather from check device connectivity with the chosen management profiles. You can still add the device without checking connectivity, and that should properly validate the IP address input.

@lunkwill42
Copy link
Member

lunkwill42 commented Nov 8, 2023

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

Also, by "ip-address that does not exist", I assume you mean "an invalid ip-address" ? If a valid address is entered, but no device has that ip address, the address could be said to not exist, but that will not crash the UI AFAIK, it will properly report that the device isn't responding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants