dainok / netdoc

Automatic Network Documentation plugin for NetBox
GNU General Public License v3.0
91 stars 14 forks source link

Support NetBox 3.6 #69

Open cmong-nextech opened 1 year ago

cmong-nextech commented 1 year ago

When using the script to add and discover an object, the following failure is logged:

`An exception occurred: DoesNotExist: ScriptModule matching query does not exist.

Traceback (most recent call last): File "/opt/netbox/netbox/extras/scripts.py", line 504, in _run_script script.output = script.run(data=data, commit=commit) File "/opt/netbox/netbox/scripts/netdoc_scripts.py", line 180, in run output = discovery( File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/tasks.py", line 124, in discovery utils.spawn_script("Ingest") File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/utils.py", line 1160, in spawn_script module = ScriptModule.objects.get(data_path="netdoc_scripts.py") File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/manager.py", line 87, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/query.py", line 637, in get raise self.model.DoesNotExist( extras.models.scripts.ScriptModule.DoesNotExist: ScriptModule matching query does not exist.`

cmong-nextech commented 1 year ago

Here's a django log showing similar information:

Internal Server Error: /plugins/netdoc/discoverable/2/discover/ Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/views/generic/base.py", line 104, in view return self.dispatch(request, *args, *kwargs) File "/opt/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch return super().dispatch(request, args, kwargs) File "/opt/netbox/netbox/utilities/views.py", line 99, in dispatch return super().dispatch(request, *args, kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/views/generic/base.py", line 143, in dispatch return handler(request, *args, *kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/views.py", line 393, in post utils.spawn_script("Discover", user=request.user, post_data=data) File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/utils.py", line 1160, in spawn_script module = ScriptModule.objects.get(data_path="netdoc_scripts.py") File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/manager.py", line 87, in manager_method return getattr(self.get_queryset(), name)(args, kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/query.py", line 637, in get raise self.model.DoesNotExist( extras.models.scripts.ScriptModule.DoesNotExist: ScriptModule matching query does not exist.

cmong-nextech commented 1 year ago

I apologize for the repeated comments here. Here is a partial success when using the "discover_immediate" script via cli:

Running task 'multiple_tasks' with args {} on 1 hosts Host '10.10.69.254': running task 'multiple_tasks' Host '10.10.69.254': running task '{"command": "show version", "template": "HOSTNAME", "enable": true, "order": 0}' Host '10.10.69.254': task '{"command": "show version", "template": "HOSTNAME", "enable": true, "order": 0}' failed with traceback: Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.9/site-packages/nornir/core/task.py", line 99, in start r = self.task(self, **self.params) File "/opt/netbox/venv/lib/python3.9/site-packages/nornir_netmiko/tasks/netmiko_send_command.py", line 28, in netmiko_send_command net_connect.enable() File "/opt/netbox/venv/lib/python3.9/site-packages/netmiko/cisco_base_connection.py", line 25, in enable return super().enable( File "/opt/netbox/venv/lib/python3.9/site-packages/netmiko/base_connection.py", line 1942, in enable raise ValueError(msg) ValueError: Failed to enter enable mode. Please ensure you pass the 'secret' argument to ConnectHandler.

Host '10.10.69.254': task 'multiple_tasks' failed with traceback: Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.9/site-packages/nornir/core/task.py", line 99, in start r = self.task(self, **self.params) File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/discoverers/netmiko_cisco_ios.py", line 49, in multiple_tasks utils.append_nornir_netmiko_tasks( File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/utils.py", line 243, in append_nornir_netmiko_tasks task.run( File "/opt/netbox/venv/lib/python3.9/site-packages/nornir/core/task.py", line 174, in run raise NornirSubTaskError(task=run_task, result=r) nornir.core.exceptions.NornirSubTaskError: Subtask: {"command": "show version", "template": "HOSTNAME", "enable": true, "order": 0} (failed)

Running task 'additional_tasks' with args {} on 1 hosts

dainok commented 1 year ago

You are posting 2 different errors.

Post 1 and 2 seems regarding to a unsupported version of NetBox/NetDoc. Latest NetDoc works with NetBox 3.5 only. Double check that.

Post 3 is about privilege escalation. The username used for 10.10.69.254 requires an enable password? Are you setting the password in the credential?

cmong-nextech commented 1 year ago

Thank you. I got the error from the privEsc post resolved last night; it was a radius provisioning error using AAA.

I seem to have been able to get things working better using the "scripts/discovery_netmiko_command.py" with some slight alterations. Seeing as the Netbox version is unsupported, I understand if you want to close this issue. However, if you're willing to help, maybe continuing this conversation can be productive in respect to a newer revision.

Currently when I attempt to ingest the discovery logs, the "ingest" class fails with the following stacktrace:

An exception occurred: TypeError: Device() got unexpected keyword arguments: 'device_role_id'

Traceback (most recent call last): File "/opt/netbox/netbox/extras/scripts.py", line 504, in _run_script script.output = script.run(data=data, commit=commit) File "/opt/netbox/netbox/scripts/netdoc_scripts.py", line 353, in run log_ingest(log) File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/utils.py", line 578, in log_ingest module.ingest(log) File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/ingestors/netmiko_cisco_ios_hostname.py", line 36, in ingest device_o = device.create(data) File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/schemas/device.py", line 108, in create obj = utils.object_create(Device, kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/netdoc/utils.py", line 1055, in object_create return model_o.objects.create(kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/manager.py", line 87, in manager_method return getattr(self.get_queryset(), name)(args, kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/query.py", line 656, in create obj = self.model(kwargs) File "/opt/netbox/netbox/utilities/tracking.py", line 41, in init super().init(args, kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/base.py", line 567, in init raise TypeError( TypeError: Device() got unexpected keyword arguments: 'device_role_id'

dainok commented 1 year ago

If you are using Netbox 3.4, please downgrade NetDoc to 0.10.34.

cmong-nextech commented 1 year ago

I am using Netbox 3.6.1

dainok commented 1 year ago

Ok, I'll keep this open, but at the moment I'm not working on NetBox 3.6.x

cmong-nextech commented 1 year ago

I got this working by changing the "device_role_id" parameter to "role_id". Ingestion is now working for "show cdp neighbors detail"

Now I'm receiving the follow stacktrace after attempting to ingest "show lldp neighbors detail"

Traceback (most recent call last): File "/opt/netbox/netbox/manage.py", line 10, in execute_from_command_line(sys.argv) File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/management/init.py", line 442, in execute_from_command_line utility.execute() File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/management/init.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv self.execute(*args, cmd_options) File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute output = self.handle(*args, *options) File "/opt/netbox/venv/lib/python3.9/site-packages/django/core/management/commands/shell.py", line 127, in handle exec(sys.stdin.read(), globals()) File "", line 37, in File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/query.py", line 1436, in filter return self._filter_or_exclude(False, args, kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/query.py", line 1454, in _filter_or_exclude clone._filter_or_exclude_inplace(negate, args, kwargs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/query.py", line 1461, in _filter_or_exclude_inplace self._query.add_q(Q(args, kwargs)) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1545, in addq clause, = self._add_q(q_object, self.used_aliases) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1576, in _add_q child_clause, needed_inner = self.build_filter( File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1491, in build_filter condition = self.build_lookup(lookups, col, value) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/sql/query.py", line 1318, in build_lookup lookup = lookup_class(lhs, rhs) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/lookups.py", line 27, in init self.rhs = self.get_prep_lookup() File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/lookups.py", line 426, in get_prep_lookup return super().get_prep_lookup() File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/lookups.py", line 276, in get_prep_lookup rhs_value = self.lhs.output_field.get_prep_value(rhs_value) File "/opt/netbox/venv/lib/python3.9/site-packages/django/db/models/fields/init.py", line 2218, in get_prep_value if value and ":" in value: TypeError: argument of type 'int' is not iterable

dainok commented 1 year ago

Which NetDoc version are you using?

cmong-nextech commented 1 year ago

Version 3.5.0

dainok commented 1 year ago

Found the error: I forgot to release 3.5.1. 3.5.0 should not be used. Please wait a few minutes and update to 3.5.1. Mind that 3.5.1 is tested with NetBox 3.5.

fatman00 commented 1 year ago

Hi @dainok

Any timeline on getting this to work with netbox 3.6.x?

dainok commented 1 year ago

Not at this time.