コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: Startups.cs プロジェクト: VulpesSARL/Fox-SDC
        void ReportThings(SQLLib sql, string MachineID, string Method, StartupItem ar, ref Dictionary <string, Int64> AlreadyReported, ReportingPolicyElement RepElementRoot)
        {
            string ID = MachineID + "\\\\" + ar.Key + "\\\\" + ar.Location;

            if (string.IsNullOrWhiteSpace(ar.HKCUUser) == false)
            {
                ID += "\\\\" + ar.HKCUUser;
            }
            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);

            ReportingProcessor.ReportStartup(sql, MachineID, Method, ar, Flags);

            if (AlreadyReported.ContainsKey(ID) == true)
            {
                AlreadyReported[ID] |= (Int64)Flags;
            }
            else
            {
                AlreadyReported.Add(ID, (Int64)Flags);
            }
        }
コード例 #3
0
ファイル: SimpleTasks.cs プロジェクト: VulpesSARL/Fox-SDC
        void ReportThings(SQLLib sql, string MachineID, string Method, SimpleTaskResult ar, ref Dictionary <string, Int64> AlreadyReported, ReportingPolicyElement RepElementRoot)
        {
            string ID = MachineID + "\\" + Method;

            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);

            ReportingProcessor.ReportSimpleTaskCompletion(sql, MachineID, Method, ar, Flags);

            if (AlreadyReported.ContainsKey(ID) == true)
            {
                AlreadyReported[ID] |= (Int64)Flags;
            }
            else
            {
                AlreadyReported.Add(ID, (Int64)Flags);
            }
        }
コード例 #4
0
        void ReportingThread(object EventDataListO)
        {
            try
            {
                using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for EventLog Data"))
                {
                    if (sql == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot connect to SQL Server for Event Log Data Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }
                    List <EventLogReportFull> EventDataList = (List <EventLogReportFull>)EventDataListO;
                    if (EventDataList.Count == 0)
                    {
                        return;
                    }
                    List <PolicyObject>        Pol             = Policies.GetPolicyForComputerInternal(sql, EventDataList[0].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.EventLog)
                        {
                            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)
                        {
                            ReportingPolicyElementEventLog evrep = JsonConvert.DeserializeObject <ReportingPolicyElementEventLog>(Element);
                            if (evrep.Book == null)
                            {
                                evrep.Book = new List <string>();
                            }
                            if (evrep.CategoryNumbers == null)
                            {
                                evrep.CategoryNumbers = new List <int>();
                            }
                            if (evrep.EventLogTypes == null)
                            {
                                evrep.EventLogTypes = new List <int>();
                            }
                            if (evrep.Sources == null)
                            {
                                evrep.Sources = new List <string>();
                            }
                            if (evrep.Book.Count == 0 && evrep.CategoryNumbers.Count == 0 && evrep.EventLogTypes.Count == 0 && evrep.Sources.Count == 0)
                            {
                                continue;
                            }
                            foreach (EventLogReportFull EV in EventDataList)
                            {
                                if (evrep.Book.Count != 0)
                                {
                                    bool Match = false;
                                    foreach (string Book in evrep.Book)
                                    {
                                        if (Book.ToLower() == EV.EventLog.ToLower())
                                        {
                                            Match = true;
                                            break;
                                        }
                                    }
                                    if (Match == false)
                                    {
                                        continue;
                                    }
                                }
                                if (evrep.Sources.Count != 0)
                                {
                                    bool Match = false;
                                    foreach (string Source in evrep.Sources)
                                    {
                                        if (Source.ToLower() == EV.Source.ToLower())
                                        {
                                            Match = true;
                                            break;
                                        }
                                    }
                                    if (Match == false)
                                    {
                                        continue;
                                    }
                                }
                                if (evrep.EventLogTypes.Count != 0)
                                {
                                    bool Match = false;
                                    foreach (int EVLType in evrep.EventLogTypes)
                                    {
                                        if (EVLType == EV.EventLogType)
                                        {
                                            Match = true;
                                            break;
                                        }
                                    }
                                    if (Match == false)
                                    {
                                        continue;
                                    }
                                }
                                if (evrep.CategoryNumbers.Count != 0)
                                {
                                    bool Match = false;
                                    foreach (int Cat in evrep.CategoryNumbers)
                                    {
                                        if (Cat == (EV.InstanceID & 0x3FFFFFFF))
                                        {
                                            Match = true;
                                            break;
                                        }
                                    }
                                    if (Match == false)
                                    {
                                        continue;
                                    }
                                }

                                if (evrep.IncludeExclude == 1) //include
                                {
                                    if (evrep.IncludeExcludeTexts != null)
                                    {
                                        bool Match = false;
                                        foreach (string s in evrep.IncludeExcludeTexts)
                                        {
                                            if (EV.Message.ToLower().Contains(s.ToLower()) == true)
                                            {
                                                Match = true;
                                                break;
                                            }
                                        }
                                        if (Match == false)
                                        {
                                            continue;
                                        }
                                    }
                                }

                                if (evrep.IncludeExclude == 2) //exclude
                                {
                                    if (evrep.IncludeExcludeTexts != null)
                                    {
                                        bool Match = true;
                                        foreach (string s in evrep.IncludeExcludeTexts)
                                        {
                                            if (EV.Message.ToLower().Contains(s.ToLower()) == true)
                                            {
                                                Match = false;
                                                break;
                                            }
                                        }
                                        if (Match == false)
                                        {
                                            continue;
                                        }
                                    }
                                }

                                bool ReportToAdmin   = RepElementRoot.ReportToAdmin.Value;
                                bool ReportToClient  = RepElementRoot.ReportToClient.Value;
                                bool UrgentForAdmin  = RepElementRoot.UrgentForAdmin.Value;
                                bool UrgentForClient = RepElementRoot.UrgentForClient.Value;

                                if (AlreadyReported.ContainsKey(EV.LogID) == true)
                                {
                                    if ((AlreadyReported[EV.LogID] & (Int64)ReportingFlags.ReportToAdmin) != 0)
                                    {
                                        ReportToAdmin = false;
                                    }
                                    if ((AlreadyReported[EV.LogID] & (Int64)ReportingFlags.ReportToClient) != 0)
                                    {
                                        ReportToClient = false;
                                    }
                                    if ((AlreadyReported[EV.LogID] & (Int64)ReportingFlags.UrgentForAdmin) != 0)
                                    {
                                        UrgentForAdmin = false;
                                    }
                                    if ((AlreadyReported[EV.LogID] & (Int64)ReportingFlags.UrgentForClient) != 0)
                                    {
                                        UrgentForClient = false;
                                    }
                                }

                                if (ReportToAdmin == false && ReportToClient == false && UrgentForAdmin == false && UrgentForClient == false)
                                {
                                    continue;
                                }
                                ReportingFlags Flags = (ReportToAdmin == true ? ReportingFlags.ReportToAdmin : 0) |
                                                       (ReportToClient == true ? ReportingFlags.ReportToClient : 0) |
                                                       (UrgentForAdmin == true ? ReportingFlags.UrgentForAdmin : 0) |
                                                       (UrgentForClient == true ? ReportingFlags.UrgentForClient : 0);
                                switch ((EventLogEntryType)EV.EventLogType)
                                {
                                case 0:
                                case EventLogEntryType.Information:
                                    Flags = (ReportingFlags)((Int64)Flags | ((Int64)ReportingStatusPictureEnum.Info << (int)ReportingFlags.IconFlagsShift));
                                    break;

                                case EventLogEntryType.Warning:
                                    Flags = (ReportingFlags)((Int64)Flags | ((Int64)ReportingStatusPictureEnum.Exclamation << (int)ReportingFlags.IconFlagsShift));
                                    break;

                                case EventLogEntryType.Error:
                                    Flags = (ReportingFlags)((Int64)Flags | ((Int64)ReportingStatusPictureEnum.Stop << (int)ReportingFlags.IconFlagsShift));
                                    break;

                                case EventLogEntryType.SuccessAudit:
                                    Flags = (ReportingFlags)((Int64)Flags | ((Int64)ReportingStatusPictureEnum.Key << (int)ReportingFlags.IconFlagsShift));
                                    break;

                                case EventLogEntryType.FailureAudit:
                                    Flags = (ReportingFlags)((Int64)Flags | ((Int64)ReportingStatusPictureEnum.NoKey << (int)ReportingFlags.IconFlagsShift));
                                    break;
                                }
                                ReportingProcessor.ReportEventLog(sql, EV.MachineID, EV, Flags);
                                if (AlreadyReported.ContainsKey(EV.LogID) == true)
                                {
                                    AlreadyReported[EV.LogID] |= (Int64)Flags;
                                }
                                else
                                {
                                    AlreadyReported.Add(EV.LogID, (Int64)Flags);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                FoxEventLog.WriteEventLog("SEH in Event Data Reporting " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
            }
        }
コード例 #5
0
        public List <ReportingPaperElements> GetItems(string MachineID, DateTime?From, DateTime?To, int ReportingPaper)
        {
            List <ReportingPaperElements> lst = new List <ReportingPaperElements>();

            if (string.IsNullOrWhiteSpace(MachineID) == true)
            {
                ReportingPaperElements funnybasicinfo = new ReportingPaperElements();
                funnybasicinfo.AgentVersion        = "Fox SDC 950228180442";
                funnybasicinfo.BIOSBootType        = "Legacy";
                funnybasicinfo.LastUpdated         = new DateTime(1995, 3, 5, 19, 35, 21);
                funnybasicinfo.MachineID           = "8878FF7A-2506-4A63-B0F1-A0C28AFD6480";
                funnybasicinfo.MachineName         = "FOX-PC1-NT3";
                funnybasicinfo.OS                  = "Windows NT 3.51 Service Pack 5";
                funnybasicinfo.OSVersion           = "3.51.1057";
                funnybasicinfo.OSWin10Version      = "";
                funnybasicinfo.TotalPhysicalMemory = CommonUtilities.NiceSize(67108864);
                funnybasicinfo.UCID                = "F3489E4C92654D12A6EF6C4C2EAA4A5E";
                funnybasicinfo.VendorBIOS          = "Award BIOS 6";
                funnybasicinfo.VendorMake          = "Vulpes 486 PC";
                funnybasicinfo.ContractID          = "Company XXX Contract";

                lst.Add(new ReportingPaperElements());
                CopyBaseData(funnybasicinfo, lst[0]);
                lst[0].ID            = 10005;
                lst[0].ReportedDate  = new DateTime(1995, 3, 5, 18, 20, 54);
                lst[0].IconPicture   = Resources.Vulpes.ToBitmap();
                lst[0].StatusPicture = ReportingStatusPicture.GetPicture(ReportingStatusPictureEnum.Good);
                lst[0].Text          = "Reporting test ...\nNew line\n\nAnother line";

                lst.Add(new ReportingPaperElements());
                CopyBaseData(funnybasicinfo, lst[1]);
                lst[1].ID            = 10004;
                lst[1].ReportedDate  = new DateTime(1995, 3, 5, 18, 19, 12);
                lst[1].IconPicture   = Resources.EventLog.ToBitmap();
                lst[1].StatusPicture = ReportingStatusPicture.GetPicture(ReportingStatusPictureEnum.Info);
                lst[1].Text          = "The Event log service was started.";

                lst.Add(new ReportingPaperElements());
                CopyBaseData(funnybasicinfo, lst[2]);
                lst[2].ID            = 10003;
                lst[2].ReportedDate  = new DateTime(1995, 3, 5, 18, 15, 35);
                lst[2].IconPicture   = Resources.EventLog.ToBitmap();
                lst[2].StatusPicture = ReportingStatusPicture.GetPicture(ReportingStatusPictureEnum.Stop);
                lst[2].Text          = "The system has rebooted without cleanly shutting down first. This error could be caused if the system stopped responding, crashed, or lost power unexpectedly.";

                return(lst);
            }

            Settings.Default.Load();

            using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for Reporting"))
            {
                if (sql == null)
                {
                    return(lst);
                }

                //Get some ComputerInfo
                SqlDataReader dr = sql.ExecSQLReader("select * from ComputerAccounts Where MachineID=@m",
                                                     new SQLParam("@m", MachineID));
                if (dr.HasRows == false)
                {
                    dr.Close();
                    sql.CloseConnection();
                    return(lst);
                }

                dr.Read();
                ReportingPaperElements basicinfo = new ReportingPaperElements();
                basicinfo.AgentVersion        = Convert.ToString(dr["AgentVersion"]);
                basicinfo.BIOSBootType        = Convert.ToString(dr["BIOSType"]);
                basicinfo.LastUpdated         = SQLLib.GetDTUTC(dr["LastUpdated"]);
                basicinfo.MachineID           = Convert.ToString(dr["MachineID"]);
                basicinfo.MachineName         = Convert.ToString(dr["ComputerName"]);
                basicinfo.OS                  = Convert.ToString(dr["OSName"]);
                basicinfo.OSVersion           = Convert.ToString(dr["OSVerMaj"]) + "." + Convert.ToString(dr["OSVerMin"]) + "." + Convert.ToString(dr["OSVerBuild"]);
                basicinfo.OSWin10Version      = Win10Version.GetWin10Version(basicinfo.OSVersion);
                basicinfo.TotalPhysicalMemory = CommonUtilities.NiceSize(Convert.ToInt64(dr["TotalPhysicalMemory"]));
                basicinfo.UCID                = Convert.ToString(dr["UCID"]);
                basicinfo.VendorBIOS          = Convert.ToString(dr["BIOS"]);
                basicinfo.VendorMake          = Convert.ToString(dr["ComputerModel"]);
                basicinfo.ContractID          = Convert.ToString(dr["ContractID"]);
                dr.Close();

                string          Query     = "";
                List <SQLParam> SQLParams = new List <SQLParam>();
                switch ((ReportingFlagsPaper)ReportingPaper)
                {
                case ReportingFlagsPaper.UrgentAdmin:
                    Query = "Select * from Reporting where machineid=@mid and (Flags & @f1)!=0 AND (Flags & @f2)=0 order by Reported desc";
                    SQLParams.Add(new SQLParam("@mid", MachineID));
                    SQLParams.Add(new SQLParam("@f1", ReportingFlags.UrgentForAdmin));
                    SQLParams.Add(new SQLParam("@f2", ReportingFlags.UrgentAdminReported));
                    break;

                case ReportingFlagsPaper.UrgentClient:
                    Query = "Select * from Reporting where machineid=@mid and (Flags & @f1)!=0 AND (Flags & @f2)=0 order by Reported desc";
                    SQLParams.Add(new SQLParam("@mid", MachineID));
                    SQLParams.Add(new SQLParam("@f1", ReportingFlags.UrgentForClient));
                    SQLParams.Add(new SQLParam("@f2", ReportingFlags.UrgentClientReported));
                    break;

                case ReportingFlagsPaper.ReportAdmin:
                    Query = "Select * from Reporting where machineid=@mid and (Flags & @f1)!=0 AND (Flags & @f2)=0 order by Reported desc";
                    SQLParams.Add(new SQLParam("@mid", MachineID));
                    SQLParams.Add(new SQLParam("@f1", ReportingFlags.ReportToAdmin));
                    SQLParams.Add(new SQLParam("@f2", ReportingFlags.AdminReported));
                    break;

                case ReportingFlagsPaper.ReportClient:
                    Query = "Select * from Reporting where machineid=@mid and (Flags & @f1)!=0 AND (Flags & @f2)=0 order by Reported desc";
                    SQLParams.Add(new SQLParam("@mid", MachineID));
                    SQLParams.Add(new SQLParam("@f1", ReportingFlags.ReportToClient));
                    SQLParams.Add(new SQLParam("@f2", ReportingFlags.ClientReported));
                    break;

                case ReportingFlagsPaper.ReReport:
                    if (From == null && To == null)
                    {
                        Query = "Select * from Reporting where machineid=@mid order by Reported desc";
                        SQLParams.Add(new SQLParam("@mid", MachineID));
                    }
                    if (From != null && To == null)
                    {
                        Query = "Select * from Reporting where machineid=@mid AND Reported>=@d1 order by Reported desc";
                        SQLParams.Add(new SQLParam("@mid", MachineID));
                        SQLParams.Add(new SQLParam("@d1", From.Value));
                    }
                    if (From == null && To != null)
                    {
                        Query = "Select * from Reporting where machineid=@mid AND Reported<=@d1 order by Reported desc";
                        SQLParams.Add(new SQLParam("@mid", MachineID));
                        SQLParams.Add(new SQLParam("@d1", To.Value));
                    }
                    if (From != null && To != null)
                    {
                        Query = "Select * from Reporting where machineid=@mid and Reported between @d1 and @d2 order by Reported desc";
                        SQLParams.Add(new SQLParam("@mid", MachineID));
                        SQLParams.Add(new SQLParam("@d1", From.Value));
                        SQLParams.Add(new SQLParam("@d2", To.Value));
                    }
                    break;

                default:
                    return(lst);
                }

                List <Int64> ReportedIDs = new List <long>();

                dr = sql.ExecSQLReader(Query, SQLParams.ToArray());
                while (dr.Read())
                {
                    ReportingPaperElements r = new ReportingPaperElements();
                    CopyBaseData(basicinfo, r);
                    ReportedIDs.Add(Convert.ToInt64(dr["ID"]));
                    r.ID            = Convert.ToInt64(dr["ID"]);
                    r.Flags         = Convert.ToInt64(dr["Flags"]);
                    r.ReportingType = Convert.ToInt32(dr["Type"]);
                    r.ReportedDate  = SQLLib.GetDTUTC(dr["Reported"]);
                    r.StatusPicture = ReportingStatusPicture.GetPicture((int)((r.Flags & (Int64)ReportingFlags.IconFlags) >> (int)ReportingFlags.IconFlagsShift));
                    IReportingExplain explain = ReportingProcessor.FindExplainer(r.ReportingType);
                    if (explain != null)
                    {
                        r.Text        = explain.Explain(Convert.ToString(dr["Data"]));
                        r.IconPicture = explain.GetIcon();
                    }
                    else
                    {
                        r.Text        = "Missing module for Type=" + r.ReportingType.ToString() + "; Text=" + Convert.ToString(dr["Data"]);
                        r.IconPicture = Resources.Nix.ToBitmap();
                    }
                    lst.Add(r);
                }
                dr.Close();

                if (ReportedIDs.Count > 0 && (ReportingFlagsPaper)ReportingPaper != ReportingFlagsPaper.ReReport)
                {
                    string SQLIn = "";
                    foreach (Int64 i in ReportedIDs)
                    {
                        SQLIn += i.ToString() + ",";
                    }

                    if (SQLIn.EndsWith(",") == true)
                    {
                        SQLIn = SQLIn.Substring(0, SQLIn.Length - 1);
                    }

                    Query     = "";
                    SQLParams = new List <SQLParam>();

                    switch ((ReportingFlagsPaper)ReportingPaper)
                    {
                    case ReportingFlagsPaper.UrgentAdmin:
                        Query = "update Reporting set Flags = Flags | @f2 where machineid=@mid and Flags & @f1!=0 AND Flags & @f2=0";
                        SQLParams.Add(new SQLParam("@mid", MachineID));
                        SQLParams.Add(new SQLParam("@f1", ReportingFlags.UrgentForAdmin));
                        SQLParams.Add(new SQLParam("@f2", ReportingFlags.UrgentAdminReported));
                        break;

                    case ReportingFlagsPaper.UrgentClient:
                        Query = "update Reporting set Flags = Flags | @f2 where machineid=@mid and Flags & @f1!=0 AND Flags & @f2=0";
                        SQLParams.Add(new SQLParam("@mid", MachineID));
                        SQLParams.Add(new SQLParam("@f1", ReportingFlags.UrgentForClient));
                        SQLParams.Add(new SQLParam("@f2", ReportingFlags.UrgentClientReported));
                        break;

                    case ReportingFlagsPaper.ReportAdmin:
                        Query = "update Reporting set Flags = Flags | @f2 where machineid=@mid and Flags & @f1!=0 AND Flags & @f2=0";
                        SQLParams.Add(new SQLParam("@mid", MachineID));
                        SQLParams.Add(new SQLParam("@f1", ReportingFlags.ReportToAdmin));
                        SQLParams.Add(new SQLParam("@f2", ReportingFlags.AdminReported));
                        break;

                    case ReportingFlagsPaper.ReportClient:
                        Query = "update Reporting set Flags = Flags | @f2 where machineid=@mid and Flags & @f1!=0 AND Flags & @f2=0";
                        SQLParams.Add(new SQLParam("@mid", MachineID));
                        SQLParams.Add(new SQLParam("@f1", ReportingFlags.ReportToClient));
                        SQLParams.Add(new SQLParam("@f2", ReportingFlags.ClientReported));
                        break;
                    }

                    sql.ExecSQLNQ(Query, SQLParams.ToArray());
                }
            }
            return(lst);
        }
コード例 #6
0
ファイル: DiskData.cs プロジェクト: VulpesSARL/Fox-SDC
        void ReportingThread(object DiskDataListO)
        {
            try
            {
                using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for DiskData"))
                {
                    if (sql == null)
                    {
                        FoxEventLog.WriteEventLog("Cannot connect to SQL Server for Disk Data Reporting!", System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }
                    ListDiskDataReport  DiskDataList = (ListDiskDataReport)DiskDataListO;
                    List <PolicyObject> Pol          = Policies.GetPolicyForComputerInternal(sql, DiskDataList.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.Disk)
                        {
                            continue;
                        }

                        foreach (string Element in RepElementRoot.ReportingElements)
                        {
                            ReportingPolicyElementDisk diskrep = JsonConvert.DeserializeObject <ReportingPolicyElementDisk>(Element);
                            if (diskrep.DriveLetter == null)
                            {
                                continue;
                            }
                            if (diskrep.DriveLetter.Length != 1)
                            {
                                continue;
                            }

                            foreach (DiskDataReport DD in DiskDataList.Items)
                            {
                                string Drive = diskrep.DriveLetter;

                                if (diskrep.DriveLetter == "$")
                                {
                                    ComputerData d = Computers.GetComputerDetail(sql, DiskDataList.MachineID);
                                    if (d != null)
                                    {
                                        if (string.IsNullOrWhiteSpace(d.SystemRoot) == false)
                                        {
                                            Drive = d.SystemRoot.Substring(0, 1);
                                        }
                                    }
                                }

                                if (string.IsNullOrWhiteSpace(DD.DriveLetter) == true)
                                {
                                    continue;
                                }
                                if (DD.DriveLetter.ToLower().Substring(0, 1) != Drive.ToLower())
                                {
                                    continue;
                                }

                                Int64 SZLimit;

                                if (diskrep.Method == 1)
                                {
                                    SZLimit = (Int64)((100m / (decimal)DD.Capacity) * (decimal)diskrep.MinimumSize);
                                }
                                else
                                {
                                    SZLimit = diskrep.MinimumSize;
                                }

                                if (DD.FreeSpace < SZLimit)
                                {
                                    bool ReportToAdmin   = RepElementRoot.ReportToAdmin.Value;
                                    bool ReportToClient  = RepElementRoot.ReportToClient.Value;
                                    bool UrgentForAdmin  = RepElementRoot.UrgentForAdmin.Value;
                                    bool UrgentForClient = RepElementRoot.UrgentForClient.Value;

                                    if (AlreadyReported.ContainsKey(DD.DriveLetter) == true)
                                    {
                                        if ((AlreadyReported[DD.DriveLetter] & (Int64)ReportingFlags.ReportToAdmin) != 0)
                                        {
                                            ReportToAdmin = false;
                                        }
                                        if ((AlreadyReported[DD.DriveLetter] & (Int64)ReportingFlags.ReportToClient) != 0)
                                        {
                                            ReportToClient = false;
                                        }
                                        if ((AlreadyReported[DD.DriveLetter] & (Int64)ReportingFlags.UrgentForAdmin) != 0)
                                        {
                                            UrgentForAdmin = false;
                                        }
                                        if ((AlreadyReported[DD.DriveLetter] & (Int64)ReportingFlags.UrgentForClient) != 0)
                                        {
                                            UrgentForClient = false;
                                        }
                                    }

                                    if (ReportToAdmin == false && ReportToClient == false && UrgentForAdmin == false && UrgentForClient == false)
                                    {
                                        continue;
                                    }
                                    ReportingFlags Flags = (ReportToAdmin == true ? ReportingFlags.ReportToAdmin : 0) |
                                                           (ReportToClient == true ? ReportingFlags.ReportToClient : 0) |
                                                           (UrgentForAdmin == true ? ReportingFlags.UrgentForAdmin : 0) |
                                                           (UrgentForClient == true ? ReportingFlags.UrgentForClient : 0);
                                    ReportingProcessor.ReportDiskData(sql, DiskDataList.MachineID, DD.DriveLetter, SZLimit, DD.FreeSpace, DD.Capacity, Flags);
                                    if (AlreadyReported.ContainsKey(DD.DriveLetter) == true)
                                    {
                                        AlreadyReported[DD.DriveLetter] |= (Int64)Flags;
                                    }
                                    else
                                    {
                                        AlreadyReported.Add(DD.DriveLetter, (Int64)Flags);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                FoxEventLog.WriteEventLog("SEH in Disk Data Reporting " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error);
            }
        }