예제 #1
0
        void LoadData()
        {
            lstSmartAttr.Items.Clear();
            lstDisks.Items.Clear();

            List <VulpesSMARTInfo> lst = Program.net.GetSMARTInfo(MID);

            if (lst == null)
            {
                return;
            }
            foreach (VulpesSMARTInfo ll in lst)
            {
                ListViewItem l = new ListViewItem(ll.Model);
                l.Tag = ll;
                l.SubItems.Add(ll.SerialNumber);
                l.SubItems.Add(ll.FirmwareRevision);
                l.SubItems.Add(ll.InterfaceType);
                l.SubItems.Add(CommonUtilities.NiceSize(ll.Size));
                l.SubItems.Add(ll.Status);
                l.SubItems.Add(ll.PredictFailure == true ? "FAILURE" : "");
                if (ll.Attributes == null)
                {
                    l.SubItems.Add("no");
                }
                else
                {
                    if (ll.Attributes.Count == 0)
                    {
                        l.SubItems.Add("no");
                    }
                    else
                    {
                        l.SubItems.Add("yes");
                    }
                }

                if (SMARTDescription.IsInError(ll) == true)
                {
                    l.ForeColor = Color.Red;
                    l.UseItemStyleForSubItems = true;
                }

                lstDisks.Items.Add(l);
            }
        }
예제 #2
0
        void ReportingThread(object SmartDataListO)
        {
            try
            {
                using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for SMART Device Data"))
                {
                    if (sql == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot connect to SQL Server for SMART Device Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }
                    SmartDataLst SmartDataList = (SmartDataLst)SmartDataListO;
                    ComputerData computerdata  = Computers.GetComputerDetail(sql, SmartDataList.MachineID);
                    if (computerdata == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot get any computer data for SMART Device Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }

                    List <PolicyObject>        Pol             = Policies.GetPolicyForComputerInternal(sql, SmartDataList.MachineID);
                    Dictionary <string, Int64> AlreadyReported = new Dictionary <string, long>();
                    foreach (PolicyObject PolO in Pol)
                    {
                        if (PolO.Type != PolicyIDs.ReportingPolicy)
                        {
                            continue;
                        }
                        ReportingPolicyElement RepElementRoot = JsonConvert.DeserializeObject <ReportingPolicyElement>(Policies.GetPolicy(sql, PolO.ID).Data);
                        if (RepElementRoot.Type != ReportingPolicyType.SMART)
                        {
                            continue;
                        }
                        if (RepElementRoot.ReportToAdmin == null)
                        {
                            RepElementRoot.ReportToAdmin = false;
                        }
                        if (RepElementRoot.ReportToClient == null)
                        {
                            RepElementRoot.ReportToClient = false;
                        }
                        if (RepElementRoot.UrgentForAdmin == null)
                        {
                            RepElementRoot.UrgentForAdmin = false;
                        }
                        if (RepElementRoot.UrgentForClient == null)
                        {
                            RepElementRoot.UrgentForClient = false;
                        }
                        if (RepElementRoot.ReportToAdmin == false && RepElementRoot.ReportToClient == false && RepElementRoot.UrgentForAdmin == false &&
                            RepElementRoot.UrgentForClient == false)
                        {
                            continue;
                        }

                        foreach (string Element in RepElementRoot.ReportingElements)
                        {
                            ReportingPolicyElementSMART arprep = JsonConvert.DeserializeObject <ReportingPolicyElementSMART>(Element);
                            if (arprep.NotifyOnAdd == false && arprep.NotifyOnRemove == false && arprep.NotifyOnUpdate == false &&
                                arprep.NotifyOnError == false)
                            {
                                continue;
                            }

                            if (arprep.NotifyOnAdd == true)
                            {
                                foreach (VulpesSMARTInfo ar in SmartDataList.Added)
                                {
                                    ReportThings(sql, SmartDataList.MachineID, "Add", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }

                            if (arprep.NotifyOnUpdate == true)
                            {
                                foreach (VulpesSMARTInfo ar in SmartDataList.Updated)
                                {
                                    foreach (VulpesSMARTInfo indbvsm in SmartDataList.InDB)
                                    {
                                        if (indbvsm.PNPDeviceID == ar.PNPDeviceID)
                                        {
                                            if (SMARTDescription.CompareFull(ar, indbvsm, arprep.SkipAttribUpdateReport) == false)
                                            {
                                                if (indbvsm.Attributes != null)
                                                {
                                                    List <int> UpdatedAttribs = new List <int>();
                                                    if (ar.Attributes == null)
                                                    {
                                                        ar.Attributes = new Dictionary <int, VulpesSMARTAttribute>();
                                                    }
                                                    foreach (KeyValuePair <int, VulpesSMARTAttribute> indb in indbvsm.Attributes)
                                                    {
                                                        if (ar.Attributes.ContainsKey(indb.Key) == true)
                                                        {
                                                            if (ar.Attributes[indb.Key].FailureImminent != indb.Value.FailureImminent ||
                                                                ar.Attributes[indb.Key].Flags != indb.Value.Flags ||
                                                                ar.Attributes[indb.Key].ID != indb.Value.ID ||
                                                                ar.Attributes[indb.Key].Threshold != indb.Value.Threshold ||
                                                                ar.Attributes[indb.Key].Value != indb.Value.Value ||
                                                                ar.Attributes[indb.Key].Vendordata != indb.Value.Vendordata ||
                                                                ar.Attributes[indb.Key].Worst != indb.Value.Worst)
                                                            {
                                                                UpdatedAttribs.Add(indb.Key);
                                                            }
                                                        }
                                                    }
                                                    ReportThings(sql, SmartDataList.MachineID, "Update", ar, ref AlreadyReported, RepElementRoot, UpdatedAttribs);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (arprep.NotifyOnRemove == true)
                            {
                                foreach (VulpesSMARTInfo ar in SmartDataList.Removed)
                                {
                                    ReportThings(sql, SmartDataList.MachineID, "Remove", ar, ref AlreadyReported, RepElementRoot);
                                }
                            }

                            if (arprep.NotifyOnError == true)
                            {
                                foreach (VulpesSMARTInfo ar in SmartDataList.Added)
                                {
                                    if (SMARTDescription.IsInError(ar) == true)
                                    {
                                        ReportThings(sql, SmartDataList.MachineID, "Error", ar, ref AlreadyReported, RepElementRoot);
                                    }
                                }
                                foreach (VulpesSMARTInfo ar in SmartDataList.Updated)
                                {
                                    if (SMARTDescription.IsInError(ar) == true)
                                    {
                                        foreach (VulpesSMARTInfo indbvsm in SmartDataList.InDB)
                                        {
                                            if (indbvsm.PNPDeviceID == ar.PNPDeviceID)
                                            {
                                                if (SMARTDescription.CompareFullCriticalOnly(indbvsm, ar) == false)
                                                {
                                                    ReportThings(sql, SmartDataList.MachineID, "Error", ar, ref AlreadyReported, RepElementRoot);
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                FoxEventLog.WriteEventLog("SEH in SMART Data Reporting " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
            }
        }