Beispiel #1
0
        private void GenerateDataSet()
        {
            string query = string.Empty;
            string machineIDFilter = string.Empty;
            string scanIDFilter = string.Empty;
            char[] sep = { '|' };
            EntityDb entityDb = new EntityDb();

            foreach (TreeNode nodeMachines in lstMachines.Nodes)
            {
                if (lstMachines.GetChecked(nodeMachines) == TriStateTreeView.CheckState.Checked ||
                    lstMachines.GetChecked(nodeMachines) == TriStateTreeView.CheckState.GreyChecked)
                {

                    foreach (TreeNode mach in nodeMachines.Nodes)
                    {
                        //if ( mach.Checked == true )
                        if (lstMachines.GetChecked(mach) ==
                           TriStateTreeView.CheckState.Checked || lstMachines.GetChecked(mach) ==
                           TriStateTreeView.CheckState.GreyChecked)
                        {
                            string tagtext = (string)mach.Tag;
                            string[] values = tagtext.Split(sep);

                            machineIDFilter = machineIDFilter + values[0] + ",";
                            scanIDFilter = scanIDFilter + values[1] + ",";

                        }
                    }
                }

            }
            machineIDFilter = machineIDFilter.TrimEnd(',', ' ');
            scanIDFilter = scanIDFilter.TrimEnd(',', ' ');

            if ( scanIDFilter == "")
            {

                return;
            }

            query = @"SELECT MachineName, MAX(ScanID) AS ScanID
                    FROM (SELECT Discover.MachineName, Scan.ScanID
                    FROM Discover INNER JOIN Scan ON
                    Discover.MachineID = Scan.MachineID
                    WHERE (Discover.MachineID IN (" + machineIDFilter+ "))) AS derivedtbl_1 GROUP BY MachineName";

            DataTable dtMachine = new DataTable();
            entityDb.RunQueryTable(query, ref dtMachine);

            if (dtMachine.Rows.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                switch (rptType)
                {
                    case ReportsType.OSInstall:
                        {
                            DataTable dtResult = new DataTable();

                            sb.AppendFormat("SELECT [Name], COUNT(*) AS Count FROM [OS] where (ScanID in ({0})) GROUP BY Name ORDER BY Count DESC", scanIDFilter);
                            entityDb.RunQueryTable(sb.ToString(), ref dtResult);
                            dtResult.TableName = "OS_Set";
                            dsResults.Tables.Add(dtResult);
                        }
                        break;
                    case ReportsType.LowDiskPercent:
                        {
                            DataTable dtResult = new DataTable();

                            dtMachine.TableName = "Machines";
                            dsResults.Tables.Add(dtMachine);
                            sb.AppendFormat("SELECT * FROM [LogicalDrive] WHERE (PercentageFreeSpace < {0}  AND Description LIKE '%Fixed%') and (ScanID in ({1}))", diskUsagePerc, scanIDFilter);

                            entityDb.RunQueryTable(sb.ToString(), ref dtResult);
                            dtResult.TableName = "LowDisk";
                            dsResults.Tables.Add(dtResult);

                            string tmpRelationName = "FK_SCAN_LOWDISK";
                            DataRelation relation1 = new DataRelation(
                                tmpRelationName,
                                dtMachine.Columns["ScanID"],
                                dtResult.Columns["ScanID"]);

                            dsResults.Relations.Add(relation1);
                            relation1.Nested = true;

                        }
                        break;
                    case ReportsType.DiskUtilization:
                        {
                            DataTable dtResult1 = new DataTable();

                            dtMachine.TableName = "Machines";
                            dsResults.Tables.Add(dtMachine);
                            sb.AppendFormat("SELECT * FROM [LogicalDrive] WHERE (Description LIKE '%Fixed%' and ScanID in ({1}))", diskUsagePerc, scanIDFilter);

                            entityDb.RunQueryTable(sb.ToString(), ref dtResult1);
                            dtResult1.TableName = "LogicalDrive";
                            dsResults.Tables.Add(dtResult1);

                            string tmpRelationName = "FK_SCAN_LOGICALDRIVE";
                            DataRelation relation = new DataRelation(
                                tmpRelationName,
                                dtMachine.Columns["ScanID"],
                                dtResult1.Columns["ScanID"]);

                            dsResults.Relations.Add(relation);
                            relation.Nested = true;

                            DataTable dtResult2 = new DataTable();

                            if(sb.Length>0)
                            {
                                sb.Remove(0, sb.Length);
                            }

                            sb.AppendFormat("SELECT * FROM [Disk] WHERE (ScanID in ({0}))", scanIDFilter);

                            entityDb.RunQueryTable(sb.ToString(), ref dtResult2);
                            dtResult2.TableName = "Disk";
                            dsResults.Tables.Add(dtResult2);

                            tmpRelationName = "FK_SCAN_DISK";
                            relation = new DataRelation(
                                tmpRelationName,
                                dtMachine.Columns["ScanID"],
                                dtResult2.Columns["ScanID"]);

                            dsResults.Relations.Add(relation);
                            relation.Nested = true;

                        }
                        break;

                    case ReportsType.HardwareComponents:
                        {
                            string []components = {"Bios", "CDRom", "Disk", "Memory", "NetworkAdapter", "Monitor", "Motherboard", "Printer", "Processor"};

                            dtMachine.TableName = "Machines";
                            dsResults.Tables.Add(dtMachine);

                            foreach (string component in components)
                            {
                                DataTable dtResult = new DataTable();

                                if (sb.Length > 0)
                                {
                                    sb.Remove(0, sb.Length);
                                }

                                sb.AppendFormat("SELECT * FROM [{0}] WHERE (ScanID in ({1}))", component, scanIDFilter);

                                entityDb.RunQueryTable(sb.ToString(), ref dtResult);
                                dtResult.TableName = component;
                                dsResults.Tables.Add(dtResult);

                                string tmpRelationName = "FK_SCAN_"+component;
                                DataRelation relation = new DataRelation(
                                    tmpRelationName,
                                    dtMachine.Columns["ScanID"],
                                    dtResult.Columns["ScanID"]);

                                dsResults.Relations.Add(relation);
                                relation.Nested = true;
                            }
                        }
                        break;

                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Thread function to collect wmi data
        /// </summary>
        /// <param name="param">receives the machine name or ip for data collecton</param>
        private void CollectWMIData(object param)
        {
            string hostname = (string)param;
            _logger.Info("wmi data collection started for machine " +hostname);
            DiscoverDb _disDb = new DiscoverDb();
            EntDiscover machinedetails = _disDb.GetMachineDetails(hostname);

            CredentialDB _credDb = new CredentialDB();
            EntCredential _cred = _credDb.GetCredential(machinedetails.CredentialID);
            _credDb.CloseConnection();
            _credDb = null;

            string _UserName = null;
            string _Password = null;

            if ( _cred != null)
            {
                _UserName = _cred.Username;
                _Password = _cred.Password;
            }

            FireStatusMessage(NAMString.ResourceFormatter.CONTROLLER_STATUS_MESSAGE_WMICOLLECT()+" "+hostname);
            WMIHandler objHandler = new WMIHandler(machinedetails.MachineName, _UserName, _Password);
            EntScan scan = new EntScan();

            if ( objHandler.IsWmiInitialized == true )
            {

                scan.MachineID = machinedetails.MachineID;

                ScanDb _scandb = new ScanDb();
                int scanID = _scandb.InsertScan(scan);
                _scandb.CloseConnection();
                _scandb = null;

                EntityDb entityDb = new EntityDb();

                FireStatusMessage(hostname+" : "+ NAMString.ResourceFormatter.CONTROLLER_STATUS_MESSAGE_PROCESSOR());

                foreach (EntProcessor pro in objHandler.GetProcessorDetails())
                {
                    pro.ScanID = scanID;
                    //procDb.InsertProcessor(pro);
                    entityDb.Insert(pro);
                }

               foreach (EntSoftwares lSoftware in objHandler.GetInstalledSoftwareDetails())
               {
                   lSoftware.ScanID = scanID;
                   entityDb.Insert(lSoftware);
               }

                entityDb.CloseConnection();
                entityDb = null;

                _disDb.UpdateLastScan(scan.MachineID, scan.Date);

                machinedetails.Discovered = true;
                machinedetails.StatusMessage = NAMString.ResourceFormatter.CONTROLLER_STATUS_MESSAGE_SCANCOMPLETE();

            }
            else
            {
                _logger.Error("WMI not initialized for machine <" + hostname+">");
                machinedetails.StatusMessage = "wmi initialization failure";
                machinedetails.Discovered = false;
            }

            machinedetails.LastChecked = DateTime.Now;
            _disDb.UpdateDiscover(machinedetails);

            if ( ScanComplete!=null)
            {
                ScanComplete(this, machinedetails.MachineName);
            }
            FireStatusMessage("Scan complete");
            _disDb.CloseConnection();
            _disDb = null;
        }
Beispiel #3
0
        private void GenerateDataSet()
        {
            string query = string.Empty;
            string machineIDFilter = string.Empty;
            string scanIDFilter = string.Empty;
            char[] sep = { '|' };
            EntityDb entityDb = new EntityDb();

            foreach (TreeNode nodeMachines in lstMachines.Nodes)
            {
                if (lstMachines.GetChecked(nodeMachines) == TriStateTreeView.CheckState.Checked ||
                    lstMachines.GetChecked(nodeMachines) == TriStateTreeView.CheckState.GreyChecked)
                {

                    foreach (TreeNode mach in nodeMachines.Nodes)
                    {

                        if (lstEntity.GetChecked(mach) == TriStateTreeView.CheckState.Checked)
                        {
                            string tagtext = (string)mach.Tag;
                            string[] values = tagtext.Split(sep);

                            machineIDFilter = machineIDFilter + values[0] + ",";
                            scanIDFilter = scanIDFilter + values[1] + ",";
                        }
                    }
                }

            }
            machineIDFilter = machineIDFilter.TrimEnd(',', ' ');
            scanIDFilter = scanIDFilter.TrimEnd(',', ' ');

            if ( scanIDFilter == "")
            {
                return;
            }

            query = @"SELECT MachineName, MAX(ScanID) AS ScanID
                                FROM (SELECT Discover.MachineName, Scan.ScanID
                                FROM Discover INNER JOIN Scan ON
                                Discover.MachineID = Scan.MachineID
                                WHERE (Discover.MachineID IN (" + machineIDFilter+ "))) AS derivedtbl_1 GROUP BY MachineName";

            //SqlCeDataAdapter dataAdapter = new SqlCeDataAdapter(query, _connection);
            DataTable dtMachine = new DataTable();
            entityDb.RunQueryTable(query, ref dtMachine);

            if ( dtMachine.Rows.Count> 0)
            {
                dtMachine.TableName = "Machines";
                dsResults.Tables.Add(dtMachine);

                foreach (TreeNode node in lstEntity.Nodes)
                {
                    if (lstEntity.GetChecked(node) ==
                           TriStateTreeView.CheckState.Checked || lstEntity.GetChecked(node) ==
                           TriStateTreeView.CheckState.GreyChecked)
                    {
                        DataTable dtResult = new DataTable();
                        string temp = string.Empty;

                        StringBuilder sb = new StringBuilder();

                        sb.AppendFormat("SELECT ScanID, ");
                        foreach (TreeNode items in node.Nodes)
                        {
                            if (lstEntity.GetChecked(items) == TriStateTreeView.CheckState.Checked ||
                                lstEntity.GetChecked(items) == TriStateTreeView.CheckState.GreyChecked)
                            {
                                temp = items.Text;
                                temp = temp.Replace(" ", "");
                                sb.AppendFormat("{0}, ", temp);
                            }
                        }
                        sb.Remove(sb.Length - 2, 1);
                        sb.AppendFormat("FROM [{0}] where ScanID in ({1})", node.Text, scanIDFilter);

                        entityDb.RunQueryTable(sb.ToString(), ref dtResult);
                        dtResult.TableName = node.Text;
                        dsResults.Tables.Add(dtResult);

                        string tmpRelationName = "FK_SCAN_" + node.Text;
                        DataRelation relation1 = new DataRelation(
                            tmpRelationName,
                            dtMachine.Columns["ScanID"],
                            dtResult.Columns["ScanID"]);

                        dsResults.Relations.Add(relation1);
                        relation1.Nested = true;
                    }
                }
            }
        }
Beispiel #4
0
        //TODO_HIGH : return the collection of the objects to the UI
        public int GetWmiDataFromDB(string machineName, DateTime scanDate, ref Hashtable objDataTable)
        {
            //TODO_NORM: Improve the code below so db handling is proper.
            DiscoverDb discDb = new DiscoverDb();
            EntDiscover machineDetails = discDb.GetMachineDetails(machineName);
            discDb.CloseConnection();
            discDb = null;

            //TODO_HIGH: Code only displays the latest, should display scan selected using combobox
            ScanDb _scanDb = new ScanDb();
            EntScan scan = _scanDb.GetLatestScanDetails(machineDetails.MachineID, scanDate);
            _scanDb.CloseConnection();
            _scanDb = null;

            if ( scan != null)
            {
                EntityDb entityDb = new EntityDb();

                ArrayList sysData = new ArrayList();
                ArrayList.Synchronized(sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Computer, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Processor, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.OS, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Bios, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.MotherBoard, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Disk, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Memory, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.LogicalDrive, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.CDRom, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.NetworkAdapter, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Video, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Multimedia, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Monitor, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Share, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Printer, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.Hotfix, ref sysData);
                entityDb.GetEntity(scan.ScanID, EntityType.StartUp, ref sysData);

                objDataTable.Add("System", sysData);

                ArrayList processData = new ArrayList();
                ArrayList.Synchronized(processData);
                entityDb.GetEntity(scan.ScanID, EntityType.Processes, ref processData);
                objDataTable.Add("Processes", processData);

                ArrayList softwareData = new ArrayList();
                ArrayList.Synchronized(softwareData);
                entityDb.GetEntity(scan.ScanID, EntityType.Softwares, ref softwareData);
                objDataTable.Add("Softwares", softwareData);

                ArrayList servicesData = new ArrayList();
                ArrayList.Synchronized(servicesData);
                entityDb.GetEntity(scan.ScanID, EntityType.Services, ref servicesData);
                objDataTable.Add("Services", servicesData);

                ArrayList ipRoutesData = new ArrayList();
                ArrayList.Synchronized(ipRoutesData);
                entityDb.GetEntity(scan.ScanID, EntityType.IPRoutes, ref ipRoutesData);
                objDataTable.Add("IPRoutes", ipRoutesData);

                ArrayList ipEnvVars = new ArrayList();
                ArrayList.Synchronized(ipEnvVars);
                entityDb.GetEntity(scan.ScanID, EntityType.EnvironmentVar, ref ipEnvVars);
                objDataTable.Add("EnvVars", ipEnvVars);

                ArrayList userGrps = new ArrayList();
                ArrayList.Synchronized(userGrps);
                entityDb.GetEntity(scan.ScanID, EntityType.UserGroup, ref userGrps);
                objDataTable.Add("UserGroups", userGrps);

                entityDb.CloseConnection();
                entityDb = null;
            }

            return 1;
        }