Add a hide_attributes to well hide attributes

This commit is contained in:
Drakarah 2025-12-22 09:17:20 +00:00
parent f837614a69
commit 29d7a15dab
3 changed files with 41 additions and 11 deletions

View File

@ -402,6 +402,8 @@ disable=True
#hide=.*Hide_this_driver.* #hide=.*Hide_this_driver.*
# Define the list of sensors to show (comma-separated regexp) # Define the list of sensors to show (comma-separated regexp)
#show=.*Drive_Temperature.* #show=.*Drive_Temperature.*
# List of attributes to hide (comma separated)
#hide_attributes=Self-tests,Errors
[hddtemp] [hddtemp]
disable=False disable=False

View File

@ -398,6 +398,8 @@ disable=True
#hide=.*Hide_this_driver.* #hide=.*Hide_this_driver.*
# Define the list of sensors to show (comma-separated regexp) # Define the list of sensors to show (comma-separated regexp)
#show=.*Drive_Temperature.* #show=.*Drive_Temperature.*
# List of attributes to hide (comma separated)
#hide_attributes=Self-tests,Errors
[hddtemp] [hddtemp]
disable=False disable=False

View File

@ -105,7 +105,7 @@ def convert_nvme_attribute_to_dict(key,value):
'when_failed': None 'when_failed': None
} }
def get_smart_data(): def get_smart_data(hide_attributes):
""" """
Get SMART attribute data Get SMART attribute data
:return: list of multi leveled dictionaries :return: list of multi leveled dictionaries
@ -144,6 +144,8 @@ def get_smart_data():
for attribute in dev.attributes: for attribute in dev.attributes:
if attribute is None: if attribute is None:
pass pass
elif attribute.name in hide_attributes:
pass
else: else:
attrib_dict = convert_attribute_to_dict(attribute) attrib_dict = convert_attribute_to_dict(attribute)
@ -162,9 +164,13 @@ def get_smart_data():
idx = 0 idx = 0
for attr in dev.if_attributes.__dict__.keys(): for attr in dev.if_attributes.__dict__.keys():
idx +=1 idx +=1
attrib_dict = convert_nvme_attribute_to_dict(attr, dev.if_attributes.__dict__[attr]) attrib_dict = convert_nvme_attribute_to_dict(attr, dev.if_attributes.__dict__[attr])
if attrib_dict['name'] in hide_attributes:
pass
else:
try: try:
if dev.if_attributes.__dict__[attr] is not None: if dev.if_attributes.__dict__[attr] is not None: # make sure the value is serializable to prevent errors in rendering
serialized = str(dev.if_attributes.__dict__[attr]) serialized = str(dev.if_attributes.__dict__[attr])
except Exception as e: except Exception as e:
logger.debug(f'Unable to serialize attribute {attr} from NVME') logger.debug(f'Unable to serialize attribute {attr} from NVME')
@ -191,6 +197,26 @@ class SmartPlugin(GlancesPluginModel):
# We want to display the stat in the curse interface # We want to display the stat in the curse interface
self.display_curse = True self.display_curse = True
if 'hide_attributes' in config.as_dict()['smart']:
logger.info(
'Followings SMART attributes wil not be displayed: {}'.format(
config.as_dict()['smart']['hide_attributes']
)
)
self.hide_attributes = config.as_dict()['smart']['hide_attributes'].split(',')
else:
self.hide_attributes = []
@property
def hide_attributes(self):
"""Set hide_attributes list"""
return self._hide_attributes
@hide_attributes.setter
def hide_attributes(self, attr_list):
"""Set hide_attributes list"""
self._hide_attributes = [i for i in attr_list]
@GlancesPluginModel._check_decorator @GlancesPluginModel._check_decorator
@GlancesPluginModel._log_result_decorator @GlancesPluginModel._log_result_decorator
def update(self): def update(self):
@ -203,7 +229,7 @@ class SmartPlugin(GlancesPluginModel):
if self.input_method == 'local': if self.input_method == 'local':
# Update stats and hide some sensors(#2996) # Update stats and hide some sensors(#2996)
stats = [s for s in get_smart_data() if self.is_display(s[self.get_key()])] stats = [s for s in get_smart_data(self.hide_attributes) if self.is_display(s[self.get_key()])]
elif self.input_method == 'snmp': elif self.input_method == 'snmp':
pass pass