#!/usr/bin/env python3 # # ssdmon # # Command-line utility to check SSD health and parameters # try: import argparse import os import sys from sonic_py_common import device_info, logger except ImportError as e: raise ImportError("%s - required module not found" % str(e)) DEFAULT_DEVICE = "/dev/sda" SYSLOG_IDENTIFIER = "ssdmon" # Global logger instance log = logger.Logger(SYSLOG_IDENTIFIER) def import_ssd_api(diskdev): """ Loads platform specific or generic ssd_mon module from source Raises an ImportError exception if none of above available Returns: Instance of the class with SSD API implementation (vendor or generic) """ # try to load platform specific module try: platform_path, _ = device_info.get_paths_to_platform_and_hwsku_dirs() platform_plugins_path = os.path.join(platform_path, "plugins") sys.path.append(os.path.abspath(platform_plugins_path)) from ssd_util import SsdUtil except ImportError as e: log.log_warning("Platform specific SsdMon module not found.") return SsdUtil(diskdev) def is_number(s): try: float(s) return True except ValueError: return False # ==================== Entry point ==================== def ssdmon(): if os.geteuid() != 0: print("Root privileges are required for this operation") sys.exit(1) parser = argparse.ArgumentParser() parser.add_argument("-d", "--device", help="Device name to show health info", default=DEFAULT_DEVICE) parser.add_argument("-t", "--temperature", action="store_true", default=False, help="Show only temperature") parser.add_argument("-j", "--health", action="store_true", default=False, help="Show only health") args = parser.parse_args() ssd = import_ssd_api(args.device) if args.temperature: print(ssd.get_temperature()) return if args.health: print(ssd.get_health()) return print("Device Model : {}".format(ssd.get_model())) print("Firmware : {}".format(ssd.get_firmware())) print("Serial : {}".format(ssd.get_serial())) print("Health : {}{}".format(ssd.get_health(), "%" if is_number(ssd.get_health()) else "")) print("Remain Life : {}{}".format(ssd.get_remaining_life(), "%" if is_number(ssd.get_remaining_life()) else "")) print("Temperature : {}{}".format(ssd.get_temperature(), "C" if is_number(ssd.get_temperature()) else "")) print("SATA Rate : {}".format(ssd.get_sata_rate())) if __name__ == '__main__': ssdmon()