HEX
Server: LiteSpeed
System: Linux baran.dnsprotection.me 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: ddir12 (3618)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //usr/lib/python3.6/site-packages/glances/plugins/__pycache__/glances_smart.cpython-36.opt-1.pyc
3

Eo�c�@s�dZddlmZddlmZddlmZddlmZyddl	m
Z
Wn6ek
rzZzda
ejdje��WYd	d	Z[XnXd
a
dd�Zd
d�ZGdd�de�Zd	S)a�
Hard disk SMART attributes plugin.
Depends on pySMART and smartmontools
Must execute as root
"usermod -a -G disk USERNAME" is not sufficient unfortunately
SmartCTL (/usr/sbin/smartctl) must be in system path for python2.

Regular PySMART is a python2 library.
We are using the pySMART.smartx updated library to support both python 2 and 3.

If we only have disk group access (no root):
$ smartctl -i /dev/sda
smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.15.0-30-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org


Probable ATA device behind a SAT layer
Try an additional '-d ata' or '-d sat' argument.

This is not very hopeful: https://medium.com/opsops/why-smartctl-could-not-be-run-without-root-7ea0583b1323

So, here is what we are going to do:
Check for admin access.  If no admin access, disable SMART plugin.

If smartmontools is not installed, we should catch the error upstream in plugin initialization.
�)�
GlancesPlugin)�logger)�disable)�is_admin)�
DeviceListTz5Missing Python Lib ({}), HDD Smart plugin is disabledNFcCs.|j|j|j|j|j|j|j|j|j|j	d�
S)N)
�name�num�flags�raw�value�worstZ	threshold�type�updated�when_failed)
rrr	r
rrZthreshr
rr)�attr�r�#/usr/lib/python3.6/glances_smart.py�convert_attribute_to_dict4src!Cs�g}y
t�}Wn4tk
rB}ztjdj|��da|Sd}~XnXx�|jD]�}|jddj|j|j	�i�xt|j
D]j}|dkr�qrt|�}|jdd�}yWn6t
k
r�}ztjdj||��wrWYdd}~XnX||d	|<qrWqLW|S)
aT
    Get SMART attribute data
    :return: list of multi leveled dictionaries
             each dict has a key "DeviceName" with the identification of the device in smartctl
             also has keys of the SMART attribute id, with value of another dict of the attributes
             [
                {
                    "DeviceName": "/dev/sda blahblah",
                    "1":
                    {
                        "flags": "..",
                        "raw": "..",
                        etc,
                    }
                    ...
                }
             ]
    z2Smart plugin error - Can not grab device list ({})TN�
DeviceNamez{} {}rz/Smart plugin error - Skip the attribute {} ({})����)r�	TypeErrorr�debug�format�import_error_tagZdevices�appendrZmodelZ
attributesr�pop�	Exception)�statsZdevlist�eZdevZ	attributeZattrib_dictrrrr�get_smart_dataCs,
r csNeZdZdZddgf�fdd�	Zejejdd���Zdd�Z	dd	d
�Z
�ZS)�Pluginz=Glances' HDD SMART plugin.

    stats is a list of dicts
    Ncs8t�st|d�tjd�tt|�j||d�d|_dS)zInit the plugin.Zsmartz5Current user is not admin, HDD SMART plugin disabled.)�args�configTN)rrrr�superr!�__init__Z
display_curse)�selfr"r#Zstats_init_value)�	__class__rrr%�s


zPlugin.__init__cCs:|j�}tr|jS|jdkr$t�}n
|jdkr.||_|jS)z*Update SMART stats using the input method.ZlocalZsnmp)Zget_init_valuerrZinput_methodr )r&rrrr�update�s

z
Plugin.updatecCsdS)zReturn the key of the list.rr)r&rrr�get_key�szPlugin.get_keycCs"g}ts|js|j�r|S|d}djd|d�}|j|j|d��x�|jD]�}|j|j��dj|dd|�|d�}|j|j|��x�tdd	�|j�D�t	d
�D]r}|j|j��dj||dd|d
�j
dd�|d
d�}|j|j|��dj||d�}|j|j|��q�WqLW|S)z2Return the dict to display in the curse interface.�z
{:{width}}zSMART disks)�widthZTITLErNcSsg|]}|dkr|�qS)rr)�.0�irrr�
<listcomp>�sz$Plugin.msg_curse.<locals>.<listcomp>)�keyz {:{width}}rr�_� z{:>8}r
)rrZis_disabledrrZcurse_add_lineZcurse_new_line�sorted�keys�int�replace)r&r"Z	max_width�retZname_max_width�msgZdevice_statZ
smart_statrrr�	msg_curse�s$ *zPlugin.msg_curse)NN)�__name__�
__module__�__qualname__�__doc__r%rZ_check_decoratorZ_log_result_decoratorr(r)r8�
__classcell__rr)r'rr!zsr!)r<Zglances.plugins.glances_pluginrZglances.loggerrZglances.mainrZglances.compatrZpySMARTr�ImportErrorrrZwarningrrr r!rrrr�<module>#s"7