napalm icon indicating copy to clipboard operation
napalm copied to clipboard

nxos_ssh get_environment fails to parse temperature info

Open raa-1 opened this issue 1 year ago • 0 comments

Description of Issue/Question

My Nexus 3000 switch gives this as an output of show environment temperature command:

swi-01# show environment temperature 
Temperature:
-------------------------------------------------------------------------
Module  Sensor             MajorThresh   MinorThres   CurTemp     Status 
                           (Celsius)     (Celsius)   (Celsius)           
-------------------------------------------------------------------------
1        Back-Right (D0)   70            44            27         Ok             
1        Back-Left  (D1)   70            42            28         Ok             
1        Front-Right(D2)   70            47            29         Ok             
1        Front-Left (D3)   70            49            35         Ok    

This code splits the line, but it doesn't expect there are whitespaces in the Sensor value, thus unpacking fails.

I suggest using something like this:

module, sensor, is_critical, is_alert, temp, _ = re.match(r'(\d+)\s+(.*?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\w+)\s+$', line).groups()

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

(Place an x between the square brackets where applicable)

  • [x] Yes
  • [] No

Setup

napalm version

(Paste verbatim output from pip freeze | grep napalm between quotes below)

napalm==4.1.0
nornir-napalm==0.4.0

Network operating system version

(Paste verbatim output from show version - or equivalent - between quotes below)

Cisco Nexus Operating System (NX-OS) Software
TAC support: http://www.cisco.com/tac
Copyright (C) 2002-2020, Cisco and/or its affiliates.
All rights reserved.
The copyrights to certain works contained in this software are
owned by other third parties and used and distributed under their own
licenses, such as open source.  This software is provided "as is," and unless
otherwise stated, there is no warranty, express or implied, including but not
limited to warranties of merchantability and fitness for a particular purpose.
Certain components of this software are licensed under
the GNU General Public License (GPL) version 2.0 or 
GNU General Public License (GPL) version 3.0  or the GNU
Lesser General Public License (LGPL) Version 2.1 or 
Lesser General Public License (LGPL) Version 2.0. 
A copy of each such license is available at
http://www.opensource.org/licenses/gpl-2.0.php and
http://opensource.org/licenses/gpl-3.0.html and
http://www.opensource.org/licenses/lgpl-2.1.php and
http://www.gnu.org/licenses/old-licenses/library.txt.

Software
  BIOS: version 4.5.0
  NXOS: version 7.0(3)I7(8)
  BIOS compile time:  11/09/2017
  NXOS image file is: bootflash:///nxos.7.0.3.I7.8_3064_compact.bin
  NXOS compile time:  3/3/2020 20:00:00 [03/04/2020 04:49:49]


Hardware
  cisco Nexus3000 C3064PQ Chassis 
  Intel(R) Celeron(R) CPU        P4505  @ 1.87GHz with 3902972 kB of memory.
  Processor Board ID FOC1733313D

  Device name: ulv-swi-01
  bootflash:    1638000 kB
  usb1:               0 kB (expansion flash)

Kernel uptime is 706 day(s), 18 hour(s), 37 minute(s), 22 second(s)

Last reset 
  Reason: Reload due to unknown reason, possible power loss
  System version: 7.0(3)I7(8)
  Service: 

plugin
  Core Plugin, Ethernet Plugin

Active Package(s):

Steps to Reproduce the Issue

napalm --debug --user USER --vendor nxos_ssh --password '' --optional "ssh_config_file='/ssh_config_with_ProxyCommand',key_file='/path/to/id_rsa'" 10.10.10.1 call get_environment

Error Traceback

(Paste the complete traceback of the exception between quotes below)

================= Traceback =================

Traceback (most recent call last):
  File "/home/USERNAME/.local/bin/napalm", line 8, in <module>
    sys.exit(main())
  File "/home/USERNAME/.local/lib/python3.10/site-packages/napalm/base/clitools/cl_napalm.py", line 308, in main
    run_tests(args)
  File "/home/USERNAME/.local/lib/python3.10/site-packages/napalm/base/clitools/cl_napalm.py", line 291, in run_tests
    call_getter(device, args.method, **method_kwargs)
  File "/home/USERNAME/.local/lib/python3.10/site-packages/napalm/base/clitools/cl_napalm.py", line 27, in wrapper
    r = func(*args, **kwargs)
  File "/home/USERNAME/.local/lib/python3.10/site-packages/napalm/base/clitools/cl_napalm.py", line 255, in call_getter
    r = func(**kwargs)
  File "/home/USERNAME/.local/lib/python3.10/site-packages/napalm/nxos_ssh/nxos_ssh.py", line 903, in get_environment
    module, sensor, is_critical, is_alert, temp, _ = line.split()
ValueError: too many values to unpack (expected 6)

raa-1 avatar Sep 25 '23 10:09 raa-1