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