List <VulpesSMARTInfo> LoadData(string MachineID, SQLLib sql) { List <VulpesSMARTInfo> lst = new List <VulpesSMARTInfo>(); SqlDataReader dr = sql.ExecSQLReader("Select * from SMARTData WHERE MachineID=@id", new SQLParam("@id", MachineID)); while (dr.Read()) { VulpesSMARTInfo s = new VulpesSMARTInfo(); sql.LoadIntoClass(dr, s); lst.Add(s); } dr.Close(); foreach (VulpesSMARTInfo sm in lst) { sm.Attributes = new Dictionary <int, VulpesSMARTAttribute>(); dr = sql.ExecSQLReader("Select * from SMARTDataAttributes WHERE MachineID=@id AND PnPDeviceID=@pnp", new SQLParam("@id", MachineID), new SQLParam("@pnp", sm.PNPDeviceID)); while (dr.Read()) { VulpesSMARTAttribute attr = new VulpesSMARTAttribute(); sql.LoadIntoClass(dr, attr); sm.Attributes.Add(attr.ID, attr); } dr.Close(); } return(lst); }
void ReportThings(SQLLib sql, string MachineID, string Method, VulpesSMARTInfo ar, ref Dictionary <string, Int64> AlreadyReported, ReportingPolicyElement RepElementRoot, List <int> UpdatedAttribs = null) { bool Critical = Method.ToLower() == "error" ? true : false; string ID = (Method.ToLower() == "error" ? "ERROR\\\\" : "") + MachineID + "\\\\" + ar.PNPDeviceID; bool ReportToAdmin = RepElementRoot.ReportToAdmin.Value; bool ReportToClient = RepElementRoot.ReportToClient.Value; bool UrgentForAdmin = RepElementRoot.UrgentForAdmin.Value; bool UrgentForClient = RepElementRoot.UrgentForClient.Value; if (AlreadyReported.ContainsKey(ID) == true) { if ((AlreadyReported[ID] & (Int64)ReportingFlags.ReportToAdmin) != 0) { ReportToAdmin = false; } if ((AlreadyReported[ID] & (Int64)ReportingFlags.ReportToClient) != 0) { ReportToClient = false; } if ((AlreadyReported[ID] & (Int64)ReportingFlags.UrgentForAdmin) != 0) { UrgentForAdmin = false; } if ((AlreadyReported[ID] & (Int64)ReportingFlags.UrgentForClient) != 0) { UrgentForClient = false; } } if (ReportToAdmin == false && ReportToClient == false && UrgentForAdmin == false && UrgentForClient == false) { return; } ReportingFlags Flags = (ReportToAdmin == true ? ReportingFlags.ReportToAdmin : 0) | (ReportToClient == true ? ReportingFlags.ReportToClient : 0) | (UrgentForAdmin == true ? ReportingFlags.UrgentForAdmin : 0) | (UrgentForClient == true ? ReportingFlags.UrgentForClient : 0); ReportingSMART sm = new ReportingSMART(); sm.App = ar; sm.UpdatedAttribs = UpdatedAttribs; ReportingProcessor.ReportSMART(sql, MachineID, Method, sm, Flags, Critical); if (AlreadyReported.ContainsKey(ID) == true) { AlreadyReported[ID] |= (Int64)Flags; } else { AlreadyReported.Add(ID, (Int64)Flags); } }
private void lstDisks_SelectedIndexChanged(object sender, EventArgs e) { lstSmartAttr.Items.Clear(); if (lstDisks.SelectedItems.Count == 0) { return; } VulpesSMARTInfo i = (VulpesSMARTInfo)lstDisks.SelectedItems[0].Tag; if (i.Attributes == null) { return; } foreach (KeyValuePair <int, VulpesSMARTAttribute> kvp in i.Attributes) { ListViewItem l = new ListViewItem("0x" + kvp.Key.ToString("X")); l.Tag = kvp.Value; string Name = "???"; string AttribIdeal = ""; if (SMARTDescription.Descriptions.ContainsKey(kvp.Key) == true) { Name = SMARTDescription.Descriptions[kvp.Key].Description; switch (SMARTDescription.Descriptions[kvp.Key].Ideal) { case SMARTDescriptionEnum.Critical: AttribIdeal = "‼"; break; case SMARTDescriptionEnum.LowIdeal: AttribIdeal = "↓"; break; case SMARTDescriptionEnum.HighIdeal: AttribIdeal = "↑"; break; } } l.SubItems.Add(Name); l.SubItems.Add(AttribIdeal); l.SubItems.Add(kvp.Value.FailureImminent == true ? "!true!" : "false"); l.SubItems.Add(kvp.Value.Value.ToString()); l.SubItems.Add(kvp.Value.Threshold.ToString()); l.SubItems.Add(kvp.Value.Worst.ToString()); l.SubItems.Add(kvp.Value.Vendordata.ToString()); if (SMARTDescription.IsAttribInError(kvp.Value) == true) { l.ForeColor = Color.Red; l.UseItemStyleForSubItems = true; } lstSmartAttr.Items.Add(l); } }
static List <VulpesSMARTInfo> GetSMARTInfo() { List <VulpesSMARTInfo> lst = new List <VulpesSMARTInfo>(); foreach (ManagementObject volume in new ManagementObjectSearcher("Select * from Win32_DiskDrive").Get()) { VulpesSMARTInfo smi = new VulpesSMARTInfo(); smi.Caption = Convert.ToString(volume["Caption"]); smi.FirmwareRevision = Convert.ToString(volume["FirmwareRevision"]); smi.InterfaceType = Convert.ToString(volume["InterfaceType"]); smi.Model = Convert.ToString(volume["Model"]); smi.Name = Convert.ToString(volume["Name"]); smi.PNPDeviceID = Convert.ToString(volume["PNPDeviceID"]); smi.SerialNumber = Convert.ToString(volume["SerialNumber"]).Trim(); smi.Size = Convert.ToInt64(volume["Size"]); smi.Status = Convert.ToString(volume["Status"]); lst.Add(smi); } //foreach (ManagementObject volume in new ManagementObjectSearcher("ROOT\\WMI", "Select * from MSStorageDriver_FailurePredictFunction").Get()) //{ // object ret = volume.InvokeMethod("EnableDisableHardwareFailurePrediction", new object[] { true }); //} foreach (ManagementObject volume in new ManagementObjectSearcher("ROOT\\WMI", "Select * from MSStorageDriver_FailurePredictStatus").Get()) { string inst = Convert.ToString(volume["InstanceName"]); if (inst.EndsWith("_0") == true) { inst = inst.Substring(0, inst.Length - 2); } VulpesSMARTInfo smi = GetElementByPNPID(lst, inst); if (smi == null) { continue; } smi.PredictFailure = Convert.ToBoolean(volume["PredictFailure"]); } foreach (ManagementObject volume in new ManagementObjectSearcher("ROOT\\WMI", "Select * from MSStorageDriver_FailurePredictData").Get()) { string inst = Convert.ToString(volume["InstanceName"]); if (inst.EndsWith("_0") == true) { inst = inst.Substring(0, inst.Length - 2); } VulpesSMARTInfo smi = GetElementByPNPID(lst, inst); if (smi == null) { continue; } smi.VendorSpecific = (byte[])volume["VendorSpecific"]; for (int i = 0; i < 30; i++) { if (smi.VendorSpecific[i * 12 + 2] == 0) //ID { continue; } smi.Attributes.Add(smi.VendorSpecific[i * 12 + 2], new VulpesSMARTAttribute() { ID = smi.VendorSpecific[i * 12 + 2], Flags = smi.VendorSpecific[i * 12 + 4], FailureImminent = (smi.VendorSpecific[i * 12 + 4] & 0x1) == 0x1, Value = smi.VendorSpecific[i * 12 + 5], Worst = smi.VendorSpecific[i * 12 + 6], Vendordata = BitConverter.ToInt32(smi.VendorSpecific, i * 12 + 7) }); } } foreach (ManagementObject volume in new ManagementObjectSearcher("ROOT\\WMI", "Select * from MSStorageDriver_FailurePredictThresholds").Get()) { string inst = Convert.ToString(volume["InstanceName"]); if (inst.EndsWith("_0") == true) { inst = inst.Substring(0, inst.Length - 2); } VulpesSMARTInfo smi = GetElementByPNPID(lst, inst); if (smi == null) { continue; } smi.VendorSpecificThreshold = (byte[])volume["VendorSpecific"]; for (int i = 0; i < 30; i++) { int id = smi.VendorSpecificThreshold[i * 12 + 2]; if (smi.Attributes.ContainsKey(id) == true) { smi.Attributes[id].Threshold = smi.VendorSpecificThreshold[i * 12 + 3]; } } } return(lst); }