public RESTStatus GetSMARTInfos(SQLLib sql, object dummy, NetworkConnectionInfo ni, string id) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } lock (ni.sqllock) { if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m", new SQLParam("@m", id))) == 0) { ni.Error = "Invalid MachineID"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.NotFound); } } SMARTRet = new VulpesSMARTInfoList(); SMARTRet.MachineID = id; SMARTRet.List = LoadData(id, sql); return(RESTStatus.Success); }
public RESTStatus ReportSmartInfos(SQLLib sql, VulpesSMARTInfoList SMART, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ComputerLogin) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } if (SMART == null) { ni.Error = "Invalid Items"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } SMART.MachineID = ni.Username; lock (ni.sqllock) { if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m", new SQLParam("@m", SMART.MachineID))) == 0) { ni.Error = "Invalid MachineID"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.NotFound); } } if (SMART.List == null) { SMART.List = new List <VulpesSMARTInfo>(); } if (TestAttributesKVP(SMART.List) == false) { ni.Error = "Invalid Data (KVP)"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.NotFound); } List <VulpesSMARTInfo> InDB = LoadData(SMART.MachineID, sql); List <VulpesSMARTInfo> Removed = new List <VulpesSMARTInfo>(); List <VulpesSMARTInfo> Updated = new List <VulpesSMARTInfo>(); List <VulpesSMARTInfo> Unchanged = new List <VulpesSMARTInfo>(); List <VulpesSMARTInfo> Added = new List <VulpesSMARTInfo>(); foreach (VulpesSMARTInfo SMARTDevice in SMART.List) { bool Found = false; foreach (VulpesSMARTInfo idb in InDB) { if (SMARTDescription.ComparePart(SMARTDevice, idb) == true) { if (SMARTDescription.CompareFull(SMARTDevice, idb, null) == true) { Unchanged.Add(SMARTDevice); Found = true; break; } else { Updated.Add(SMARTDevice); Found = true; break; } } } if (Found == false) { Added.Add(SMARTDevice); } } foreach (VulpesSMARTInfo SMARTDevice in InDB) { bool Found = false; foreach (VulpesSMARTInfo i in SMART.List) { if (SMARTDescription.ComparePart(SMARTDevice, i) == true) { Found = true; } } if (Found == false) { Removed.Add(SMARTDevice); } } foreach (VulpesSMARTInfo SMARTDevice in Added) { if (string.IsNullOrWhiteSpace(SMARTDevice.PNPDeviceID) == true) { continue; } lock (ni.sqllock) { sql.InsertMultiData("SMARTData", new SQLData("MachineID", SMART.MachineID), new SQLData("PNPDeviceID", SMARTDevice.PNPDeviceID == null ? "" : SMARTDevice.PNPDeviceID), new SQLData("Caption", SMARTDevice.Caption == null ? "" : SMARTDevice.Caption), new SQLData("FirmwareRevision", SMARTDevice.FirmwareRevision == null ? "" : SMARTDevice.FirmwareRevision), new SQLData("InterfaceType", SMARTDevice.InterfaceType == null ? "" : SMARTDevice.InterfaceType), new SQLData("Model", SMARTDevice.Model == null ? "" : SMARTDevice.Model), new SQLData("Name", SMARTDevice.Name == null ? "" : SMARTDevice.Name), new SQLData("PredictFailure", SMARTDevice.PredictFailure), new SQLData("SerialNumber", SMARTDevice.SerialNumber == null ? "" : SMARTDevice.SerialNumber), new SQLData("Size", SMARTDevice.Size), new SQLData("Status", SMARTDevice.Status == null ? "" : SMARTDevice.Status), new SQLData("DT", DateTime.UtcNow)); if (SMARTDevice.VendorSpecific != null) { sql.ExecSQL("UPDATE SMARTData SET VendorSpecific=@v WHERE MachineID=@id AND PNPDeviceID=@pnp", new SQLParam("@pnp", SMARTDevice.PNPDeviceID), new SQLParam("@id", SMART.MachineID), new SQLParam("@v", SMARTDevice.VendorSpecific)); } if (SMARTDevice.VendorSpecificThreshold != null) { sql.ExecSQL("UPDATE SMARTData SET VendorSpecificThreshold=@v WHERE MachineID=@id AND PNPDeviceID=@pnp", new SQLParam("@pnp", SMARTDevice.PNPDeviceID), new SQLParam("@id", SMART.MachineID), new SQLParam("@v", SMARTDevice.VendorSpecificThreshold)); } } if (SMARTDevice.Attributes == null) { SMARTDevice.Attributes = new Dictionary <int, VulpesSMARTAttribute>(); } List <int> HasID = new List <int>(); foreach (KeyValuePair <int, VulpesSMARTAttribute> kvp in SMARTDevice.Attributes) { if (HasID.Contains(kvp.Value.ID) == true) { continue; } sql.InsertMultiData("SMARTDataAttributes", new SQLData("MachineID", SMART.MachineID), new SQLData("PNPDeviceID", SMARTDevice.PNPDeviceID), new SQLData("FailureImminent", kvp.Value.FailureImminent), new SQLData("Flags", kvp.Value.Flags), new SQLData("ID", kvp.Value.ID), new SQLData("Threshold", kvp.Value.Threshold), new SQLData("Value", kvp.Value.Value), new SQLData("Vendordata", kvp.Value.Vendordata), new SQLData("Worst", kvp.Value.Worst)); HasID.Add(kvp.Value.ID); } } foreach (VulpesSMARTInfo SMARTDevice in Removed) { if (string.IsNullOrWhiteSpace(SMARTDevice.PNPDeviceID) == true) { continue; } lock (ni.sqllock) { sql.ExecSQL("DELETE FROM SMARTDataAttributes WHERE MachineID=@id AND PNPDeviceID=@pnp", new SQLParam("@id", SMART.MachineID), new SQLParam("@pnp", SMARTDevice.PNPDeviceID)); sql.ExecSQL("DELETE FROM SMARTData WHERE MachineID=@id AND PNPDeviceID=@pnp", new SQLParam("@id", SMART.MachineID), new SQLParam("@pnp", SMARTDevice.PNPDeviceID)); } } foreach (VulpesSMARTInfo SMARTDevice in Updated) { if (string.IsNullOrWhiteSpace(SMARTDevice.PNPDeviceID) == true) { continue; } lock (ni.sqllock) { sql.ExecSQL("DELETE FROM SMARTDataAttributes WHERE MachineID=@id AND PNPDeviceID=@pnp", new SQLParam("@id", SMART.MachineID), new SQLParam("@pnp", SMARTDevice.PNPDeviceID)); sql.ExecSQL("DELETE FROM SMARTData WHERE MachineID=@id AND PNPDeviceID=@pnp", new SQLParam("@id", SMART.MachineID), new SQLParam("@pnp", SMARTDevice.PNPDeviceID)); } lock (ni.sqllock) { sql.InsertMultiData("SMARTData", new SQLData("MachineID", SMART.MachineID), new SQLData("PNPDeviceID", SMARTDevice.PNPDeviceID), new SQLData("Caption", SMARTDevice.Caption == null ? "" : SMARTDevice.Caption), new SQLData("FirmwareRevision", SMARTDevice.FirmwareRevision == null ? "" : SMARTDevice.FirmwareRevision), new SQLData("InterfaceType", SMARTDevice.InterfaceType == null ? "" : SMARTDevice.InterfaceType), new SQLData("Model", SMARTDevice.Model == null ? "" : SMARTDevice.Model), new SQLData("Name", SMARTDevice.Name == null ? "" : SMARTDevice.Name), new SQLData("PredictFailure", SMARTDevice.PredictFailure), new SQLData("SerialNumber", SMARTDevice.SerialNumber == null ? "" : SMARTDevice.SerialNumber), new SQLData("Size", SMARTDevice.Size), new SQLData("Status", SMARTDevice.Status == null ? "" : SMARTDevice.Status), new SQLData("DT", DateTime.UtcNow)); if (SMARTDevice.VendorSpecific != null) { sql.ExecSQL("UPDATE SMARTData SET VendorSpecific=@v WHERE MachineID=@id AND PNPDeviceID=@pnp", new SQLParam("@pnp", SMARTDevice.PNPDeviceID), new SQLParam("@id", SMART.MachineID), new SQLParam("@v", SMARTDevice.VendorSpecific)); } if (SMARTDevice.VendorSpecificThreshold != null) { sql.ExecSQL("UPDATE SMARTData SET VendorSpecificThreshold=@v WHERE MachineID=@id AND PNPDeviceID=@pnp", new SQLParam("@pnp", SMARTDevice.PNPDeviceID), new SQLParam("@id", SMART.MachineID), new SQLParam("@v", SMARTDevice.VendorSpecificThreshold)); } } if (SMARTDevice.Attributes == null) { SMARTDevice.Attributes = new Dictionary <int, VulpesSMARTAttribute>(); } List <int> HasID = new List <int>(); foreach (KeyValuePair <int, VulpesSMARTAttribute> kvp in SMARTDevice.Attributes) { if (HasID.Contains(kvp.Value.ID) == true) { continue; } sql.InsertMultiData("SMARTDataAttributes", new SQLData("MachineID", SMART.MachineID), new SQLData("PNPDeviceID", SMARTDevice.PNPDeviceID), new SQLData("FailureImminent", kvp.Value.FailureImminent), new SQLData("Flags", kvp.Value.Flags), new SQLData("ID", kvp.Value.ID), new SQLData("Threshold", kvp.Value.Threshold), new SQLData("Value", kvp.Value.Value), new SQLData("Vendordata", kvp.Value.Vendordata), new SQLData("Worst", kvp.Value.Worst)); HasID.Add(kvp.Value.ID); } } SmartDataLst l = new SmartDataLst(); l.Added = Added; l.Removed = Removed; l.Unchanged = Unchanged; l.Updated = Updated; l.InDB = InDB; l.MachineID = SMART.MachineID; Thread t = new Thread(new ParameterizedThreadStart(new DReportingThread(ReportingThread))); t.Start(l); return(RESTStatus.Success); }