IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

S.M.A.R.T PredictFailure (WMI) retourne toujours false


Sujet :

C#

  1. #1
    Membre averti
    Homme Profil pro
    Etudiant
    Inscrit en
    Avril 2014
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Etudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 12
    Par défaut S.M.A.R.T PredictFailure (WMI) retourne toujours false
    Salut !

    J'essaie actuellement de récupérer les erreurs S.M.A.R.T. sur mes disques locaux, pour le moment coté valeurs/worst/threshold j'ai tout de bon, en revanche je galère un petit peu pour déterminer si un disque doit être considéré sur sa deadline ou non.

    J'utilise WMI notamment la classe MSStorageDriver_FailurePredictStatus (http://www.scriptinternals.com/new/u...dictStatus.htm) qui possède une propriété PredictFailure sauf ça me renvoie toujours false même sur un disque sur sa fin.

    De même, pour chaque ID des erreurs S.M.A.R.T, je ne vois pas comment déterminer si cette caractéristique est mauvaise comme le nombre de secteurs ré-alloués etc ...
    Du coup j'ai un peu fouillé sur le net et j'ai trouvé ceci comme morceau de code (C#) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     // get wmi access to hdd 
               var searcher = new ManagementObjectSearcher("Select * from Win32_DiskDrive");
               searcher.Scope = new ManagementScope(@"\root\wmi");      
     
               // check if SMART reports the drive is failing
               searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictStatus");          
               iDriveIndex = 0;
               foreach (ManagementObject drive in searcher.Get())
               {
                 dicDrives[iDriveIndex].IsOK = (bool)drive.Properties["PredictFailure"].Value == false; // Toujours false qui est renvoyé
                 iDriveIndex++;
               }
    Après il y a un moyen de savoir si un attribut est critique via ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
     // retrive attribute flags, value worste and vendor data information
              searcher.Query = new ObjectQuery("Select * from MSStorageDriver_FailurePredictData");
              iDriveIndex = 0;  
              foreach (ManagementObject data in searcher.Get())
              {              
                  Byte[] bytes = (Byte[])data.Properties["VendorSpecific"].Value;
                  for (int i = 0; i < 30; ++i)
                  {
                    try
                    {                  
                      int id = bytes[i*12 + 2];
     
                      int flags = bytes[i * 12 + 4]; // least significant status byte, +3 most significant byte, but not used so ignored.
                      //bool advisory = (flags & 0x1) == 0x0;
                      bool failureImminent = (flags & 0x1) == 0x1; // Ici
                      //bool onlineDataCollection = (flags & 0x2) == 0x2;
     
                      int value = bytes[i*12 + 5];
                      int worst = bytes[i*12 + 6];
                      int vendordata = BitConverter.ToInt32(bytes, i*12 + 7);
                      if (id == 0) continue;
     
                      var attr = dicDrives[iDriveIndex].Attributes[id];
                      attr.Current = value;
                      attr.Worst = worst;
                      attr.Data = vendordata;
                      attr.IsOK = failureImminent == false;
                    }
                    catch
                    {
                      // given key does not exist in attribute collection (attribute not in the dictionary of attributes)
                    }                
                  }
                  iDriveIndex++;
              }
    Globalement je comprends le code sans trop de problèmes, je pense que mon manque de connaissances vient du coté de WMI, j'ai essayé sur un disque sain et un autre avec des erreurs mais dans ce dernier cas il ne me prévient pas du tout.

    Une idée de comment je pourrai interpréter ça et/ou le mettre en place ? Merci.

  2. #2
    Membre Expert
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Billets dans le blog
    7
    Par défaut
    Bonsoir,

    Désolé pour le déterrage du topic mais étant un habitué de cette communauté je voulais voir (comme à mon habitude) si une bribe de mon projet pouvait servir à qqun.
    Breff....

    Il n'est ici nulle question d'être ou ne pas être familiarisé avec WMI, tout est question de compréhension en s'appuyant sur les données de retour ! Perso je me suis inspiré de ceci pour mettre en forme ma classe SMART :
    http://www.i-programmer.info/project...s.html?start=2

    Donc étant donné que je travail sur un projet lié à l'optimisation HDD/SSD voici ce qu j'ai pondu en 2 temps 3 mouvements :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Management;
     
    namespace Smart
    {
        public class Infos
        {
     
            public byte[] VendorSpecByte { get; set; }
            public string InstanceN { get; set; }
            public List<PropertyContent> Datas { get; set; }
     
            public Infos()
            {
                Datas = new List<PropertyContent>();
                LoadInfos();
            }
     
            private void LoadInfos()
            {
                using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT VendorSpecific, InstanceName FROM MSStorageDriver_FailurePredictData"))
                {
                    foreach (ManagementObject data in searcher.Get())
                    {
                        try
                        {
                            this.VendorSpecByte = (byte[])data.GetPropertyValue("VendorSpecific");
                            this.InstanceN = (string)data.GetPropertyValue("InstanceName");
                            for (int i = 0; i <= 29; i++)
                            {
                                int id = VendorSpecByte[i * 12 + 2];
                                int flags = VendorSpecByte[i * 12 + 4];
                                bool failureImminent = (flags & 0x1) == 0x1;
                                UInt32 vendordata = BitConverter.ToUInt32(VendorSpecByte, i * 12 + 7);
                                if (!(id == 0))
                                {
                                    PropertyContent pInfos = new PropertyContent();
                                    pInfos.Id = id;
                                    pInfos.Value = Convert.ToString(vendordata);
                                    pInfos.IsOk = (failureImminent == false);
                                    this.Datas.Add(pInfos);
                                }
                            }
                        }
                        catch (ManagementException ex)
                        {
                            throw new ManagementException("Erreur WMI", ex);
                        }
                    }
                }
            }
     
            public string FormatToString()
            {
                string str = String.Empty;
                foreach (PropertyContent d in Datas)
                {
                    str += ("ID:"
                                 + (d.Id + ("\r\n" + ("PropertyName:"
                                 + (d.PropertyName + ("\r\n" + ("PropertyValue:"
                                 + (d.Value + ("\r\n" + ("PropertyState:"
                                 + (Convert.ToString(d.IsOk) + "\r\n")))))))))));
                }
     
                return str;
            }
     
        }
     
        public class PropertyContent
        {
     
            private int m_Id;
            public int Id
            {
                get { return m_Id; }
                set
                {
                    m_Id = value;
                    switch (m_Id)
                    {
                        case 1:
                            m_PropertyName = PropertyNames.RawReadErrorRate;
                            break;
                        case 2:
                            m_PropertyName = PropertyNames.ThroughputPerformance;
                            break;
                        case 3:
                            m_PropertyName = PropertyNames.SpinUpTime;
                            break;
                        case 4:
                            m_PropertyName = PropertyNames.StartStopCount;
                            break;
                        case 5:
                            m_PropertyName = PropertyNames.ReallocatedSectorCount;
                            break;
                        case 6:
                            m_PropertyName = PropertyNames.ReadChannelMargin;
                            break;
                        case 7:
                            m_PropertyName = PropertyNames.SeekErrorRate;
                            break;
                        case 8:
                            m_PropertyName = PropertyNames.SeekTimePerformance;
                            break;
                        case 9:
                            m_PropertyName = PropertyNames.PowerOnHours;
                            break;
                        case 10:
                            m_PropertyName = PropertyNames.SpinRetryCount;
                            break;
                        case 11:
                            m_PropertyName = PropertyNames.CalibrationRetryCount;
                            break;
                        case 12:
                            m_PropertyName = PropertyNames.PowerCycleCount;
                            break;
                        case 171:
                            m_PropertyName = PropertyNames.ProgramFailBlockCount;
                            break;
                        case 172:
                            m_PropertyName = PropertyNames.EraseFailBlockCount;
                            break;
                        case 173:
                            m_PropertyName = PropertyNames.UnknownAttribute;
                            break;
                        case 174:
                            m_PropertyName = PropertyNames.UnexpectedPowerLossCount;
                            break;
                        case 187:
                            m_PropertyName = PropertyNames.ReportedUncorrectableErrors;
                            break;
                        case 192:
                            m_PropertyName = PropertyNames.PoweroffRetractCount;
                            break;
                        case 193:
                            m_PropertyName = PropertyNames.LoadCycleCount;
                            break;
                        case 194:
                            m_PropertyName = PropertyNames.Temperature;
                            break;
                        case 196:
                            m_PropertyName = PropertyNames.ReallocationEventCount;
                            break;
                        case 197:
                            m_PropertyName = PropertyNames.CurrentPendingSectorCount;
                            break;
                        case 198:
                            m_PropertyName = PropertyNames.OfflineScanUncorrectableSectorCount;
                            break;
                        case 199:
                            m_PropertyName = PropertyNames.UltraDMACRCErrorCount;
                            break;
                        case 201:
                            m_PropertyName = PropertyNames.SoftReadErrorRate;
                            break;
                        case 220:
                            m_PropertyName = PropertyNames.DiskShift;
                            break;
                        case 230:
                            m_PropertyName = PropertyNames.LifeCurveStatus;
                            break;
                        case 232:
                            m_PropertyName = PropertyNames.AvailableReservedSpace;
                            break;
                        case 234:
                            m_PropertyName = PropertyNames.Reserved;
                            break;
                        case 241:
                            m_PropertyName = PropertyNames.LifetimeWritesFromHost;
                            break;
                        case 242:
                            m_PropertyName = PropertyNames.LifetimeReadsFromHost;
                            break;
                    }
                }
            }
     
            private string m_PropertyName;
            public string PropertyName
            {
                get { return m_PropertyName; }
            }
     
            public string Value { get; set; }
            public bool IsOk { get; set; }
     
            private struct PropertyNames
            {
                public const string RawReadErrorRate = "Raw Read Error Rate";
                public const string ThroughputPerformance = "Throughput Performance";
                public const string SpinUpTime = "Spin Up Time";
                public const string StartStopCount = "Start/Stop Count";
                public const string ReallocatedSectorCount = "Reallocated Sector Count";
                public const string ReadChannelMargin = "Read Channel Margin";
                public const string SeekErrorRate = "Seek Error Rate";
                public const string SeekTimePerformance = "Seek Time Performance";
                public const string PowerOnHours = "Power-On Hours";
                public const string SpinRetryCount = "Spin Retry Count";
                public const string CalibrationRetryCount = "Calibration Retry Count";
                public const string PowerCycleCount = "Power Cycle Count";
                public const string ProgramFailBlockCount = "Program Fail Block Count";
                public const string EraseFailBlockCount = "Erase Fail Block Count";
                public const string UnknownAttribute = "Unknown Attribute";
                public const string UnexpectedPowerLossCount = "Unexpected Power Loss Count";
                public const string ReportedUncorrectableErrors = "Reported Uncorrectable Errors";
                public const string PoweroffRetractCount = "Power-off Retract Count";
                public const string LoadCycleCount = "Load Cycle Count";
                public const string Temperature = "Temperature";
                public const string ReallocationEventCount = "Reallocation Event Count";
                public const string CurrentPendingSectorCount = "Current Pending Sector Count";
                public const string OfflineScanUncorrectableSectorCount = "Off-line Scan Uncorrectable Sector Count";
                public const string UltraDMACRCErrorCount = "Ultra DMA CRC Error Count";
                public const string SoftReadErrorRate = "Soft Read Error Rate";
                public const string DiskShift = "Disk Shift";
                public const string LifeCurveStatus = "Life Curve Status";
                public const string AvailableReservedSpace = "Available Reserved Space";
                public const string Reserved = "Reserved";
                public const string LifetimeWritesFromHost = "Lifetime Writes From Host";
                public const string LifetimeReadsFromHost = "Lifetime Reads From Host";
            }
        }
    }
    J'ai ajouté une méthode ToString pour afficher directement les informations lors de mon debug :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    SmartInfos infos = new Smart.Infos();
    MessageBox.Show(Convert.ToString(infos));
    PS1 : Il y a possibilité de savoir approximativement la durée de vie d'un disque selon les données constructeur, voici un billet super bien détaillé :
    http://www.hdsentinel.com/smart/index.php

    PS2 : On pourrait tout aussi bien agrémenter cette classe "Infos" en ajoutant une méthode Dispose ...etc......

    A+

Discussions similaires

  1. IsAjaxRequest Retourne toujours false
    Par Akawan dans le forum ASP.NET MVC
    Réponses: 2
    Dernier message: 17/09/2010, 16h50
  2. Réponses: 12
    Dernier message: 05/12/2009, 15h16
  3. checkdnsrr retourne toujours false
    Par razbitume dans le forum Langage
    Réponses: 6
    Dernier message: 27/07/2009, 21h21
  4. ma nouvelle class retourne toujours false
    Par gtraxx dans le forum jQuery
    Réponses: 2
    Dernier message: 30/12/2008, 08h57
  5. [XSLT]fonction contains retourne toujours false
    Par wildmary dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 01/08/2007, 11h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo