louwrentius / showtools

Shows detailed disk or network device information
BSD 3-Clause "New" or "Revised" License
122 stars 17 forks source link

Getting Error "TypeError: string indices must be integers, not 'str'" when running on RHEL 9.3 #23

Open thetreythomas opened 10 months ago

thetreythomas commented 10 months ago

Trying to run this on RHEL 9.3. When I run the command show disk -a, I get the below error:

(fioTools) [root@localhost VirtualEnvironments]# show disk -a
Traceback (most recent call last):
  File "/toshiba/VirtualEnvironments/fioTools/bin/show", line 33, in <module>
    sys.exit(load_entry_point('showtools==2.0.3', 'console_scripts', 'show')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/toshiba/VirtualEnvironments/fioTools/lib64/python3.11/site-packages/showtools/__init__.py", line 39, in main
    devicedata = process.process_devices(processed_args, devicetype, devices)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/toshiba/VirtualEnvironments/fioTools/lib64/python3.11/site-packages/showtools/showlib/processdevice.py", line 20, in process_devices
    devicedata.append(lookuptable[devicetype](device, args))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/toshiba/VirtualEnvironments/fioTools/lib64/python3.11/site-packages/showtools/showlib/disk.py", line 65, in get_disk_device_data
    lookup = disklookup.device_options_table(fullpath, hdparmdata, smartdata)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/toshiba/VirtualEnvironments/fioTools/lib64/python3.11/site-packages/showtools/showlib/disklookup.py", line 33, in device_options_table
    "model":{"value": diskattr.get_disk_model(smartdata),
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/toshiba/VirtualEnvironments/fioTools/lib64/python3.11/site-packages/showtools/showlib/diskattr.py", line 82, in get_disk_model
    model = smart.get_generic_parameter_from_smart(smartdata, "model")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/toshiba/VirtualEnvironments/fioTools/lib64/python3.11/site-packages/showtools/showlib/smart.py", line 55, in get_generic_parameter_from_smart
    returndata = returndata[x]
                 ~~~~~~~~~~^^^
TypeError: string indices must be integers, not 'str'

My setup is: OS: RHEL 9.3 Python: 3.11.5 showtools installed via pip

(fioTools) [root@localhost VirtualEnvironments]# pip freeze
markdown-it-py==3.0.0
mdurl==0.1.2
Pygments==2.17.2
rich==13.7.0
showtools==2.0.3

I made sure to have the OS package dependencies installed as well (hdparm, smartmontools, ethtool).

louwrentius commented 10 months ago

Thanks for your report. If possible can you share the smartctl in json output for your device?

j-bahr commented 7 months ago

I'm seeing the same error, I have an nvme drive and many ATA drives, sharing output of both.

$ sudo ~/.local/bin/show disk -a
Traceback (most recent call last):
  File "/home/jbahr/.local/bin/show", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/jbahr/.local/pipx/venvs/showtools/lib/python3.11/site-packages/showtools/__init__.py", line 39, in main
    devicedata = process.process_devices(processed_args, devicetype, devices)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jbahr/.local/pipx/venvs/showtools/lib/python3.11/site-packages/showtools/showlib/processdevice.py", line 20, in process_devices
    devicedata.append(lookuptable[devicetype](device, args))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jbahr/.local/pipx/venvs/showtools/lib/python3.11/site-packages/showtools/showlib/disk.py", line 65, in get_disk_device_data
    lookup = disklookup.device_options_table(fullpath, hdparmdata, smartdata)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jbahr/.local/pipx/venvs/showtools/lib/python3.11/site-packages/showtools/showlib/disklookup.py", line 33, in device_options_table
    "model":{"value": diskattr.get_disk_model(smartdata),
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jbahr/.local/pipx/venvs/showtools/lib/python3.11/site-packages/showtools/showlib/diskattr.py", line 82, in get_disk_model
    model = smart.get_generic_parameter_from_smart(smartdata, "model")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jbahr/.local/pipx/venvs/showtools/lib/python3.11/site-packages/showtools/showlib/smart.py", line 55, in get_generic_parameter_from_smart
    returndata = returndata[x]
                 ~~~~~~~~~~^^^
TypeError: string indices must be integers, not 'str'

NVME

{
  "json_format_version": [
    1,
    0
  ],
  "smartctl": {
    "version": [
      7,
      3
    ],
    "svn_revision": "5338",
    "platform_info": "x86_64-linux-6.5.0-26-generic",
    "build_info": "(local build)",
    "argv": [
      "smartctl",
      "-j",
      "-a",
      "/dev/nvme0n1"
    ],
    "exit_status": 0
  },
  "local_time": {
    "time_t": 1712095120,
    "asctime": "Tue Apr  2 21:58:40 2024 UTC"
  },
  "device": {
    "name": "/dev/nvme0n1",
    "info_name": "/dev/nvme0n1",
    "type": "nvme",
    "protocol": "NVMe"
  },
  "model_name": "Samsung SSD 980 PRO with Heatsink 1TB",
  "serial_number": "XXXXXXXXXX",
  "firmware_version": "XXXXXXX",
  "nvme_pci_vendor": {
    "id": 5197,
    "subsystem_id": 5197
  },
  "nvme_ieee_oui_identifier": 9528,
  "nvme_total_capacity": 1000204886016,
  "nvme_unallocated_capacity": 0,
  "nvme_controller_id": 6,
  "nvme_version": {
    "string": "1.3",
    "value": 66304
  },
  "nvme_number_of_namespaces": 1,
  "nvme_namespaces": [
    {
      "id": 1,
      "size": {
        "blocks": 1953525168,
        "bytes": 1000204886016
      },
      "capacity": {
        "blocks": 1953525168,
        "bytes": 1000204886016
      },
      "utilization": {
        "blocks": 263085536,
        "bytes": 134699794432
      },
      "formatted_lba_size": 512,
      "eui64": {
        "oui": 9528,
        "ext_id": 778215358676
      }
    }
  ],
  "user_capacity": {
     "blocks": 1953525168,
    "bytes": 1000204886016
  },
  "logical_block_size": 512,
  "smart_support": {
    "available": true,
    "enabled": true
  },
  "smart_status": {
    "passed": true,
    "nvme": {
      "value": 0
    }
  },
  "nvme_smart_health_information_log": {
    "critical_warning": 0,
    "temperature": 41,
    "available_spare": 100,
    "available_spare_threshold": 10,
    "percentage_used": 1,
    "data_units_read": 757904,
    "data_units_written": 5171792,
    "host_reads": 26649120,
    "host_writes": 317924056,
    "controller_busy_time": 3676,
    "power_cycles": 8,
    "power_on_hours": 584,
    "unsafe_shutdowns": 3,
    "media_errors": 0,
    "num_err_log_entries": 0,
    "warning_temp_time": 0,
    "critical_comp_time": 0,
    "temperature_sensors": [
      41,
      42
    ]
  },
  "temperature": {
    "current": 41
  },
  "power_cycle_count": 8,
  "power_on_time": {
    "hours": 584
  }
}

ATA output


{
  "json_format_version": [
    1,
    0
  ],
  "smartctl": {
    "version": [
      7,
      3
    ],
    "svn_revision": "5338",
    "platform_info": "x86_64-linux-6.5.0-26-generic",
    "build_info": "(local build)",
    "argv": [
      "smartctl",
      "-j",
      "-a",
      "/dev/sdb"
    ],
    "drive_database_version": {
      "string": "7.3/5319"
    },
    "exit_status": 0
  },
  "local_time": {
    "time_t": 1712095281,
    "asctime": "Tue Apr  2 22:01:21 2024 UTC"
  },
  "device": {
    "name": "/dev/sdb",
    "info_name": "/dev/sdb [SAT]",
    "type": "sat",
    "protocol": "ATA"
  },
  "model_family": "Western Digital Red",
  "model_name": "WDC WD80EFAX-68LHPN0",
  "serial_number": "XXXXXXXX",
  "wwn": {
    "naa": 5,
    "oui": 3274,
    "id": 9978613623
  },
  "firmware_version": "83.H0A83",
  "user_capacity": {
    "blocks": 15628053168,
    "bytes": 8001563222016
  },
  "logical_block_size": 512,
  "physical_block_size": 4096,
  "rotation_rate": 5400,
  "form_factor": {
    "ata_value": 2,
    "name": "3.5 inches"
  },
  "trim": {
    "supported": false
  },
  "in_smartctl_database": true,
  "ata_version": {
    "string": "ACS-2, ATA8-ACS T13/1699-D revision 4",
    "major_value": 1020,
    "minor_value": 41
  },
  "sata_version": {
    "string": "SATA 3.2",
    "value": 255
  },
  "interface_speed": {
    "max": {
      "sata_value": 14,
      "string": "6.0 Gb/s",
      "units_per_second": 60,
      "bits_per_unit": 100000000
    },
    "current": {
      "sata_value": 3,
      "string": "6.0 Gb/s",
      "units_per_second": 60,
      "bits_per_unit": 100000000
    }
  },
  "smart_support": {
    "available": true,
    "enabled": true
  },
  "smart_status": {
    "passed": true
  },
  "ata_smart_data": {
    "offline_data_collection": {
      "status": {
        "value": 128,
        "string": "was never started"
      },
      "completion_seconds": 93
    },
    "self_test": {
      "status": {
        "value": 0,
        "string": "completed without error",
        "passed": true
      },
      "polling_minutes": {
        "short": 2,
        "extended": 1093
      }
    },
    "capabilities": {
      "values": [
        91,
        3
      ],
      "exec_offline_immediate_supported": true,
      "offline_is_aborted_upon_new_cmd": false,
      "offline_surface_scan_supported": true,
      "self_tests_supported": true,
      "conveyance_self_test_supported": false,
      "selective_self_test_supported": true,
      "attribute_autosave_enabled": true,
      "error_logging_supported": true,
      "gp_logging_supported": true
    }
  },
  "ata_sct_capabilities": {
    "value": 61,
    "error_recovery_control_supported": true,
    "feature_control_supported": true,
    "data_table_supported": true
  },
  "ata_smart_attributes": {
    "revision": 16,
    "table": [
      {
        "id": 1,
        "name": "Raw_Read_Error_Rate",
        "value": 100,
        "worst": 100,
        "thresh": 16,
        "when_failed": "",
         "when_failed": "",
        "flags": {
          "value": 11,
          "string": "PO-R-- ",
          "prefailure": true,
          "updated_online": true,
          "performance": false,
          "error_rate": true,
          "event_count": false,
          "auto_keep": false
        },
        "raw": {
          "value": 0,
          "string": "0"
        }
      },
      {
        "id": 2,
        "name": "Throughput_Performance",
        "value": 129,
        "worst": 129,
        "thresh": 54,
        "when_failed": "",
        "flags": {
          "value": 4,
          "string": "--S--- ",
          "prefailure": false,
          "updated_online": false,
          "performance": true,
          "error_rate": false,
          "event_count": false,
          "auto_keep": false
        },
        "raw": {
          "value": 112,
          "string": "112"
        }
      },
      {
        "id": 3,
        "name": "Spin_Up_Time",
        "value": 188,
        "worst": 188,
        "thresh": 24,
        "when_failed": "",
        "flags": {
          "value": 7,
          "string": "POS--- ",
          "prefailure": true,
          "updated_online": true,
          "performance": true,
          "error_rate": false,
          "event_count": false,
          "auto_keep": false
        },
        "raw": {
          "value": 38673383840,
          "string": "416 (Average 285)"
        }
      },
      {
        "id": 4,
        "name": "Start_Stop_Count",
        "value": 100,
        "worst": 100,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 18,
          "string": "-O--C- ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": true,
          "auto_keep": false
        },
        "raw": {
          "value": 53,
          "string": "53"
        }
      },
      {
        "id": 5,
        "name": "Reallocated_Sector_Ct",
        "value": 100,
        "worst": 100,
        "thresh": 5,
        "when_failed": "",
        "flags": {
          "value": 51,
          "string": "PO--CK ",
          "prefailure": true,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": true,
          "auto_keep": true
        },
        "raw": {
          "value": 0,
          "string": "0"
        }
      },
      {
        "id": 7,
        "name": "Seek_Error_Rate",
        "value": 100,
        "worst": 100,
        "thresh": 67,
        "when_failed": "",
        "flags": {
          "value": 10,
          "string": "-O-R-- ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": true,
          "event_count": false,
          "auto_keep": false
        },
        "raw": {
          "value": 0,
          "string": "0"
        }
      },
      {
        "id": 8,
        "name": "Seek_Time_Performance",
        "value": 128,
        "worst": 128,
        "thresh": 20,
        "when_failed": "",
        "flags": {
          "value": 4,
          "string": "--S--- ",
          "prefailure": false,
          "updated_online": false,
          "performance": true,
           "error_rate": false,
          "event_count": false,
          "auto_keep": false
        },
        "raw": {
          "value": 18,
          "string": "18"
        }
      },
      {
        "id": 9,
        "name": "Power_On_Hours",
        "value": 92,
        "worst": 92,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 18,
          "string": "-O--C- ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": true,
          "auto_keep": false
        },
        "raw": {
          "value": 57860,
          "string": "57860"
        }
      },
      {
        "id": 10,
        "name": "Spin_Retry_Count",
        "value": 100,
        "worst": 100,
        "thresh": 60,
        "when_failed": "",
        "flags": {
          "value": 18,
          "string": "-O--C- ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": true,
          "auto_keep": false
        },
        "raw": {
          "value": 0,
          "string": "0"
        }
      },
      {
        "id": 12,
        "name": "Power_Cycle_Count",
        "value": 100,
        "worst": 100,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 50,
          "string": "-O--CK ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": true,
          "auto_keep": true
          },
        "raw": {
          "value": 53,
          "string": "53"
        }
      },
      {
        "id": 22,
        "name": "Helium_Level",
        "value": 100,
        "worst": 100,
        "thresh": 25,
        "when_failed": "",
        "flags": {
          "value": 35,
          "string": "PO---K ",
          "prefailure": true,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": false,
          "auto_keep": true
        },
        "raw": {
          "value": 100,
          "string": "100"
        }
      },
      {
        "id": 192,
        "name": "Power-Off_Retract_Count",
        "value": 92,
        "worst": 92,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 50,
          "string": "-O--CK ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": true,
          "auto_keep": true
        },
        "raw": {
          "value": 10564,
          "string": "10564"
        }
      },
      {
        "id": 193,
        "name": "Load_Cycle_Count",
        "value": 92,
        "worst": 92,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 18,
          "string": "-O--C- ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": true,
          "auto_keep": false
        },
        "raw": {
          "value": 10564,
          "string": "10564"
        }
      },
      {
        "id": 194,
        "name": "Temperature_Celsius",
        "value": 162,
        "worst": 162,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 2,
          "string": "-O---- ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": false,
          "auto_keep": false
        },
        "raw": {
          "value": 223339282472,
          "string": "40 (Min/Max 15/52)"
        }
      },
      {
        "id": 196,
        "name": "Reallocated_Event_Count",
        "value": 100,
        "worst": 100,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 50,
          "string": "-O--CK ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": true,
          "auto_keep": true
        },
        "raw": {
          "value": 0,
          "string": "0"
        }
      },
      {
        "id": 197,
        "name": "Current_Pending_Sector",
        "value": 100,
        "worst": 100,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 34,
          "string": "-O---K ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": false,
          "event_count": false,
          "auto_keep": true
        },
        "raw": {
          "value": 0,
          "string": "0"
        }
      },
      {
          "id": 198,
        "name": "Offline_Uncorrectable",
        "value": 100,
        "worst": 100,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 8,
          "string": "---R-- ",
          "prefailure": false,
          "updated_online": false,
          "performance": false,
          "error_rate": true,
          "event_count": false,
          "auto_keep": false
        },
        "raw": {
          "value": 0,
          "string": "0"
        }
      },
      {
        "id": 199,
        "name": "UDMA_CRC_Error_Count",
        "value": 200,
        "worst": 200,
        "thresh": 0,
        "when_failed": "",
        "flags": {
          "value": 10,
          "string": "-O-R-- ",
          "prefailure": false,
          "updated_online": true,
          "performance": false,
          "error_rate": true,
          "event_count": false,
          "auto_keep": false
        },
        "raw": {
          "value": 0,
          "string": "0"
        }
      }
    ]
  },
  "power_on_time": {
    "hours": 57860
  },
  "power_cycle_count": 53,
  "temperature": {
    "current": 40
  },
  "ata_smart_error_log": {
    "summary": {
      "revision": 1,
      "count": 0
    }
  },
  "ata_smart_self_test_log": {
    "standard": {
      "revision": 1,
      "count": 0
    }
  },
  "ata_smart_selective_self_test_log": {
    "revision": 1,
    "table": [
      {
        "lba_min": 0,
        "lba_max": 0,
        "status": {
          "value": 0,
          "string": "Not_testing"
        }
      },
      {
        "lba_min": 0,
        "lba_max": 0,
        "status": {
          "value": 0,
          "string": "Not_testing"
        }
      },
      {
        "lba_min": 0,
        "lba_max": 0,
        "status": {
          "value": 0,
          "string": "Not_testing"
        }
      },
      {
        "lba_min": 0,
        "lba_max": 0,
        "status": {
          "value": 0,
          "string": "Not_testing"
        }
      },
      {
        "lba_min": 0,
        "lba_max": 0,
        "status": {
          "value": 0,
          "string": "Not_testing"
        }
      }
    ],
    "flags": {
      "value": 0,
      "remainder_scan_enabled": false
    },
    "power_up_scan_resume_minutes": 0
  }
}
louwrentius commented 7 months ago

Thanks! I'll look at this, but can't promise timelines 🤷‍♀️