TheNetworkGuy / netbox-zabbix-sync

Python script to synchronise Netbox devices to Zabbix.
MIT License
109 stars 27 forks source link

AttributeError: object has no attribute "name" #22

Closed rasulovk closed 1 year ago

rasulovk commented 1 year ago

Version of netbox : 1b92ee3a14d6 (v3.3.2)

Python 3 version: Python 3.9.2

Zabbix version: Zabbix 5.4.8

After adding Primary IP in netbox following error occurs:

Traceback (most recent call last): File "/home/devlin/Docker/netbox/netbox-zabbix-sync/netbox_zabbix_sync.py", line 740, in main(args) File "/home/devlin/Docker/netbox/netbox-zabbix-sync/netbox_zabbix_sync.py", line 83, in main device = NetworkDevice(nb_device, zabbix, netbox_journals, File "/home/devlin/Docker/netbox/netbox-zabbix-sync/netbox_zabbix_sync.py", line 191, in init self._setBasics() File "/home/devlin/Docker/netbox/netbox-zabbix-sync/netbox_zabbix_sync.py", line 212, in _setBasics f"found for {self.nb.device_type.name}.") File "/home/devlin/.local/lib/python3.9/site-packages/pynetbox/core/response.py", line 298, in getattr raise AttributeError('object has no attribute "{}"'.format(k)) AttributeError: object has no attribute "name"

TheNetworkGuy commented 1 year ago

I will look at this later today, thank you for mentioning this issue.

rasulovk commented 1 year ago

@TheNetworkGuy Hi, any updates ?

TheNetworkGuy commented 1 year ago

Good day, i have checked out the code today but unfortunately i am unable to replicate the issue. The only explanation that i can give is that you are trying to sync a Netbox device which you haven't given a name. I haven't made a check for this specific scenario. Can you confirm that all the devices which you are trying to sync also have a name in Netbox?

rasulovk commented 1 year ago

@TheNetworkGuy Sorry for late reply. Configuration screenshot has been attached.

Screen Shot 2022-11-24 at 22 05 15
rasulovk commented 1 year ago

@TheNetworkGuy If I remove IP address from "Primary IPv4", then script will work.

TheNetworkGuy commented 1 year ago

This behaviour is expected since the script will skip any devices which do not have a valid primary IPv4 address.

Can you share on how you are running the script and with what parameters? And can you confirm that the name does not have any special characters in it? Does changing the device name (temporary) in Netbox result in a good sync?

Thank you for sharing the device details, i'll try to replicate the setup.

TheNetworkGuy commented 1 year ago

By the way i just took a better look at your setup and it seems that you haven't created any custom fields for the Zabbix ID. Is this assumption correct? https://github.com/TheNetworkGuy/netbox-zabbix-sync#netbox-settings

Although this should be triggering an error anyways: 2022-11-24 19:46:15,327 - Netbox-Zabbix-sync - WARNING - Custom field zabbix_hostid not found for device123.

TheNetworkGuy commented 1 year ago

Yes i can replicate the issue now. It seems that when the NB custom field for Zabbix templates is not configured the script tries to warn you for this by mentioning the device type name. However this value has been modified by Netbox to the display variable. I'll push the code later today, meanwhile your problem will be fixed by adding the 2 custom fields like i mentioned previously :) If you have any other questions feel free to let me know with a new issue.

rasulovk commented 1 year ago

@TheNetworkGuy Oh yes, I don't understand how to configure it. I did only SNMP part

Screen Shot 2022-11-25 at 18 56 11

Could you please show me what I did wrong, I don't want see this error: ) " 2022-11-24 19:46:15,327 - Netbox-Zabbix-sync - WARNING - Custom field zabbix_hostid not found for device123."

Thanks in advance

TheNetworkGuy commented 1 year ago

The config context data is not required if you are using the default Zabbix parameters. If you don't specify the config context then the following default interface config will be applied:

The Zabbix macro {$SNMP_COMMUNITY} will by default resolve to "public". You can verify this under the Zabbix menu Administration -> General -> Macros.

So to summarize, the default script implementation will do exactly what you have in your config context data. It won't hurt or anything but right now it does not provide anything extra either :)

As for your other question, create 2 custom fields as mentioned here: https://github.com/TheNetworkGuy/netbox-zabbix-sync#custom-fields. Steps on how to create custom fields can be found here: https://docs.netbox.dev/en/stable/customization/custom-fields/. If you do these steps then the error will go away.

To help you understand why you need these 2 fields:

rasulovk commented 1 year ago

@TheNetworkGuy I feel I'm close to proper configuration, just last question: Am I right now? :

Screen Shot 2022-11-25 at 23 16 55 Screen Shot 2022-11-25 at 23 17 21 Screen Shot 2022-11-25 at 23 17 54

Looks like I missed something :)

TheNetworkGuy commented 1 year ago

This looks great, custom fields are OK.

The script tells you that the hostgroup "ATS building/Fortinet/Access switch" does not exist in Zabbix. You can fix this in 2 ways.

Create the hostgroup manually

Recommended for testing purposes (like you are doing right now!) This method allows you to manually add a single or couple of hostgroups so that you can double check everything before potentially nuking your production Zabbix setup.

Use the -H flag to let the script create the hostgroup for you.

If you are using a Zabbix account with permissions to create hostgroups, i would recommend going for the -H flag. https://github.com/TheNetworkGuy/netbox-zabbix-sync#flags. Keep in mind that this can create a lot of hostgroups. If the format is to your liking then that's fine but i would use the -H flag first in a testing environment. If the Zabbix installation that you are using is not production than this should be fine.

Also all of this tells me that i need to update the documentation and provide better examples of different types of configuration to make everyone's life easier. But that's for another day :)

rasulovk commented 1 year ago

@TheNetworkGuy Thanks a lot. I would to new feature, I'm using "oxidized" solution for backup network equipment, Can we add new script to add network name and ip to "oxidized" text configuration?

https://github.com/ytti/oxidized

TheNetworkGuy commented 1 year ago

@rasulovk Glad that you got it working.

As for Oxidized, we use this as well with Netbox. However instead of using a script to add data to a text file, use the HTTP source. I cannot explain everything since this goes way out of the scope of Netbox - Zabbxi sync. But please check this post, it uses the Netbox API to provision the Oxidized inventory. https://www.reddit.com/r/networking/comments/o78vvp/comment/h3b934o/?utm_source=reddit&utm_medium=web2x&context=3

rasulovk commented 1 year ago

@TheNetworkGuy thanks a lot, you help me a lot.