static void RThread() { do { try { using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for Reporting", 0)) { if (sql == null) { Pause(); if (StopThread == true) { break; } } string ErrorMessage; if (MailSender.CheckConfig() == false) { Pause(); if (StopThread == true) { break; } continue; } if (string.IsNullOrWhiteSpace(SettingsManager.Settings.EMailAdminTo) == true) { Pause(); if (StopThread == true) { break; } continue; } SqlDataReader dr; List <string> ConcernedMachineIDs; #region Normal Admin Report if (SettingsManager.Settings.LastScheduleRanAdmin == null) { SettingsManager.Settings.LastScheduleRanAdmin = DateTime.UtcNow; SettingsManager.SaveApplySettings2(sql, SettingsManager.Settings); } else { DateTime?Planned = Scheduler.GetNextRunDate(SettingsManager.Settings.LastScheduleRanAdmin.Value, SettingsManager.Settings.EMailAdminScheduling); if (RunAdminNow == true) { Planned = DateTime.UtcNow.AddMinutes(-1); RunAdminNow = false; } if (Planned != null) { if (Planned.Value < DateTime.UtcNow) //is in the past - run now (may also be a "miss") { dr = sql.ExecSQLReader("Select distinct machineid from Reporting where (Flags & @f1)!=0 AND (Flags & @f2)=0", new SQLParam("@f1", ReportingFlags.ReportToAdmin), new SQLParam("@f2", ReportingFlags.AdminReported)); ConcernedMachineIDs = new List <string>(); while (dr.Read()) { ConcernedMachineIDs.Add(Convert.ToString(dr["MachineID"])); } dr.Close(); if (ConcernedMachineIDs.Count > 0) { byte[] PDFFile = RenderReport.RenderMachineReport(sql, ConcernedMachineIDs, null, null, ReportingFlagsPaper.ReportAdmin, "PDF"); if (PDFFile == null) { FoxEventLog.WriteEventLog("Admin Report has no data.", System.Diagnostics.EventLogEntryType.Error); } else { string Text = SettingsManager.Settings.EMailAdminText; string Subject = SettingsManager.Settings.EMailAdminSubject; Text = Text.Replace("{URGENT}", ""). Replace("{NMACHINESS}", ConcernedMachineIDs.Count == 1 ? "" : "s"). Replace("{NMACHINES}", ConcernedMachineIDs.Count.ToString()); Subject = Subject.Replace("{URGENT}", ""). Replace("{NMACHINESS}", ConcernedMachineIDs.Count == 1 ? "" : "s"). Replace("{NMACHINES}", ConcernedMachineIDs.Count.ToString()); if (MailSender.SendEMailAdmin(Subject, Text, new List <System.Net.Mail.Attachment> { new System.Net.Mail.Attachment(new MemoryStream(PDFFile), ReportAttachementFilename) }, System.Net.Mail.MailPriority.Normal, out ErrorMessage, SettingsManager.Settings.EMailAdminIsHTML) == false) { FoxEventLog.WriteEventLog("Cannot send Admin E-Mail: " + ErrorMessage, System.Diagnostics.EventLogEntryType.Error); } } } SettingsManager.Settings.LastScheduleRanAdmin = DateTime.UtcNow; SettingsManager.SaveApplySettings2(sql, SettingsManager.Settings); } } else { //update anyways SettingsManager.Settings.LastScheduleRanAdmin = DateTime.UtcNow; SettingsManager.SaveApplySettings2(sql, SettingsManager.Settings); } } #endregion #region Urgent Admin dr = sql.ExecSQLReader("Select distinct machineid from Reporting where (Flags & @f1)!=0 AND (Flags & @f2)=0", new SQLParam("@f1", ReportingFlags.UrgentForAdmin), new SQLParam("@f2", ReportingFlags.UrgentAdminReported)); ConcernedMachineIDs = new List <string>(); while (dr.Read()) { ConcernedMachineIDs.Add(Convert.ToString(dr["MachineID"])); } dr.Close(); if (ConcernedMachineIDs.Count > 0) { byte[] PDFFile = RenderReport.RenderMachineReport(sql, ConcernedMachineIDs, null, null, ReportingFlagsPaper.UrgentAdmin, "PDF"); if (PDFFile == null) { FoxEventLog.WriteEventLog("Urgent Admin Report has no data.", System.Diagnostics.EventLogEntryType.Error); } else { string Text = SettingsManager.Settings.EMailAdminText; string Subject = SettingsManager.Settings.EMailAdminSubject; Text = Text.Replace("{URGENT}", "Urgent "). Replace("{NMACHINESS}", ConcernedMachineIDs.Count == 1 ? "" : "s"). Replace("{NMACHINES}", ConcernedMachineIDs.Count.ToString()); Subject = Subject.Replace("{URGENT}", "Urgent "). Replace("{NMACHINESS}", ConcernedMachineIDs.Count == 1 ? "" : "s"). Replace("{NMACHINES}", ConcernedMachineIDs.Count.ToString()); if (MailSender.SendEMailAdmin(Subject, Text, new List <System.Net.Mail.Attachment> { new System.Net.Mail.Attachment(new MemoryStream(PDFFile), ReportAttachementFilename) }, System.Net.Mail.MailPriority.High, out ErrorMessage, SettingsManager.Settings.EMailAdminIsHTML) == false) { FoxEventLog.WriteEventLog("Cannot send Urgent Admin E-Mail: " + ErrorMessage, System.Diagnostics.EventLogEntryType.Error); } } } #endregion #region Normal Client Report if (Settings.Default.UseContract == true) { if (SettingsManager.Settings.LastScheduleRanClient == null) { SettingsManager.Settings.LastScheduleRanClient = DateTime.UtcNow; SettingsManager.SaveApplySettings2(sql, SettingsManager.Settings); } else { DateTime?Planned = Scheduler.GetNextRunDate(SettingsManager.Settings.LastScheduleRanClient.Value, SettingsManager.Settings.EMailClientScheduling); if (Planned != null) { if (Planned.Value < DateTime.UtcNow) //is in the past - run now (may also be a "miss") { dr = sql.ExecSQLReader(@"select ComputerAccounts.MachineID,ComputerAccounts.ContractID,EMail from ComputerAccounts inner join Contracts on Contracts.ContractID = ComputerAccounts.ContractID where Disabled = 0 and MachineID in (Select distinct machineid from Reporting where (Flags & @f1) != 0 AND(Flags & @f2) = 0) and EMail is not null and EMail !=''", new SQLParam("@f1", ReportingFlags.ReportToClient), new SQLParam("@f2", ReportingFlags.ClientReported)); List <ConcernedMachineIDsClient> ConcernedMachineIDC = new List <ConcernedMachineIDsClient>(); List <string> ContractIDs = new List <string>(); while (dr.Read()) { ConcernedMachineIDsClient m = new ConcernedMachineIDsClient(); m.ContractID = Convert.ToString(dr["ContractID"]); m.MachineID = Convert.ToString(dr["MachineID"]); m.EMail = Convert.ToString(dr["EMail"]); ConcernedMachineIDC.Add(m); if (ContractIDs.Contains(m.ContractID) == false) { ContractIDs.Add(m.ContractID); } } dr.Close(); foreach (string ContractID in ContractIDs) { List <string> ConcernedMachineIDsForClient = new List <string>(); string EMail = ""; foreach (ConcernedMachineIDsClient m in ConcernedMachineIDC) { if (m.ContractID == ContractID) { ConcernedMachineIDsForClient.Add(m.MachineID); } if (string.IsNullOrWhiteSpace(EMail) == true) { EMail = m.EMail; } } if (string.IsNullOrWhiteSpace(EMail) == true) { continue; } if (ConcernedMachineIDsForClient.Count > 0) { byte[] PDFFile = RenderReport.RenderMachineReport(sql, ConcernedMachineIDsForClient, null, null, ReportingFlagsPaper.ReportClient, "PDF"); if (PDFFile == null) { FoxEventLog.WriteEventLog("Client Report has no data.", System.Diagnostics.EventLogEntryType.Error); } else { string Text = SettingsManager.Settings.EMailClientText; string Subject = SettingsManager.Settings.EMailClientSubject; Text = Text.Replace("{URGENT}", ""). Replace("{NMACHINESS}", ConcernedMachineIDsForClient.Count == 1 ? "" : "s"). Replace("{NMACHINES}", ConcernedMachineIDsForClient.Count.ToString()); Subject = Subject.Replace("{URGENT}", ""). Replace("{NMACHINESS}", ConcernedMachineIDsForClient.Count == 1 ? "" : "s"). Replace("{NMACHINES}", ConcernedMachineIDsForClient.Count.ToString()); if (MailSender.SendEMailClient(EMail, Subject, Text, new List <System.Net.Mail.Attachment> { new System.Net.Mail.Attachment(new MemoryStream(PDFFile), ReportAttachementFilename) }, System.Net.Mail.MailPriority.High, out ErrorMessage, SettingsManager.Settings.EMailClientIsHTML) == false) { FoxEventLog.WriteEventLog("Cannot send Client E-Mail: " + ErrorMessage, System.Diagnostics.EventLogEntryType.Error); } } } } } } else { //update anyways SettingsManager.Settings.LastScheduleRanClient = DateTime.UtcNow; SettingsManager.SaveApplySettings2(sql, SettingsManager.Settings); } } } #endregion #region Urgent Client if (Settings.Default.UseContract == true) { dr = sql.ExecSQLReader(@"select ComputerAccounts.MachineID,ComputerAccounts.ContractID,EMail from ComputerAccounts inner join Contracts on Contracts.ContractID = ComputerAccounts.ContractID where Disabled = 0 and MachineID in (Select distinct machineid from Reporting where (Flags & @f1) != 0 AND(Flags & @f2) = 0) and EMail is not null and EMail !=''", new SQLParam("@f1", ReportingFlags.UrgentForClient), new SQLParam("@f2", ReportingFlags.UrgentClientReported)); List <ConcernedMachineIDsClient> ConcernedMachineIDC = new List <ConcernedMachineIDsClient>(); List <string> ContractIDs = new List <string>(); while (dr.Read()) { ConcernedMachineIDsClient m = new ConcernedMachineIDsClient(); m.ContractID = Convert.ToString(dr["ContractID"]); m.MachineID = Convert.ToString(dr["MachineID"]); m.EMail = Convert.ToString(dr["EMail"]); ConcernedMachineIDC.Add(m); if (ContractIDs.Contains(m.ContractID) == false) { ContractIDs.Add(m.ContractID); } } dr.Close(); foreach (string ContractID in ContractIDs) { List <string> ConcernedMachineIDsForClient = new List <string>(); string EMail = ""; foreach (ConcernedMachineIDsClient m in ConcernedMachineIDC) { if (m.ContractID == ContractID) { ConcernedMachineIDsForClient.Add(m.MachineID); } if (string.IsNullOrWhiteSpace(EMail) == true) { EMail = m.EMail; } } if (string.IsNullOrWhiteSpace(EMail) == true) { continue; } if (ConcernedMachineIDsForClient.Count > 0) { byte[] PDFFile = RenderReport.RenderMachineReport(sql, ConcernedMachineIDsForClient, null, null, ReportingFlagsPaper.UrgentClient, "PDF"); if (PDFFile == null) { FoxEventLog.WriteEventLog("Urgent Client Report has no data.", System.Diagnostics.EventLogEntryType.Error); } else { string Text = SettingsManager.Settings.EMailClientText; string Subject = SettingsManager.Settings.EMailClientSubject; Text = Text.Replace("{URGENT}", "Urgent "). Replace("{NMACHINESS}", ConcernedMachineIDsForClient.Count == 1 ? "" : "s"). Replace("{NMACHINES}", ConcernedMachineIDsForClient.Count.ToString()); Subject = Subject.Replace("{URGENT}", "Urgent "). Replace("{NMACHINESS}", ConcernedMachineIDsForClient.Count == 1 ? "" : "s"). Replace("{NMACHINES}", ConcernedMachineIDsForClient.Count.ToString()); if (MailSender.SendEMailClient(EMail, Subject, Text, new List <System.Net.Mail.Attachment> { new System.Net.Mail.Attachment(new MemoryStream(PDFFile), ReportAttachementFilename) }, System.Net.Mail.MailPriority.High, out ErrorMessage, SettingsManager.Settings.EMailClientIsHTML) == false) { FoxEventLog.WriteEventLog("Cannot send Urgent Client E-Mail: " + ErrorMessage, System.Diagnostics.EventLogEntryType.Error); } } } } } #endregion } } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot process reporting data\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } Pause(); if (StopThread == true) { break; } } while (StopThread == false); }
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); } }
public static void SMain() { string ErrorReason; Console.WriteLine("Server version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + (InstanceID == "" ? "" : " (" + InstanceID + ")")); FoxEventLog.WriteEventLog("Server version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + " starting" + (InstanceID == "" ? "" : " (" + InstanceID + ")"), EventLogEntryType.Information); if (SQLTest.TestSettings(out ErrorReason) == false) { FoxEventLog.WriteEventLog("Settings are faulty: " + ErrorReason, EventLogEntryType.Error); Console.WriteLine("Settings are faulty: " + ErrorReason); #if !DEBUG Process.GetCurrentProcess().Kill(); #endif return; } if (SQLTest.TestServer(out ErrorReason) == false) { FoxEventLog.WriteEventLog("Cannot connect to the server: " + ErrorReason, EventLogEntryType.Error); Console.WriteLine("Cannot connect to the server: " + ErrorReason); #if !DEBUG Process.GetCurrentProcess().Kill(); #endif return; } RESTful.RegisterRESTfulClasses(); FS_Watcher.InstallFSW(); if (Utilities.TestSign(out ErrorReason) == false) { FoxEventLog.WriteEventLog("Cannot test-sign with the certificate " + SettingsManager.Settings.UseCertificate + ": " + ErrorReason, EventLogEntryType.Warning); } #if DEBUG if (Fox_LicenseGenerator.SDCLicensing.ValidLicense == false) { FoxEventLog.WriteEventLog("Writing a crap-license into memory.", EventLogEntryType.Information); Fox_LicenseGenerator.SDCLicensing.NumComputers = 1000; Fox_LicenseGenerator.SDCLicensing.AllowContract = true; Fox_LicenseGenerator.SDCLicensing.Data = new Fox_LicenseGenerator.LicensingData(); Fox_LicenseGenerator.SDCLicensing.Data.Features = ""; Fox_LicenseGenerator.SDCLicensing.Data.LicenseID = Guid.NewGuid().ToString(); Fox_LicenseGenerator.SDCLicensing.Data.LicenseType = "Memory"; Fox_LicenseGenerator.SDCLicensing.Data.Owner = "Fox"; Fox_LicenseGenerator.SDCLicensing.Data.OwnerCustomID = ""; Fox_LicenseGenerator.SDCLicensing.Data.SupportValidTo = null; Fox_LicenseGenerator.SDCLicensing.Data.UCID = UCID.GetUCID(); Fox_LicenseGenerator.SDCLicensing.Data.ValidTo = null; Fox_LicenseGenerator.SDCLicensing.Data.ValidFrom = DateTime.UtcNow.Date; Fox_LicenseGenerator.SDCLicensing.Data.Vacant1 = "1000"; Fox_LicenseGenerator.SDCLicensing.ValidLicense = true; } #endif try { Console.CancelKeyPress += Console_CancelKeyPress; WebServerHandler.RunWebServer(); MaintenanceTasks.StartMaintenanceTreads(); ReportingThread.StartReportingThreads(); RemoteNetworkConnectionWSCrosser.InitialInitWS(); Console.WriteLine("=============== Server started ==============="); Debug.WriteLine("=============== Server started ==============="); Console.WriteLine(Settings.Default.ListenOn); Debug.WriteLine(Settings.Default.ListenOn); Console.WriteLine(Settings.Default.WSListenOn); Debug.WriteLine(Settings.Default.WSListenOn); FoxEventLog.WriteEventLog("Server started", EventLogEntryType.Information); ServiceRunning = true; Thread tmm = new Thread(new ThreadStart(TimeoutManager)); tmm.Start(); do { Thread.Sleep(1000); } while (ServiceRunning == true); } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot start server " + ee.Message, EventLogEntryType.Error); Console.WriteLine("Cannot start server " + ee.Message); #if !DEBUG Process.GetCurrentProcess().Kill(); #endif return; } }
void ReportingThread(object StartupListO) { try { using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for Startup Data")) { if (sql == null) { FoxEventLog.WriteEventLog("Cannot connect to SQL Server for Startup Reporting!", System.Diagnostics.EventLogEntryType.Error); return; } StartupLst StartupList = (StartupLst)StartupListO; ComputerData computerdata = Computers.GetComputerDetail(sql, StartupList.MachineID); if (computerdata == null) { FoxEventLog.WriteEventLog("Cannot get any computer data for Startup Reporting!", System.Diagnostics.EventLogEntryType.Error); return; } List <PolicyObject> Pol = Policies.GetPolicyForComputerInternal(sql, StartupList.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.Startup) { 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) { ReportingPolicyElementStartup arprep = JsonConvert.DeserializeObject <ReportingPolicyElementStartup>(Element); if (arprep.NotifyOnAdd == false && arprep.NotifyOnRemove == false && arprep.NotifyOnUpdate == false) { continue; } if (arprep.NotifyOnAdd == true) { foreach (StartupItem ar in GetFilteredData(StartupList.Added, computerdata, arprep)) { ReportThings(sql, StartupList.MachineID, "Add", ar, ref AlreadyReported, RepElementRoot); } } if (arprep.NotifyOnUpdate == true) { foreach (StartupItem ar in GetFilteredData(StartupList.Updated, computerdata, arprep)) { ReportThings(sql, StartupList.MachineID, "Update", ar, ref AlreadyReported, RepElementRoot); } } if (arprep.NotifyOnRemove == true) { foreach (StartupItem ar in GetFilteredData(StartupList.Removed, computerdata, arprep)) { ReportThings(sql, StartupList.MachineID, "Remove", ar, ref AlreadyReported, RepElementRoot); } } } } } } catch (Exception ee) { FoxEventLog.WriteEventLog("SEH in Startup Reporting " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } }
static public bool InitNi(NetworkConnectionInfo ni) { if (ni == null) { return(false); } if (ni.Inited == true) { return(true); } ni.ServerInfo = new ServerInfo(); ni.ServerInfo.Name = Environment.MachineName; ni.ServerInfo.ProtocolVersion = 1; ni.ServerInfo.ServerVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); if (ni.FromClone == false) { ni.LoggedIn = false; ni.ComputerLoggedIn = false; ni.Username = ""; ni.Name = ""; ni.EMail = ""; } SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for " + ni.ID); if (sql == null) { return(false); } ni.sql = sql; ni.sql.SEHError = true; ni.Inited = true; ni.ServerInfo.ServerGUID = Convert.ToString(sql.ExecSQLScalar("SELECT [Value] from Config WHERE [Key]='GUID'")); ni.ServerInfo.SQLServer = "N/A"; ni.ServerInfo.SQLService = "N/A"; ni.ServerInfo.SQLCollation = "N/A"; ni.ServerInfo.SQLEdition = "N/A"; ni.ServerInfo.SQLProductVersion = "N/A"; ni.ServerInfo.SQLProductLevel = "N/A"; ni.ServerInfo.SQLProductName = "N/A"; ni.ServerInfo.LicFeatures = "N/A"; ni.ServerInfo.LicLicenseID = "N/A"; ni.ServerInfo.LicLicenseType = "N/A"; ni.ServerInfo.LicOwner = "N/A"; ni.ServerInfo.LicOwnerCustomID = "N/A"; ni.ServerInfo.LicSupportValidTo = null; ni.ServerInfo.LicUCID = "N/A"; ni.ServerInfo.LicVacant1 = "N/A"; ni.ServerInfo.LicVacant2 = "N/A"; ni.ServerInfo.LicVacant3 = "N/A"; ni.ServerInfo.LicVacant4 = "N/A"; ni.ServerInfo.LicVacant5 = "N/A"; ni.ServerInfo.LicValidFrom = new DateTime(2000, 1, 1, 0, 0, 0, 0); ni.ServerInfo.LicValidTo = null; if (Settings.Default.CensorSQLInformations == false) { ni.ServerInfo.SQLServer = Convert.ToString(sql.ExecSQLScalar("select @@SERVERNAME")); ni.ServerInfo.SQLService = Convert.ToString(sql.ExecSQLScalar("select @@SERVICENAME")); ni.ServerInfo.SQLCollation = Convert.ToString(sql.ExecSQLScalar("select SERVERPROPERTY ('Collation')")); ni.ServerInfo.SQLEdition = Convert.ToString(sql.ExecSQLScalar("select SERVERPROPERTY ('edition')")); ni.ServerInfo.SQLProductVersion = Convert.ToString(sql.ExecSQLScalar("SELECT SERVERPROPERTY('productversion')")); ni.ServerInfo.SQLProductLevel = Convert.ToString(sql.ExecSQLScalar("select SERVERPROPERTY ('productlevel')")); ni.ServerInfo.SQLProductName = Convert.ToString(sql.ExecSQLScalar("SELECT LEFT(@@version, CHARINDEX(' - ', @@version))")); } if (Settings.Default.CensorLicInformations == false) { if (Fox_LicenseGenerator.SDCLicensing.Data != null) { ni.ServerInfo.LicFeatures = Fox_LicenseGenerator.SDCLicensing.Data.Features; ni.ServerInfo.LicLicenseID = Fox_LicenseGenerator.SDCLicensing.Data.LicenseID; ni.ServerInfo.LicLicenseType = Fox_LicenseGenerator.SDCLicensing.Data.LicenseType; ni.ServerInfo.LicOwner = Fox_LicenseGenerator.SDCLicensing.Data.Owner; ni.ServerInfo.LicOwnerCustomID = Fox_LicenseGenerator.SDCLicensing.Data.OwnerCustomID; ni.ServerInfo.LicSupportValidTo = Fox_LicenseGenerator.SDCLicensing.Data.SupportValidTo; ni.ServerInfo.LicUCID = Fox_LicenseGenerator.SDCLicensing.Data.UCID; ni.ServerInfo.LicVacant1 = Fox_LicenseGenerator.SDCLicensing.Data.Vacant1; ni.ServerInfo.LicVacant2 = Fox_LicenseGenerator.SDCLicensing.Data.Vacant2; ni.ServerInfo.LicVacant3 = Fox_LicenseGenerator.SDCLicensing.Data.Vacant3; ni.ServerInfo.LicVacant4 = Fox_LicenseGenerator.SDCLicensing.Data.Vacant4; ni.ServerInfo.LicVacant5 = Fox_LicenseGenerator.SDCLicensing.Data.Vacant5; ni.ServerInfo.LicValidFrom = Fox_LicenseGenerator.SDCLicensing.Data.ValidFrom; ni.ServerInfo.LicValidTo = Fox_LicenseGenerator.SDCLicensing.Data.ValidTo; } else { ni.ServerInfo.LicOwner = "Error"; } } return(true); }
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); }
void ReportingThread(object SimpleTaskO) { try { using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for SimpleTask Result Data")) { if (sql == null) { FoxEventLog.WriteEventLog("Cannot connect to SQL Server for SimpleTask Result Reporting!", System.Diagnostics.EventLogEntryType.Error); return; } SimpleTaskResult SimpleTask = (SimpleTaskResult)SimpleTaskO; List <PolicyObject> Pol = Policies.GetPolicyForComputerInternal(sql, SimpleTask.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.SimpleTaskCompleted) { 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) { ReportingPolicyElementSimpleTaskCompleted arprep = JsonConvert.DeserializeObject <ReportingPolicyElementSimpleTaskCompleted>(Element); ReportThings(sql, SimpleTask.MachineID, "Completed", SimpleTask, ref AlreadyReported, RepElementRoot); } } } } catch (Exception ee) { FoxEventLog.WriteEventLog("SEH in SimpleTask Result Reporting " + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } }
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); } }
static void MThread() { do { using (SQLLib sql = SQLTest.ConnectSQL("Fox SDC Server for Maintenance", 0)) { if (sql == null) { Pause(); if (StopThread == true) { break; } } try { if (SettingsManager.Settings.KeepEventLogDays > 0) { DateTime now = DateTime.UtcNow; Int64 res = Convert.ToInt64(sql.ExecSQLScalar(@"DECLARE @Deleted_Rows INT DECLARE @Deleted_Rows_Total INT SET @Deleted_Rows = 1 SET @Deleted_Rows_Total = 0 WHILE (@Deleted_Rows > 0) BEGIN delete top (10000) from EventLog where TimeGenerated<DATEADD(day, @d, getutcdate()) SET @Deleted_Rows = @@ROWCOUNT SET @Deleted_Rows_Total = @Deleted_Rows_Total + @Deleted_Rows END Select @Deleted_Rows_Total", new SQLParam("@d", 0 - SettingsManager.Settings.KeepEventLogDays))); Int64 secs = Convert.ToInt64((DateTime.UtcNow - now).TotalSeconds); FoxEventLog.WriteEventLog("Eventlog data Maintenance completed: " + res.ToString() + " entr" + (res == 1 ? "y" : "ies") + " deleted\nTime needed: " + secs + " second" + (secs == 1 ? "" : "s"), System.Diagnostics.EventLogEntryType.Information); } if (SettingsManager.Settings.KeepNonPresentDisks > 0) { DateTime now = DateTime.UtcNow; int res = sql.ExecSQLNQ("delete from DiskData where DevicePresent!=1 AND LastUpdated<DATEADD(day, @d, getutcdate())", new SQLParam("@d", 0 - SettingsManager.Settings.KeepNonPresentDisks)); Int64 secs = Convert.ToInt64((DateTime.UtcNow - now).TotalSeconds); FoxEventLog.WriteEventLog("Nonpresent disk data Maintenance completed: " + res.ToString() + " entr" + (res == 1 ? "y" : "ies") + " deleted\nTime needed: " + secs + " second" + (secs == 1 ? "" : "s"), System.Diagnostics.EventLogEntryType.Information); } if (SettingsManager.Settings.KeepReports > 0) { DateTime now = DateTime.UtcNow; int res = sql.ExecSQLNQ("delete from Reporting where Reported<DATEADD(day, @d, getutcdate())", new SQLParam("@d", 0 - SettingsManager.Settings.KeepReports)); Int64 secs = Convert.ToInt64((DateTime.UtcNow - now).TotalSeconds); FoxEventLog.WriteEventLog("Report Maintenance completed: " + res.ToString() + " entr" + (res == 1 ? "y" : "ies") + " deleted\nTime needed: " + secs + " second" + (secs == 1 ? "" : "s"), System.Diagnostics.EventLogEntryType.Information); } if (SettingsManager.Settings.KeepBitlockerRK > 0) { DateTime now = DateTime.UtcNow; int res = sql.ExecSQLNQ("delete from BitlockerRK where Reported<DATEADD(day, @d, getutcdate())", new SQLParam("@d", 0 - SettingsManager.Settings.KeepBitlockerRK)); Int64 secs = Convert.ToInt64((DateTime.UtcNow - now).TotalSeconds); FoxEventLog.WriteEventLog("Old BitlockerRK Maintenance completed: " + res.ToString() + " entr" + (res == 1 ? "y" : "ies") + " deleted\nTime needed: " + secs + " second" + (secs == 1 ? "" : "s"), System.Diagnostics.EventLogEntryType.Information); } if (SettingsManager.Settings.KeepChatLogs > 0) { DateTime now = DateTime.UtcNow; int res = sql.ExecSQLNQ("delete from Chats where DT<DATEADD(day, @d, getutcdate())", new SQLParam("@d", 0 - SettingsManager.Settings.KeepChatLogs)); Int64 secs = Convert.ToInt64((DateTime.UtcNow - now).TotalSeconds); FoxEventLog.WriteEventLog("Old Chat Logs Maintenance completed: " + res.ToString() + " entr" + (res == 1 ? "y" : "ies") + " deleted\nTime needed: " + secs + " second" + (secs == 1 ? "" : "s"), System.Diagnostics.EventLogEntryType.Information); } } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot delete Eventlog data\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } sql.CloseConnection(); } Pause(); if (StopThread == true) { break; } } while (StopThread == false); }
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); } }