PalisadoesFoundation / switchmap-ng

A Python 3 inventory system that tabulates the status of network ports.
Apache License 2.0
16 stars 7 forks source link

device.py crashes for some NX-OS gear #127

Open dcthor opened 1 year ago

dcthor commented 1 year ago

device.py crashes for some NX-OS gear, for example Nexus 9k NX-OS 7.x

For some reason the ifindex within the ifStackStatus doesn't exist for this OS. I set up a try/except and it will prevent the code from crashing, but might not be the best choice. Before I PR I thought it best to discuss here first:

At row 250 -- Original code

                higherlayers = updated_device_data[
                    'system']['IF-MIB']['ifStackStatus'][ifindex]

Code suggestion

                try:
                    higherlayers = updated_device_data[
                        'system']['IF-MIB']['ifStackStatus'][ifindex]
                except:
                    log_message = (
                        'host {} missing ifindex {}'.format(self._devicename,ifindex))
                    log.log2debug(1029, log_message)
                    higherlayers = []

Note: Note, I think it'd be best to remove the log_message from my test code before doing the PR... it does fill the logfile... here's a small subset:

2023-02-10 13:27:33,323 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526649728
2023-02-10 13:27:33,324 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526649792
2023-02-10 13:27:33,324 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526649856
2023-02-10 13:27:33,324 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526649920
2023-02-10 13:27:33,324 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526649984
2023-02-10 13:27:33,324 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526650048
2023-02-10 13:27:33,324 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526650112
2023-02-10 13:27:33,324 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526650176
2023-02-10 13:27:33,324 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526650240
2023-02-10 13:27:33,324 - switchmap_file - DEBUG - [dcthor] (1029S): host <host-removed> missing ifindex 526650304