/// <summary> /// This function is responsible for the actual generation of the Applications Report /// It overrides the abstract definition in the base class and stores it's data in the DataSet /// </summary> public override void GenerateReport(UltraGrid grid) { // Delete any cached data as we are re-running the report _cachedAssetGroups = null; // Begin initialization of the Grid grid.BeginUpdate(); // Save the grid layout to a temporary file if (grid.Rows.Count != 0) { SaveTemporaryLayout(grid); } // Create a new dataSource _reportDataSet = new DataSet("auditdataDataSet"); grid.DataSource = _reportDataSet; // We will always need the list of assets so we may as well get it now LocationsDAO lwDataAccess = new LocationsDAO(); AssetGroup.GROUPTYPE displayType = AssetGroup.GROUPTYPE.userlocation; DataTable table = lwDataAccess.GetGroups(new AssetGroup(displayType)); _cachedAssetGroups = new AssetGroup(table.Rows[0], displayType); _cachedAssetGroups.Populate(true, _ignoreChildAssets, true); // Now apply the filter to these groups _cachedAssetGroups.ApplyFilters(_selectedGroups, _selectedAssets, _ignoreChildAssets); // Now that we have a definitive list of the assets (as objects) which we want to include in the // report we could really do with expanding this list so that ALL of the assets are in a single list // and not distributed among the publishers _cachedAssetList = _cachedAssetGroups.GetAllAssets(); // Create the list of report columns which will maintain the data for this report _auditDataReportColumns.Populate(_listSelectedFields , _dictionaryLabels , _publisherFilter , _showIncluded , _showIgnored); // Create the tables, columns and relationships as these may have changed since we loaded the report CreateTables(); // Clear any existing data out of the dataset _reportDataSet.Tables["AuditData"].Rows.Clear(); // Generate the data for the report GenerateReportData(); // reload the temprary layout saved around the report generation //LoadTemporaryLayout(grid); // ...and perform any required initialization of the grid InitializeGrid(grid); grid.EndUpdate(); }
/// <summary> /// This function is responsible for generating the actual data which will be displayed by the report /// </summary> protected void GenerateReportData() { // Create a string representation of the publisher filter list passed to us // We need to get the entire licensing information at this point AssetGroup.GROUPTYPE displayType = AssetGroup.GROUPTYPE.userlocation; DataTable table = new LocationsDAO().GetGroups(new AssetGroup(displayType)); AssetGroup _cachedAssetGroups = new AssetGroup(table.Rows[0], displayType); _cachedAssetGroups.Populate(true, _ignoreChildAssets, true); // Now apply the filter to these groups _cachedAssetGroups.ApplyFilters(_selectedGroups, _selectedAssets, _ignoreChildAssets); // Now that we have a definitive list of the assets (as objects) which we want to include in the // report we could really do with expanding this list so that ALL of the assets are in a single list // and not distributed among the publishers AssetList _cachedAssetList = _cachedAssetGroups.GetAllAssets(); _selectedAssets = String.Empty; foreach (Asset asset in _cachedAssetList) { _selectedAssets += asset.Name + ";"; } char[] charsToTrim = { ';' }; _selectedAssets.TrimEnd(charsToTrim); ResetSelectedAssets(); // OK different reports require different processing so branch here switch (_subtype) { case eHistoryType.changesbetween: GenerateChangesBetweenReportData(); break; case eHistoryType.hasbeenaudited: GenerateLastAuditDateReportData(true); break; case eHistoryType.hasnotbeenaudited: GenerateLastAuditDateReportData(false); break; case eHistoryType.lastaudit: GenerateLastAuditDateReportData(true); break; case eHistoryType.mostrecentchanges: GenerateMostRecentReportData(); break; } }
private void UpdateInteractiveLocations() { auditScannerDefinition.InteractiveLocations.Clear(); DataTable table = new LocationsDAO().GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.userlocation)); AssetGroup rootLocation = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.userlocation); // Populate all levels for this user location rootLocation.Populate(true, false, true); auditScannerDefinition.RootLocation = rootLocation.Name; foreach (AssetGroup childLocation in rootLocation.Groups) { childLocation.Assets.Clear(); auditScannerDefinition.InteractiveLocations.Add(childLocation); SaveInteractiveLocation(childLocation); } }
/// <summary> /// this is the main display function called to display expanded information pertaining to the specified /// group. We need to display the sub-groups and assets within this group /// </summary> /// <param name="group"></param> public void Show(AssetGroup group) { _currentGroup = group; // get our controller and from there the current display moderators NetworkWorkItemController wiController = tabView.WorkItem.Controller as NetworkWorkItemController; // Populate this group if not done so already if (!group.Populated) { group.Populate(false, false, true); } // Initialize the tab view InitializeTabView(); // ...and add in the child groups and children tabView.DisplayGroup(group); }
/// <summary> /// generate the most recent history records for each asset /// </summary> protected void GenerateMostRecentReportData() { // Get a complete list of groups and assets and then apply our filters to this list LocationsDAO lwDataAccess = new LocationsDAO(); AssetGroup.GROUPTYPE displayType = AssetGroup.GROUPTYPE.userlocation; DataTable table = lwDataAccess.GetGroups(new AssetGroup(displayType)); AssetGroup assetGroups = new AssetGroup(table.Rows[0], displayType); assetGroups.Populate(true, false, true); // Now apply the filter to these groups assetGroups.ApplyFilters(_selectedGroups, _selectedAssets, _ignoreChildAssets); // Now that we have a definitive list of the assets (as objects) which we want to include in the // report we could really do with expanding this list so that ALL of the assets are in a single list // and not distributed among the publishers AssetList listAssets = assetGroups.GetAllAssets(); // OK - get the last audit trail records for these assets - the last audit date is stored in the // Asset object so we don't need to get that again foreach (Asset asset in listAssets) { // Skip any assets not audited yet if (asset.LastAudit.Ticks == 0) { continue; } // Get the audit trail records for this asset DataTable historyTable = new AuditTrailDAO().GetAssetAuditHistory(asset, asset.LastAudit, DateTime.Now); // Add the entries in the data table as ATE records to our DataSet foreach (DataRow row in historyTable.Rows) { AuditTrailEntry ate = new AuditTrailEntry(row); AddChangesRecord(ate); } } }
public void NetworkDiscoveryCompleteHandler(object sender, DataEventArgs <List <string[]> > e) { try { LocationsDAO lwDataAccess = new LocationsDAO(); string macAddress = String.Empty; string vendor = String.Empty; string ipAddress = String.Empty; // We need to get the root item as all of the domains need to be parented to this DataTable table = lwDataAccess.GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.domain)); AssetGroup rootGroup = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.domain); // Get the child domains - as domains are single level we do not need to recurse rootGroup.Populate(false, false, true); // We'll loop through the domains first and add then to the database recovering their ids so that // we only have to do this once. for (int i = 0; i < e.Data.Count; i++) { string assetName = e.Data[i][0]; string groupName = e.Data[i][1]; // Does this domain already exist? AssetGroup childGroup = rootGroup.IsChildGroup(groupName); // No - add it as a new group both to the database and to the parent if (childGroup == null) { childGroup = new AssetGroup(AssetGroup.GROUPTYPE.domain); childGroup.Name = groupName; childGroup.ParentID = rootGroup.GroupID; childGroup.GroupID = lwDataAccess.GroupAdd(childGroup); rootGroup.Groups.Add(childGroup); } try { // Recover the IP address for the asset ipAddress = Utility.GetIpAddress(assetName); // try to get the MAC address and vendor from IP IPAddress hostIPAddress = IPAddress.Parse(ipAddress); byte[] ab = new byte[6]; int len = ab.Length; int r = SendARP((int)hostIPAddress.Address, 0, ab, ref len); macAddress = BitConverter.ToString(ab, 0, 6); } catch (Exception ex) { // if we hit an invalid IP error here we can just log and carry on log.Error(String.Format("Error {0} with IP address [{1}]", ex.Message, ipAddress)); } if (macAddress != String.Empty) { using (System.IO.StreamReader sr = new System.IO.StreamReader(System.IO.Path.Combine(Application.StartupPath, "oui.txt"))) { string line; while ((line = sr.ReadLine()) != null) { if (line.StartsWith(macAddress.Substring(0, 8))) { if (line.Substring(18).ToUpper().StartsWith("APPLE")) { vendor = line.Substring(18); } break; } } } } // Now that we have the ID of the group (even if we just added the group) we can now // add the asset to the database also. Asset newAsset = new Asset(); newAsset.Name = assetName; newAsset.MACAddress = macAddress.Replace('-', ':'); newAsset.Make = vendor; AssetList assetList = new AssetList(new AssetDAO().GetAssets(0, AssetGroup.GROUPTYPE.userlocation, false), true); bool bUpdateAsset = true; foreach (Asset existingAsset in assetList) { if (assetName == existingAsset.Name) { // this asset already exists - only need to check if domain or IP have changed // if they have, send it away to be updated if (existingAsset.IPAddress != ipAddress || existingAsset.DomainID != childGroup.GroupID) { newAsset = existingAsset; newAsset.IPAddress = newAsset.IPAddress != ipAddress ? ipAddress : newAsset.IPAddress; newAsset.DomainID = newAsset.DomainID != childGroup.GroupID ? childGroup.GroupID : newAsset.DomainID; } else { // asset exists, nothing has changed so don't process bUpdateAsset = false; } break; } } if (bUpdateAsset) { newAsset.DomainID = childGroup.GroupID; newAsset.IPAddress = ipAddress; // Add the asset newAsset.Add(); } // Does this asset already exist? //if (rootGroup.FindAsset(assetName) == null) //{ // newAsset.DomainID = childGroup.GroupID; // newAsset.IPAddress = ipAddress; // // Add the asset // newAsset.Add(); //} } } catch (Exception ex) { logger.Error(ex.Message); } //WorkItem.ExplorerView.RefreshView(); //WorkItem.TabView.RefreshView(); }
public void InsertComputer(string assetName, string groupName, string ipAddress, string macAddress) { LocationsDAO lwDataAccess = new LocationsDAO(); SettingsDAO lSettingsDao = new SettingsDAO(); // We need to get the root item as all of the domains need to be parented to this System.Data.DataTable table = lwDataAccess.GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.domain)); AssetGroup rootGroup = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.domain); // Get the child domains - as domains are single level we do not need to recurse rootGroup.Populate(false, false, true); // We'll loop through the domains first and add then to the database recovering their ids so that // we only have to do this once. // Does this domain already exist? AssetGroup childGroup; lock (this) { childGroup = rootGroup.IsChildGroup(groupName); // No - add it as a new group both to the database and to the parent if (childGroup == null) { childGroup = new AssetGroup(AssetGroup.GROUPTYPE.domain); childGroup.Name = groupName; childGroup.ParentID = rootGroup.GroupID; childGroup.GroupID = lwDataAccess.GroupAdd(childGroup); rootGroup.Groups.Add(childGroup); } } string vendor = String.Empty; try { if (macAddress != String.Empty) { // // CMD IMPORTANT UNCOMMENT THESE LINES // using (System.IO.StreamReader sr = new System.IO.StreamReader(System.IO.Path.Combine(Application.StartupPath, "oui.txt"))) // { // string line; // while ((line = sr.ReadLine()) != null) // { // if (line.StartsWith(macAddress.Substring(0, 8))) // { // if (line.Substring(18).ToUpper().StartsWith("APPLE")) // { // vendor = line.Substring(18); // break; // } // } // } // } } } catch (FormatException) { } // Now that we have the ID of the group (even if we just added the group) we can now // add the asset to the database also. Asset newAsset = new Asset(); newAsset.Name = assetName; newAsset.MACAddress = macAddress.Replace('-', ':'); newAsset.Make = vendor; if (vendor.ToUpper().StartsWith("APPLE")) { // add as an Apple Device assetTypes.Populate(); AssetType parentAssetType = assetTypes.FindByName("Apple Devices"); if (parentAssetType == null) { // Now create a child of this asset type parentAssetType = new AssetType(); parentAssetType.Name = "Apple Devices"; parentAssetType.Auditable = false; parentAssetType.Icon = "apple.png"; parentAssetType.ParentID = 0; parentAssetType.Add(); // Update the internal list assetTypes.Add(parentAssetType); } assetTypes.Populate(); parentAssetType = assetTypes.FindByName("Apple Devices"); AssetType childAssetType = assetTypes.FindByName("Apple Device"); if (childAssetType == null) { // Now create a child of this asset type childAssetType = new AssetType(); childAssetType.Name = "Apple Device"; childAssetType.Auditable = false; childAssetType.Icon = parentAssetType.Icon; childAssetType.ParentID = parentAssetType.AssetTypeID; childAssetType.Add(); // Update the internal list assetTypes.Add(childAssetType); } assetTypes.Populate(); childAssetType = assetTypes.FindByName("Apple Device"); newAsset.AssetTypeID = childAssetType.AssetTypeID; } AssetList assetList = new AssetList(new AssetDAO().GetAssets(0, AssetGroup.GROUPTYPE.userlocation, false), true); bool bUpdateAsset = true; bool bSNMPAsset = false; bool bExistingAuditedAsset = false; foreach (Asset existingAsset in assetList) { if ((existingAsset.AgentVersion == "SNMP") && (existingAsset.IPAddress == ipAddress)) { bSNMPAsset = true; break; } if ((assetName == existingAsset.Name) && (groupName == existingAsset.Domain)) { // this asset already exists - only need to check if domain or IP have changed // if they have, send it away to be updated if (existingAsset.IPAddress != ipAddress || existingAsset.DomainID != childGroup.GroupID) { newAsset = existingAsset; newAsset.IPAddress = newAsset.IPAddress != ipAddress ? ipAddress : newAsset.IPAddress; newAsset.DomainID = newAsset.DomainID != childGroup.GroupID ? childGroup.GroupID : newAsset.DomainID; } else { // asset exists, nothing has changed so don't process bUpdateAsset = false; } break; } if (!bSNMPAsset && existingAsset.IPAddress == ipAddress && existingAsset.Domain != newAsset.Domain) { bExistingAuditedAsset = true; //check for any asset name change if so update asset with audittrail entry if (existingAsset.Name != assetName) { string strOldValue = existingAsset.Name; newAsset = existingAsset; newAsset.Name = assetName; newAsset.Update(); AuditTrailDAO objAuditTrailDAO = new AuditTrailDAO(); // Build a blank AuditTrailEntry AuditTrailEntry ate = CreateAteForAssetNameChange(newAsset); ate.Key = ate.Key + "|" + "Computer Name"; ate.OldValue = strOldValue; ate.NewValue = assetName; objAuditTrailDAO.AuditTrailAdd(ate); } } } if (bUpdateAsset && !bSNMPAsset && !bExistingAuditedAsset) { newAsset.Domain = childGroup.Name; newAsset.DomainID = childGroup.GroupID; newAsset.IPAddress = ipAddress; // Add the asset newAsset.Add(); if (lSettingsDao.GetSettingAsBoolean("AutoScanNetwork", false) && lSettingsDao.GetSettingAsBoolean("AutoScanDeployAgent", false)) { string scannerPath = System.IO.Path.Combine(Application.StartupPath, "scanners") + "\\auditagent\\default.xml"; System.IO.File.Copy(scannerPath, "AuditAgent\\AuditAgent.xml", true); Operation newOperation = new Operation(newAsset.AssetID, Operation.OPERATION.deployagent); newOperation.Add(); } } if (!bSNMPAsset) { Interlocked.Increment(ref _foundCounter); FireNetworkDiscoveryUpdate(new DiscoveryUpdateEventArgs(_foundCounter.ToString(), "Computer", _maximumCount, 0)); } }