dainok / netdoc

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

Issue when Update IPAM from ARP tables #113

Closed dietybright closed 8 months ago

dietybright commented 9 months ago

when running report IPAMFromARP, it is showing error without any other message, not sure where is the issue

Check corrispondence between ARP table and IPAM

Started: 2024-01-02 18:00 Duration: 0 minutes, 0.10 seconds Errored Report Methods Report Results Time Level

dietybright commented 9 months ago

I would like to delete arp entry one by one and make a test on netdoc but seem no delete option on GUI/API

when trying to run report/script by python cli, I am getting below output, not sure where is the source issue from netdoc arp table

ubuntu@netbox:~$ sudo /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runscript --loglevel debug netdoc_scripts.IPAMFromARP [2024-01-03 10:39:47,889][INFO] - Running script (commit=False) [2024-01-03 10:39:47,899][ERROR] - An exception occurred: AttributeError: 'NoneType' object has no attribute 'address'

Traceback (most recent call last):
  File "/opt/netbox/netbox/extras/management/commands/runscript.py", line 45, in _run_script
    script.output = script.run(data=data, commit=commit)
  File "/opt/netbox/netbox/scripts/netdoc_scripts.py", line 443, in run
    .address.prefixlen
AttributeError: 'NoneType' object has no attribute 'address'

[2024-01-03 10:39:47,899][INFO] - Database changes have been reverted due to error. [2024-01-03 10:39:47,900][ERROR] - Exception raised during script execution: 'NoneType' object has no attribute 'address' [2024-01-03 10:39:47,907][INFO] - Script completed in 0 minutes, 0.01 seconds

ubuntu@netbox:~$ sudo /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runreport netdoc_reports.IPAMFromARP
[03:40:27] Running netdoc_reports.IPAMFromARP... 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.10/site-packages/django/core/management/init.py", line 446, in execute_from_command_line utility.execute() File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/init.py", line 440, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv self.execute(*args, *cmd_options) File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute output = self.handle(args, **options) File "/opt/netbox/netbox/extras/management/commands/runreport.py", line 49, in handle for test_name, attrs in job.data.items(): AttributeError: 'NoneType' object has no attribute 'items'

dainok commented 8 months ago

Hi! Sorry for the delay.

In the first message you are writing about report, on the second one you are writing about script. On my small lab both are working fine, so I need additional help from you.

I think you are using an old version of netbox. 2 months ago I fixed a bug (maybe the one you are encountering) and current source file looks different from yours (https://github.com/dainok/netdoc/blob/master/netdoc/jobs/netdoc_scripts.py see line 443)

dietybright commented 8 months ago

Hi @dainok ,

Actually I used to new version 3.5.15, netdoc_scripts.py is the same on my env but not sure why when running the script it showing the error on row 443.

Can you have a look on the error log when run report as above message

dainok commented 8 months ago

@dietybright can you verify the md5?

md5sum /opt/netbox/netbox/scripts/netdoc_scripts.py

You should get 8f67adee4364f8a997feefa8ac90daf9. If not please overwrite with the one in the netdoc repository.

dietybright commented 8 months ago

I was the same with original one

8f67adee4364f8a997feefa8ac90daf9 /opt/netbox/netbox/scripts/netdoc_scripts.py

dainok commented 8 months ago

@dietybright can you please check if you have ARP entries without IP address? It should not happen, but this could be the cause.

dietybright commented 8 months ago

All arp entries have IP address, some entry having mac-address 00:00:00:00:00:00, do you think this is the cause?

dainok commented 8 months ago

No, 0 should be supported even if I don't expect it. Can you put a print before the failing line and check which entry is failing?

dietybright commented 8 months ago

I tried to add print(address) under line446 opt/netbox/netbox/scripts/netdoc_scripts.py, but whenever excute command "sudo /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runscript --loglevel debug netdoc_scripts.IPAMFromARP" it will override all the change

dainok commented 8 months ago

Better if you use logging.error(item)

dietybright commented 8 months ago

Hi @dainok , could you share more specific where should I put logging.error(item) to find down the issue, I tried to put logging.error(address) at line 446 but still not able to show up the detail debug

dainok commented 8 months ago

Try the following:

    # IP address with prefixlen built from ARP table and associated interface
            logging.error(arptableentry_o) # <- ADD THIS LINE
            address = str(arptableentry_o.ip_address.ip)
            prefixlen = (
                arptableentry_o.interface.ip_addresses.filter(
                    address__net_contains_or_equals=address
                )
                .first()
                .address.prefixlen
            )
            ip_address = f"{address}/{prefixlen}"
dietybright commented 8 months ago

Hi @dainok ,

It still same, everytime I run command "sudo /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py runscript --loglevel debug netdoc_scripts.IPAMFromARP", the added command under /opt/netbox/netbox/scripts/netdoc_scripts.py gone, any idea?

dainok commented 8 months ago

yes, you have to modify the script in the netdoc folder, not in netbox. This happens because every time netbox is started (server or rq) scripts are updated from netdoc folder.

dietybright commented 8 months ago

Got the cause now,

[2024-01-29 17:43:19,886][INFO] - Running script (commit=False) ERROR:root:0.0.0.0/32 has AA:AE:20:11:04:38 at ae1.2011 (ae1.2011) [2024-01-29 17:43:20,760][ERROR] - An exception occurred: AttributeError: 'NoneType' object has no attribute 'address'

@dainok can we ignore 0.0.0.0/32 ?

dainok commented 8 months ago

That's interesting you have an ARP for 0.0.0.0 :) Let me think about how to avoid this.

dietybright commented 8 months ago

@dainok anyway we can delete netdoc arp entry manually? I will try to delete those 0.0.0.0 and try again

dainok commented 8 months ago

Yes, using netbox shell

from netdoc import models
models.ArpTableEntry.objects.filter(...your filter...).delete()
dainok commented 8 months ago

@dietybright can you test https://github.com/dainok/netdoc/pull/118/files#diff-e47e1cf1303729ba095a497f2ae002ebc328d27006f8178755d2721b1e3f0884

dietybright commented 8 months ago

It worked, thank @dainok