/// <summary>
        /// Get Oracle Version
        /// </summary>
        /// <param name="OracleHome">Oracle Home</param>
        /// <param name="version">Version</param>
        /// <returns></returns>
        private ResultCodes GetOracleServerEdition(string OracleHome, out string edition)
        {
            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                  0,
                                  "Task Id {0}: Attempting to retrieve config file from OracleHome: {1}.",
                                  m_taskId,
                                  OracleHome);
            StringBuilder fileContent        = new StringBuilder();
            string        contentXMLFilePath = string.Empty;

            edition = @"";
            if (OracleHome.EndsWith(@"\"))
            {
                contentXMLFilePath = OracleHome + @"inventory\ContentsXML\comps.xml";
            }
            else
            {
                contentXMLFilePath = OracleHome + @"\inventory\ContentsXML\comps.xml";
            }

            if (Lib.ValidateFile(m_taskId, contentXMLFilePath, m_cimvScope))
            {
                using (IRemoteProcess rp =
                           RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, contentXMLFilePath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) {
                    //
                    // Launch the remote process.
                    // This method will block until the entire remote process operation completes.
                    resultCode = rp.Launch();
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Remote file retrieval operation completed with result code {1}.",
                                          m_taskId,
                                          resultCode.ToString());
                    fileContent.Append(rp.Stdout);
                }
                // Parse config file content
                edition = parseContentXMLFile(fileContent.ToString());
            }
            else
            {
                Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                      0,
                                      "Task Id {0}: Oracle Server Config file: {1} does not exist.",
                                      m_taskId,
                                      contentXMLFilePath);
                // Some Oracle Administrator might have corrupted config file or registry settings.
                // In order not to confuse scan result with actual error, return RC_SUCCESS instead.
                resultCode = ResultCodes.RC_SUCCESS;
            }
            return(resultCode);
        }
예제 #2
0
        /// <summary>
        /// Collect usage statistics from agent.
        /// </summary>
        /// <param name="cimvScope">WMI connection.</param>
        /// <returns>Operation result code.</returns>
        private ResultCodes GetUsageStatistics(ManagementScope cimvScope)
        {
            Lib.Logger.TraceEvent(TraceEventType.Error,
                                  0,
                                  "Task Id {0}: Attempting to get usage statistics",
                                  m_taskId);
            ResultCodes resultCode = ResultCodes.RC_PROCESSING_EXCEPTION;

            if (String.IsNullOrEmpty(m_serviceDataPath))
            {
                return(resultCode);
            }

            String        resultPath  = m_serviceDataPath + "result.cvs";
            StringBuilder fileContent = new StringBuilder();

            if (Lib.ValidateFile(m_taskId, resultPath, cimvScope))
            {
                using (IRemoteProcess rp =
                           RemoteProcess.GetRemoteFile(m_taskId, cimvScope, resultPath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher))
                {
                    // Launch the remote process.
                    // This method will block until the entire remote process operation completes.
                    resultCode = rp.Launch();
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Remote file retrieval operation completed with result code {1}.",
                                          m_taskId,
                                          resultCode.ToString());
                    fileContent.Append(rp.Stdout);
                }
                string[] lines = fileContent.ToString().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                m_resultFileContents = String.Join(BdnaDelimiters.DELIMITER_TAG, lines);

                resultCode = ResultCodes.RC_SUCCESS;
            }

            return(resultCode);
        }
예제 #3
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        ///
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(
            long taskId,
            long cleId,
            long elementId,
            long databaseTimestamp,
            long localTimestamp,
            IDictionary <string, string> attributes,
            IDictionary <string, string> scriptParameters,
            IDictionary <string, object> connection,
            string tftpPath,
            string tftpPath_login,
            string tftpPath_password,
            ITftpDispatcher tftpDispatcher)
        {
            m_executionTimer    = Stopwatch.StartNew();
            m_taskId            = taskId.ToString();
            m_cleId             = cleId;
            m_elementId         = elementId;
            m_databaseTimestamp = databaseTimestamp;
            m_localTimestamp    = localTimestamp;
            m_attributes        = attributes;
            m_scriptParameters  = scriptParameters;

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASProfileFootprintScript.",
                                  m_taskId);
            try {
                ManagementScope cimvScope    = null;
                ManagementScope defaultScope = null;

                // Check ManagementScope CIMV
                if (null == connection)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to WindowsWASProfileFootprintScript is null.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey(@"cimv2"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for CIMV namespace is not present in connection object.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey(@"default"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for Default namespace is not present in connection object.",
                                          m_taskId);
                }
                else
                {
                    cimvScope    = connection[@"cimv2"] as ManagementScope;
                    defaultScope = connection[@"default"] as ManagementScope;

                    if (!cimvScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to CIMV namespace failed.",
                                              m_taskId);
                    }
                    else if (!defaultScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to Default namespace failed.",
                                              m_taskId);
                    }
                }

                //Check WAS Installation Path attribute
                if (resultCode.Equals(ResultCodes.RC_SUCCESS))
                {
                    if (scriptParameters.ContainsKey("profilePath"))
                    {
                        m_profileHome = scriptParameters[@"profilePath"];
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing parameter WAS Profile Path parameter.",
                                              m_taskId);
                    }
                }

                // Check Remote Process Temp Directory
                if (resultCode.Equals(ResultCodes.RC_SUCCESS))
                {
                    if (!connection.ContainsKey(@"TemporaryDirectory"))
                    {
                        connection[@"TemporaryDirectory"] = @"%TMP%";
                    }
                    else
                    {
                        if (!connection[@"TemporaryDirectory"].Equals(@"%TMP%"))
                        {
                            if (!Lib.ValidateDirectory(m_taskId, connection[@"TemporaryDirectory"].ToString(), cimvScope))
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Error,
                                                      0,
                                                      "Task Id {0}: Temporary directory {1} is not valid.",
                                                      m_taskId,
                                                      connection[@"TemporaryDirectory"].ToString());
                                resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;  //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST
                            }
                            else
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                      0,
                                                      "Task Id {0}: User specified temp directory has been validated.",
                                                      m_taskId);
                            }
                        }
                    }
                }

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Attempting to retrieve file {1}.",
                                          m_taskId,
                                          m_profileHome);
                    StringBuilder fileContent = new StringBuilder();
                    StringBuilder setupCmd    = new StringBuilder();
                    setupCmd.Append((string)m_profileHome).Append(@"\bin\setupCmdLine.bat");

                    if (Lib.ValidateFile(m_taskId, setupCmd.ToString(), cimvScope))
                    {
                        using (IRemoteProcess rp =
                                   RemoteProcess.GetRemoteFile(m_taskId, cimvScope, setupCmd.ToString(), connection, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher))
                        {
                            //
                            // Launch the remote process.
                            // This method will block until the entire remote process operation completes.
                            resultCode = rp.Launch();
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Remote file retrieval operation completed with result code {1}.",
                                                  m_taskId,
                                                  resultCode.ToString());
                            fileContent.Append(rp.Stdout);
                        }
                        // Parse file content
                        resultCode = parseCmdlineFile(fileContent.ToString());
                    }
                    else
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: WAS setupCmdline file: {1} does not exist.",
                                              m_taskId,
                                              m_profileHome);
                        resultCode = ResultCodes.RC_SUCCESS;
                    }
                }
            } catch (Exception ex) {
                Lib.LogException(m_taskId,
                                 m_executionTimer,
                                 "Unhandled exception in WindowsWASProfileFootprintScript",
                                 ex);
                resultCode = ResultCodes.RC_PROCESSING_EXCEPTION;
            }

            CollectionScriptResults result = new CollectionScriptResults(resultCode,
                                                                         0,
                                                                         null,
                                                                         null,
                                                                         null,
                                                                         false,
                                                                         m_dataRow.ToString());

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASProfileFootprintScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  result.ResultCode.ToString());
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        ///
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(
            long taskId,
            long cleId,
            long elementId,
            long databaseTimestamp,
            long localTimestamp,
            IDictionary <string, string> attributes,
            IDictionary <string, string> scriptParameters,
            IDictionary <string, object> connection,
            string tftpPath,
            string tftpPath_login,
            string tftpPath_password,
            ITftpDispatcher tftpDispatcher)
        {
            Stopwatch     executionTimer    = Stopwatch.StartNew();
            string        taskIdString      = taskId.ToString();
            StringBuilder dataRow           = new StringBuilder();
            StringBuilder parsedIniFileData = new StringBuilder();
            ResultCodes   resultCode        = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script CollectWindowsCPAINIFile.",
                                  taskIdString);

            Lib.Logger.TraceEvent(TraceEventType.Information, 0, "Task Id {0}: Hash Dump = {1}", taskIdString, scriptParameters.ToString());
            string        remoteFileName  = scriptParameters[@"CPAWindowsIniFilePath"];
            StringBuilder collectedCPAttr = new StringBuilder();
            string        logData         = null;

            Lib.Logger.TraceEvent(TraceEventType.Information,
                                  0,
                                  "Passed file name into the script : {0}",
                                  remoteFileName);

            Lib.Logger.TraceEvent(TraceEventType.Information,
                                  0,
                                  "Task Id {0}: Running TFTP to collect the contents of CPA INI file on a remote system",
                                  taskIdString);


            MemoryStream ms = new MemoryStream(4096);

            using (TraceListener tl = new TextWriterTraceListener(ms)) {
                tl.TraceOutputOptions = TraceOptions.DateTime | TraceOptions.ProcessId | TraceOptions.ThreadId;

                try {
                    Lib.Logger.Listeners.Add(tl);
                    //
                    // Create a remote process object to manage the
                    // transfer of the remote file contents to our
                    // script.
                    //
                    // Many of these values are passed to the script from
                    // WinCs to give the Remote Process library access to
                    // Facilities outside the script sandbox.  The script
                    // need not care what these values are, just pass them
                    // through.
                    //
                    // Wrap the RemoteProcess in a using clause so that resources
                    // are automatically released when the remote process
                    // operation completes.

                    ManagementScope cimvScope = connection[@"cimv2"] as ManagementScope;

                    if (!cimvScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to CIMV namespace failed",
                                              taskIdString);
                        return(new CollectionScriptResults(resultCode, 0, null, null, null, false, dataRow.ToString()));
                    }
                    connection[@"TemporaryDirectory"] = @"c:\";

                    // collect data from multiple files
                    if (remoteFileName.Contains(","))
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Information,
                                              0,
                                              "CPAIniFilePath has multiple INI files path (" + remoteFileName + ")",
                                              taskIdString);
                        string[] iniFiles = remoteFileName.Split(',');
                        for (int fileCount = 0; fileCount < iniFiles.Length; fileCount++)
                        {
                            String fileName = iniFiles[fileCount];
                            Lib.Logger.TraceEvent(TraceEventType.Information,
                                                  0,
                                                  "CPA file path is " + fileName,
                                                  taskIdString);
                            using (IRemoteProcess rp =
                                       RemoteProcess.GetRemoteFile(taskIdString, // Task Id to log against.
                                                                   cimvScope,    // WMI connection, passed to collection script from WinCs
                                                                   fileName,     // Name of remote file to retrieve.
                                                                   connection,   // credential hash passed to all collection/connection scripts
                                                                   tftpPath,
                                                                   tftpPath_login,
                                                                   tftpPath_password,
                                                                   tftpDispatcher)) { // TFTP listener, passed to script from WinCs
                                //
                                // Launch the remote process.  This method will
                                // block until the entire remote process operation
                                // completes.
                                ResultCodes rc = rp.Launch();

                                //
                                // Once you get control back, there are properties that
                                // can be checked to information about the outcome of the
                                // operation, obtain log data, and retrieve collection results.
                                Lib.Logger.TraceEvent(TraceEventType.Information,
                                                      0,
                                                      "Remote process operation completed with result code" + rc.ToString(),
                                                      taskIdString);

                                if (null != collectedCPAttr)
                                {
                                    collectedCPAttr.Append(rp.Stdout);
                                }
                            }
                        }
                        if (null != collectedCPAttr)
                        {
                            int MIN_SECTIONS = 1;
                            // string collectedCPAttr = sb.ToString();
                            // System.Console.WriteLine(collectedCPAttr);

                            string[] cpAttrSections = new Regex(@"\[").Split(collectedCPAttr.ToString());
                            // System.Console.WriteLine("{0} sections in text:", cpAttrSections.Length);
                            if (cpAttrSections.Length > 0)
                            {
                                for (int secCtr = 0; secCtr < cpAttrSections.Length; secCtr++)
                                {
                                    // System.Console.WriteLine("This Section");
                                    // System.Console.WriteLine(cpAttrSections[secCtr]);
                                    string[] secEntries = cpAttrSections[secCtr].Split('\n');
                                    if (secEntries.Length == 1)
                                    {
                                        continue;
                                    }


                                    for (int entryCtr = 0; entryCtr < secEntries.Length; entryCtr++)
                                    {
                                        string tEntry = secEntries[entryCtr].Trim();
                                        if (tEntry.Length > 0)
                                        {
                                            if (tEntry.EndsWith("]"))
                                            {
                                                if (secCtr > MIN_SECTIONS)
                                                {
                                                    parsedIniFileData.Append("<BDNA,>");
                                                }
                                                parsedIniFileData.Append("Section=");
                                                parsedIniFileData.Append(tEntry.TrimEnd(']'));
                                            }
                                            else
                                            {
                                                if (secEntries[entryCtr - 1].Trim().EndsWith("]"))
                                                {
                                                    parsedIniFileData.Append("<BDNA,1>");
                                                }
                                                else
                                                {
                                                    parsedIniFileData.Append("<BDNA,2>");
                                                }
                                                parsedIniFileData.Append(tEntry);
                                            }
                                        }
                                    }
                                }
                            }

                            Lib.Logger.TraceEvent(TraceEventType.Information,
                                                  0,
                                                  "Parsing Succeeded. Parsed INI File Data is : " + parsedIniFileData.ToString(),
                                                  parsedIniFileData.ToString());

                            if (ResultCodes.RC_SUCCESS == resultCode)
                            {
                                dataRow.Append(elementId).Append(',')
                                .Append(attributes[@"collectedCPAttr"])
                                .Append(',')
                                .Append(scriptParameters[@"CollectorId"]).Append(',')
                                .Append(taskId).Append(',')
                                .Append(databaseTimestamp + executionTimer.ElapsedMilliseconds)
                                .Append(',')
                                .Append(@"collectedCPAttr")
                                .Append(',')
                                .Append(BdnaDelimiters.BEGIN_TAG)
                                .Append(collectedCPAttr)
                                .Append(BdnaDelimiters.END_TAG);

                                dataRow.Append(elementId).Append(',')
                                .Append(attributes[@"parsedCPAttr"])
                                .Append(',')
                                .Append(scriptParameters[@"CollectorId"]).Append(',')
                                .Append(taskId).Append(',')
                                .Append(databaseTimestamp + executionTimer.ElapsedMilliseconds)
                                .Append(',')
                                .Append(@"parsedCPAttr")
                                .Append(',')
                                .Append(BdnaDelimiters.BEGIN_TAG)
                                .Append(parsedIniFileData)
                                .Append(BdnaDelimiters.END_TAG);
                            }
                        }
                    }
                    else
                    {
                        using (IRemoteProcess rp =
                                   RemoteProcess.GetRemoteFile(taskIdString,   // Task Id to log against.
                                                               cimvScope,      // WMI connection, passed to collection script from WinCs
                                                               remoteFileName, // Name of remote file to retrieve.
                                                               connection,     // credential hash passed to all collection/connection scripts
                                                               tftpPath,
                                                               tftpPath_login,
                                                               tftpPath_password,
                                                               tftpDispatcher)) {   // TFTP listener, passed to script from WinCs
                            //
                            // Launch the remote process.  This method will
                            // block until the entire remote process operation
                            // completes.
                            ResultCodes rc = rp.Launch();

                            //
                            // Once you get control back, there are properties that
                            // can be checked to information about the outcome of the
                            // operation, obtain log data, and retrieve collection results.
                            Lib.Logger.TraceEvent(TraceEventType.Information,
                                                  0,
                                                  "Remote process operation completed with result code" + rc.ToString(),
                                                  taskIdString);

                            if (null != collectedCPAttr)
                            {
                                collectedCPAttr.Append(rp.Stdout);
                                int MIN_SECTIONS = 1;
                                // string collectedCPAttr = sb.ToString();
                                // System.Console.WriteLine(collectedCPAttr);

                                string[] cpAttrSections = new Regex(@"\[").Split(collectedCPAttr.ToString());
                                // System.Console.WriteLine("{0} sections in text:", cpAttrSections.Length);
                                if (cpAttrSections.Length > 0)
                                {
                                    for (int secCtr = 0; secCtr < cpAttrSections.Length; secCtr++)
                                    {
                                        // System.Console.WriteLine("This Section");
                                        // System.Console.WriteLine(cpAttrSections[secCtr]);
                                        string[] secEntries = cpAttrSections[secCtr].Split('\n');
                                        if (secEntries.Length == 1)
                                        {
                                            continue;
                                        }


                                        for (int entryCtr = 0; entryCtr < secEntries.Length; entryCtr++)
                                        {
                                            string tEntry = secEntries[entryCtr].Trim();
                                            if (tEntry.Length > 0)
                                            {
                                                if (tEntry.EndsWith("]"))
                                                {
                                                    if (secCtr > MIN_SECTIONS)
                                                    {
                                                        parsedIniFileData.Append("<BDNA,>");
                                                    }
                                                    parsedIniFileData.Append("Section=");
                                                    parsedIniFileData.Append(tEntry.TrimEnd(']'));
                                                }
                                                else
                                                {
                                                    if (secEntries[entryCtr - 1].Trim().EndsWith("]"))
                                                    {
                                                        parsedIniFileData.Append("<BDNA,1>");
                                                    }
                                                    else
                                                    {
                                                        parsedIniFileData.Append("<BDNA,2>");
                                                    }
                                                    parsedIniFileData.Append(tEntry);
                                                }
                                            }
                                        }
                                    }
                                }

                                Lib.Logger.TraceEvent(TraceEventType.Information,
                                                      0,
                                                      "Parsing Succeeded. Parsed INI File Data is : " + parsedIniFileData.ToString(),
                                                      parsedIniFileData.ToString());

                                if (ResultCodes.RC_SUCCESS == resultCode)
                                {
                                    dataRow.Append(elementId).Append(',')
                                    .Append(attributes[@"collectedCPAttr"])
                                    .Append(',')
                                    .Append(scriptParameters[@"CollectorId"]).Append(',')
                                    .Append(taskId).Append(',')
                                    .Append(databaseTimestamp + executionTimer.ElapsedMilliseconds)
                                    .Append(',')
                                    .Append(@"collectedCPAttr")
                                    .Append(',')
                                    .Append(BdnaDelimiters.BEGIN_TAG)
                                    .Append(collectedCPAttr)
                                    .Append(BdnaDelimiters.END_TAG);

                                    dataRow.Append(elementId).Append(',')
                                    .Append(attributes[@"parsedCPAttr"])
                                    .Append(',')
                                    .Append(scriptParameters[@"CollectorId"]).Append(',')
                                    .Append(taskId).Append(',')
                                    .Append(databaseTimestamp + executionTimer.ElapsedMilliseconds)
                                    .Append(',')
                                    .Append(@"parsedCPAttr")
                                    .Append(',')
                                    .Append(BdnaDelimiters.BEGIN_TAG)
                                    .Append(parsedIniFileData)
                                    .Append(BdnaDelimiters.END_TAG);
                                }
                            }
                            else
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Error,
                                                      0,
                                                      "CPA INI File not found on target machine.",
                                                      taskIdString);
                                resultCode = ResultCodes.RC_PROCESSING_EXCEPTION;
                            }
                        }
                    }
                } finally {
                    tl.Flush();
                    Lib.Logger.Listeners.Remove(tl);
                }

                logData = Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
            }

            Lib.Logger.TraceEvent(TraceEventType.Information,
                                  0,
                                  "CPA INI File data returned: ",
                                  taskIdString);
            Lib.Logger.TraceEvent(TraceEventType.Information,
                                  0,
                                  collectedCPAttr.ToString(),
                                  taskIdString);
            Lib.Logger.TraceEvent(TraceEventType.Information,
                                  0,
                                  "Log data returned: ",
                                  taskIdString);
            Lib.Logger.TraceEvent(TraceEventType.Information,
                                  0,
                                  logData,
                                  taskIdString);

            return(new CollectionScriptResults(resultCode, 0, null, null, null, false, dataRow.ToString()));
        }
예제 #5
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(long taskId, long cleId, long elementId, long databaseTimestamp,
                                                   long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters,
                                                   IDictionary <string, object> connection, string tftpPath, string tftpPath_login,
                                                   string tftpPath_password, ITftpDispatcher tftpDispatcher)
        {
            m_taskId            = taskId.ToString();
            m_cleId             = cleId;
            m_elementId         = elementId;
            m_databaseTimestamp = databaseTimestamp;
            m_localTimestamp    = localTimestamp;
            m_attributes        = attributes;
            m_scriptParameters  = scriptParameters;
            m_tftpPath          = tftpPath;
            m_tftpPath_login    = tftpPath_login;
            m_tftpPath_password = tftpPath_password;
            m_tftpDispatcher    = tftpDispatcher;
            m_connection        = connection;
            m_executionTimer    = Stopwatch.StartNew();

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script VMwareVMLSConfigFileContentScript.",
                                  m_taskId);
            try {
                // Check ManagementScope CIMV
                if (connection == null)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to VMwareVMLSConfigFileContentScript is null.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey("cimv2"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for CIMV namespace is not present in connection object.",
                                          m_taskId);
                }
                else
                {
                    m_cimvScope = connection[@"cimv2"] as ManagementScope;
                    if (!m_cimvScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to CIMV namespace failed.",
                                              m_taskId);
                    }
                }

                //Check VMLSFilePath attribute
                if (scriptParameters.ContainsKey("VMLSFilePath"))
                {
                    m_vmlsFilePath = scriptParameters[@"VMLSFilePath"];
                }
                else
                {
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing parameter VMLSFilePath attribute.",
                                          m_taskId);
                }

                // Check Remote Process Temp Directory
                if (!m_connection.ContainsKey(@"TemporaryDirectory"))
                {
                    m_connection[@"TemporaryDirectory"] = @"%TMP%";
                }
                else
                {
                    if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%"))
                    {
                        if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope))
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Error,
                                                  0,
                                                  "Task Id {0}: Temporary directory {1} is not valid.",
                                                  m_taskId,
                                                  m_connection[@"TemporaryDirectory"].ToString());
                            resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;  //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST
                        }
                        else
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: User specified temp directory has been validated.",
                                                  m_taskId);
                        }
                    }
                }

                // DEBUG-- to be removed
                #region DEBUG
                StringBuilder sb = new StringBuilder();
                foreach (KeyValuePair <string, string> kvp in m_attributes)
                {
                    sb.Append(@"Attribute[").Append((string)kvp.Key).Append(@"]=").AppendLine((string)kvp.Value);
                }
                Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                      0,
                                      "Task Id {0}: Attribute dictionary contents:\n{1}",
                                      m_taskId,
                                      sb.ToString());
                #endregion
                // DEBUG

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Attempting to retrieve file {1}.",
                                          m_taskId,
                                          m_vmlsFilePath);
                    StringBuilder fileContent = new StringBuilder();

                    if (Lib.ValidateFile(m_taskId, m_vmlsFilePath, m_cimvScope))
                    {
                        using (IRemoteProcess rp =
                                   RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, m_vmlsFilePath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) {
                            //
                            // Launch the remote process.
                            // This method will block until the entire remote process operation completes.
                            resultCode = rp.Launch();
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Remote file retrieval operation completed with result code {1}.",
                                                  m_taskId,
                                                  resultCode.ToString());
                            fileContent.Append(rp.Stdout);
                        }
                        // Format file content to format: name=value
                        string strFormattedString = this.formatFileContent(fileContent.ToString());
                        this.BuildDataRow(@"VMLSFileContent", strFormattedString);
                    }
                    else
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: VMLS file {1} does not exist.",
                                              m_taskId,
                                              m_vmlsFilePath);
                        resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE;
                    }
                }
            }
            catch (Exception ex) {
                if (ResultCodes.RC_SUCCESS == resultCode)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in VMwareVMLSConfigFileContentScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                    resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE;
                }
                else
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in VMwareVMLSConfigFileContentScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script VMwareVMLSConfigFileContentScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  resultCode.ToString());
            return(new CollectionScriptResults
                       (resultCode, 0, null, null, null, false, m_dataRow.ToString()));
        }
예제 #6
0
        /// <summary>
        /// Get File Content
        /// (Note that file path must be absolute path)
        /// (Note that file path should not have double quote in general, but it has escaped the double quote to be convenient).
        /// </summary>
        /// <param name="filePath">File Path</param>
        /// <param name="collectedData">Collected Result.</param>
        /// <returns></returns>
        private ResultCodes GetFileContent(string filePath, out string collectedData)
        {
            collectedData = string.Empty;
            ResultCodes resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_ACCESS_FILE_PROPERTY;

            if (!m_connection.ContainsKey(@"TemporaryDirectory"))
            {
                m_connection[@"TemporaryDirectory"] = @"%TMP%";
            }
            else
            {
                if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%"))
                {
                    if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope))
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Temporary directory {1} is not valid.",
                                              m_taskId,
                                              m_connection[@"TemporaryDirectory"].ToString());
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;  //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST
                    }
                    else
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: User specified temp directory has been validated.",
                                              m_taskId);
                    }
                }
            }

            if (filePath.EndsWith("\"") && filePath.StartsWith("\""))
            {
                filePath = filePath.Substring(1, filePath.Length - 2);
            }
            if (Lib.ValidateFile(m_taskId, filePath, m_cimvScope))
            {
                using (IRemoteProcess rp =
                           RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, filePath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) {
                    //
                    // Launch the remote process.
                    // This method will block until the entire remote process operation completes.
                    resultCode = rp.Launch();
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Remote file retrieval operation completed with result code {1}.",
                                          m_taskId,
                                          resultCode.ToString());
                    collectedData = rp.Stdout.ToString();
                }
            }
            else
            {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: filepath: {1} does not exist.",
                                      m_taskId,
                                      filePath);
            }

            return(resultCode);
        }
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(long taskId, long cleId, long elementId, long databaseTimestamp,
                                                   long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters,
                                                   IDictionary <string, object> connection, string tftpPath, string tftpPath_login,
                                                   string tftpPath_password, ITftpDispatcher tftpDispatcher)
        {
            m_taskId            = taskId.ToString();
            m_cleId             = cleId;
            m_elementId         = elementId;
            m_databaseTimestamp = databaseTimestamp;
            m_localTimestamp    = localTimestamp;
            m_attributes        = attributes;
            m_scriptParameters  = scriptParameters;
            m_tftpDispatcher    = tftpDispatcher;
            m_tftpPath          = tftpPath;
            m_tftpPath_login    = tftpPath_login;
            m_tftpPath_password = tftpPath_password;
            m_connection        = connection;
            m_executionTimer    = Stopwatch.StartNew();

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script MSVirtualServerVMConfigFileContentScript.",
                                  m_taskId);
            try
            {
                // Check ManagementScope CIMV
                if (connection == null)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to MSVirtualServerVMConfigFileContentScript is null.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey("cimv2"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for CIMV namespace is not present in connection object.",
                                          m_taskId);
                }
                else
                {
                    m_cimvScope = connection[@"cimv2"] as ManagementScope;
                    if (!m_cimvScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to CIMV namespace failed",
                                              m_taskId);
                    }
                }

                //Check VM Config File Path attribute
                if (scriptParameters.ContainsKey("vmcFile"))
                {
                    m_vmcFilePath = scriptParameters[@"vmcFile"];
                }
                else
                {
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing parameter VM Config File Path attribute.",
                                          m_taskId);
                }

                // Check Remote Process Temp Directory
                if (!m_connection.ContainsKey(@"TemporaryDirectory"))
                {
                    m_connection[@"TemporaryDirectory"] = @"%TMP%";
                }
                else
                {
                    if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%"))
                    {
                        if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope))
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Error,
                                                  0,
                                                  "Task Id {0}: Temporary directory {1} is not valid.",
                                                  m_taskId,
                                                  m_connection[@"TemporaryDirectory"].ToString());
                            resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;  //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST
                        }
                        else
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: User specified temp directory has been validated.",
                                                  m_taskId);
                        }
                    }
                }

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Attempting to retrieve file {1}.",
                                          m_taskId,
                                          m_vmcFilePath);
                    StringBuilder fileContent = new StringBuilder();

                    if (Lib.ValidateFile(m_taskId, m_vmcFilePath, m_cimvScope))
                    {
                        using (IRemoteProcess rp =
                                   RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, m_vmcFilePath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher))
                        {
                            //
                            // Launch the remote process.
                            // This method will block until the entire remote process operation completes.
                            rp.Encoding = Encoding.Unicode;
                            resultCode  = rp.Launch();
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Remote file retrieval operation completed with result code {1}.",
                                                  m_taskId,
                                                  resultCode.ToString());
                            fileContent.Append(rp.Stdout);
                        }
                        //Console.WriteLine(fileContent.ToString());
                        string        formattedFile = fileContent.ToString().Substring(1);
                        StringBuilder fileData      = getVMData(formattedFile);
                        this.BuildDataRow(@"vmcFileData", fileData.ToString());
                    }
                    else
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: VM Config file {1} does not exist.",
                                              m_taskId,
                                              m_vmcFilePath);

                        resultCode = ResultCodes.RC_SUCCESS; //@TODO: change to RC_REMOTE_FILE_NOT_EXISTED
                        //resultCode = ResultCodes.RC_PROCESSING_EXCEPTION;  //@TODO: change to RC_REMOTE_FILE_NOT_EXISTED
                    }
                }
            }
            catch (Exception ex)
            {
                if (ResultCodes.RC_SUCCESS == resultCode)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in MSVirtualServerVMConfigFileContentScript.  Elapsed time {1}.\n{2}Result code changed to RC_PROCESSING_EXECEPTION.",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                    resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE;
                }
                else
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in MSVirtualServerVMConfigFileContentScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script MSVirtualServerVMConfigFileContentScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  resultCode.ToString());
            return(new CollectionScriptResults
                       (resultCode, 0, null, null, null, false, m_dataRow.ToString()));
        }
예제 #8
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher)
        {
            m_taskId            = taskId.ToString();
            m_cleId             = cleId;
            m_elementId         = elementId;
            m_databaseTimestamp = databaseTimestamp;
            m_localTimestamp    = localTimestamp;
            m_attributes        = attributes;
            m_scriptParameters  = scriptParameters;
            m_tftpDispatcher    = tftpDispatcher;
            m_tftpPath          = tftpPath;
            m_tftpPath_login    = tftpPath_login;
            m_tftpPath_password = tftpPath_password;
            m_connection        = connection;
            m_executionTimer    = Stopwatch.StartNew();

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script WinFileContentScript.",
                                  m_taskId);
            try {
                // Check ManagementScope CIMV
                if (connection == null)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to VMWareVMXConfigFileContentScript is null.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey("cimv2"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for CIMV namespace is not present in connection object.",
                                          m_taskId);
                }
                else
                {
                    m_cimvScope = connection[@"cimv2"] as ManagementScope;
                    if (!m_cimvScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to CIMV namespace failed",
                                              m_taskId);
                    }
                }



                string filePath = string.Empty;

                foreach (KeyValuePair <string, string> kvp in scriptParameters)
                {
                    string key = kvp.Key;
                    if (key.Contains(":"))
                    {
                        int i = key.IndexOf(':');
                        key = key.Substring(i + 1);
                    }

                    if (key == @"filePath")
                    {
                        filePath = kvp.Value;
                    }
                }

                if (string.IsNullOrEmpty(filePath))
                {
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task id {0}: Missing file path parameter.",
                                          m_taskId);
                }


                // Check Remote Process Temp Directory
                if (!m_connection.ContainsKey(@"TemporaryDirectory"))
                {
                    m_connection[@"TemporaryDirectory"] = @"%TMP%";
                }
                else
                {
                    if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%"))
                    {
                        if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope))
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Error,
                                                  0,
                                                  "Task Id {0}: Temporary directory {1} is not valid.",
                                                  m_taskId,
                                                  m_connection[@"TemporaryDirectory"].ToString());
                            resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;  //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST
                        }
                        else
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: User specified temp directory has been validated.",
                                                  m_taskId);
                        }
                    }
                }

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Attempting to retrieve file {1}.",
                                          m_taskId,
                                          m_FilePath);
                    StringBuilder fileContent = new StringBuilder();

                    if (Lib.ValidateFile(m_taskId, filePath, m_cimvScope))
                    {
                        using (IRemoteProcess rp =
                                   RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, filePath, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) {
                            //
                            // Launch the remote process.
                            // This method will block until the entire remote process operation completes.
                            resultCode = rp.Launch();
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Remote file retrieval operation completed with result code {1}.",
                                                  m_taskId,
                                                  resultCode.ToString());
                            fileContent.Append(rp.Stdout);
                        }
                        this.BuildDataRow(@"fileContent", fileContent.ToString());
                    }
                    else
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: file {1} does not exist.",
                                              m_taskId,
                                              filePath);
                        //resultCode = ResultCodes.RC_SUCCESS;
                    }
                }
            } catch (ManagementException me) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Insufficient privilege to read file.\nMessage: {1}",
                                      m_taskId,
                                      me.Message);
                if (me.InnerException != null)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Inner Exception Message: {1}.",
                                          m_taskId,
                                          me.InnerException.Message);
                }
                resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE;
            } catch (COMException ce) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Not enough privilege to access run WMI query.\nMessage: {1}.",
                                      m_taskId,
                                      ce.Message);
                if (ce.InnerException != null)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Inner Exception Message: {1}.",
                                          m_taskId,
                                          ce.InnerException.Message);
                }
                resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_RUN_WMI_QUERY;
            } catch (Exception ex) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Unhandled exception in WinFileContentScript.  Elapsed time {1}.\n{2}",
                                      m_taskId,
                                      m_executionTimer.Elapsed.ToString(),
                                      ex.ToString());
                resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE;
            }
            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script VMWareVMXConfigFileContentScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  resultCode.ToString());

            return(new CollectionScriptResults
                       (resultCode, 0, null, null, null, false, m_dataRow.ToString()));
        }
예제 #9
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        ///
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(
            long taskId,
            long cleId,
            long elementId,
            long databaseTimestamp,
            long localTimestamp,
            IDictionary <string, string> attributes,
            IDictionary <string, string> scriptParameters,
            IDictionary <string, object> connection,
            string tftpPath,
            string tftpPath_login,
            string tftpPath_password,
            ITftpDispatcher tftpDispatcher)
        {
            m_executionTimer    = Stopwatch.StartNew();
            m_taskId            = taskId.ToString();
            m_cleId             = cleId;
            m_elementId         = elementId;
            m_databaseTimestamp = databaseTimestamp;
            m_localTimestamp    = localTimestamp;
            m_attributes        = attributes;
            m_scriptParameters  = scriptParameters;

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASGetFileScript.",
                                  m_taskId);
            try {
                ManagementScope cimvScope    = null;
                ManagementScope defaultScope = null;

                // Check ManagementScope CIMV
                if (null == connection)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to WindowsWASGetFileScript is null.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey(@"cimv2"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for CIMV namespace is not present in connection object.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey(@"default"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for Default namespace is not present in connection object.",
                                          m_taskId);
                }
                else
                {
                    cimvScope    = connection[@"cimv2"] as ManagementScope;
                    defaultScope = connection[@"default"] as ManagementScope;

                    if (!cimvScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to CIMV namespace failed.",
                                              m_taskId);
                    }
                    else if (!defaultScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to Default namespace failed.",
                                              m_taskId);
                    }
                }

                //Check Script Variables
                if (resultCode.Equals(ResultCodes.RC_SUCCESS))
                {
                    //
                    // We have to massage the script parameter set, replace
                    // any keys with a colon by just the part after the colon.
                    // We should probably narrow this to just the registryKey
                    // and registryRoot entries...
                    Dictionary <string, string> d = new Dictionary <string, string>();

                    foreach (KeyValuePair <string, string> kvp in scriptParameters)
                    {
                        string[] sa = kvp.Key.Split(s_collectionParameterSetDelimiter,
                                                    StringSplitOptions.RemoveEmptyEntries);
                        Debug.Assert(sa.Length > 0);
                        d[sa[sa.Length - 1]] = kvp.Value;
                    }

                    scriptParameters = d;
                    if (scriptParameters.ContainsKey("profRegPath"))
                    {
                        m_filePath = scriptParameters[@"profRegPath"];
                    }
                    else if (scriptParameters.ContainsKey("cellPath"))
                    {
                        m_filePath = scriptParameters[@"cellPath"];
                    }
                    else if (scriptParameters.ContainsKey("nodeVarPath"))
                    {
                        m_filePath = scriptParameters[@"nodeVarPath"];
                    }
                    else if (scriptParameters.ContainsKey("rsrcFilePath"))
                    {
                        m_filePath = scriptParameters[@"rsrcFilePath"];
                    }
                    else if (scriptParameters.ContainsKey("svrCfgPath"))
                    {
                        m_filePath = scriptParameters[@"svrCfgPath"];
                    }
                    else if (scriptParameters.ContainsKey("virtHostsFilePath"))
                    {
                        m_filePath = scriptParameters[@"virtHostsFilePath"];
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing parameter WAS Script parameter.",
                                              m_taskId);
                    }
                }

                // Check Remote Process Temp Directory
                if (resultCode.Equals(ResultCodes.RC_SUCCESS))
                {
                    if (!connection.ContainsKey(@"TemporaryDirectory"))
                    {
                        connection[@"TemporaryDirectory"] = @"%TMP%";
                    }
                    else
                    {
                        if (!connection[@"TemporaryDirectory"].Equals(@"%TMP%"))
                        {
                            if (!Lib.ValidateDirectory(m_taskId, connection[@"TemporaryDirectory"].ToString(), cimvScope))
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Error,
                                                      0,
                                                      "Task Id {0}: Temporary directory {1} is not valid.",
                                                      m_taskId,
                                                      connection[@"TemporaryDirectory"].ToString());
                                resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;  //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST
                            }
                            else
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                      0,
                                                      "Task Id {0}: User specified temp directory has been validated.",
                                                      m_taskId);
                            }
                        }
                    }
                }

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    StringBuilder fileContent = new StringBuilder();
                    StringBuilder fileName    = new StringBuilder();
                    string[]      fileData    = m_filePath.Split('=');
                    fileName.Append(fileData[0]);

                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Attempting to retrieve file {1}.",
                                          m_taskId,
                                          fileName.ToString());

                    if (Lib.ValidateFile(m_taskId, fileName.ToString(), cimvScope))
                    {
                        using (IRemoteProcess rp =
                                   RemoteProcess.GetRemoteFile(m_taskId, cimvScope, fileName.ToString(), connection, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) {
                            // Launch the remote process.
                            // This method will block until the entire remote process operation completes.
                            resultCode = rp.Launch();
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Remote file retrieval operation completed with result code {1}.",
                                                  m_taskId,
                                                  resultCode.ToString());
                            fileContent.Append(rp.Stdout);
                        }

                        m_dataRow.Append(m_elementId).Append(',')
                        .Append(m_attributes[fileData[1]]).Append(',')
                        .Append(m_scriptParameters[@"CollectorId"]).Append(',')
                        .Append(m_taskId).Append(',')
                        .Append(m_databaseTimestamp + m_executionTimer.ElapsedMilliseconds).Append(',')
                        .Append(fileData[1]).Append(',')
                        .Append(BdnaDelimiters.BEGIN_TAG).Append(fileContent).Append(BdnaDelimiters.END_TAG);
                    }
                    else
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: WAS Config file: {1} does not exist.",
                                              m_taskId,
                                              fileName.ToString());

                        resultCode = ResultCodes.RC_SUCCESS;
                    }
                }
            } catch (Exception ex) {
                Lib.LogException(m_taskId,
                                 m_executionTimer,
                                 "Unhandled exception in WindowsWASGetFileScript",
                                 ex);
                resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE;
            }

            CollectionScriptResults result = new CollectionScriptResults(resultCode,
                                                                         0,
                                                                         null,
                                                                         null,
                                                                         null,
                                                                         false,
                                                                         m_dataRow.ToString());

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASGetFileScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  result.ResultCode.ToString());
            return(result);
        }
예제 #10
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(long taskId, long cleId, long elementId, long databaseTimestamp, long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters, IDictionary <string, object> connection, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher)
        {
            m_taskId            = taskId.ToString();
            m_cleId             = cleId;
            m_elementId         = elementId;
            m_databaseTimestamp = databaseTimestamp;
            m_localTimestamp    = localTimestamp;
            m_attributes        = attributes;
            m_scriptParameters  = scriptParameters;
            m_tftpPath          = tftpPath;
            m_tftpPath_login    = tftpPath_login;
            m_tftpPath_password = tftpPath_password;
            m_tftpDispatcher    = tftpDispatcher;
            m_connection        = connection;
            m_executionTimer    = Stopwatch.StartNew();

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script CitrixLicensing.",
                                  m_taskId);
            try {
                // Check ManagementScope CIMV
                if (connection == null)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to CitrixLicensing is null.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey("cimv2"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for CIMV namespace is not present in connection object.",
                                          m_taskId);
                }
                else
                {
                    m_cimvScope = connection[@"cimv2"] as ManagementScope;
                    if (!m_cimvScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to CIMV namespace failed",
                                              m_taskId);
                    }
                }


                if (scriptParameters.ContainsKey("LicenseFileDir"))
                {
                    m_Dirs = scriptParameters[@"LicenseFileDir"];
                }
                else
                {
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing script parameter LicenseFileDir.",
                                          m_taskId);
                }

                // Check Remote Process Temp Directory
                if (!m_connection.ContainsKey(@"TemporaryDirectory"))
                {
                    m_connection[@"TemporaryDirectory"] = @"%TMP%";
                }
                else
                {
                    if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%"))
                    {
                        if (!Lib.ValidateDirectory(m_taskId, m_connection[@"TemporaryDirectory"].ToString(), m_cimvScope))
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Error,
                                                  0,
                                                  "Task Id {0}: Temporary directory {1} is not valid.",
                                                  m_taskId,
                                                  m_connection[@"TemporaryDirectory"].ToString());
                            resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;  //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST
                        }
                        else
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: User specified temp directory has been validated.",
                                                  m_taskId);
                        }
                    }
                }

                StringBuilder fileContent = new StringBuilder();

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    String[] m_Dirs_list = m_Dirs.Split(';');  ///just in case files exist in more than one location and each is seperated by ;

                    foreach (String m_Dir in m_Dirs_list)
                    {
                        ////m_Dir = "C:\\Program Files\\Citrix\\Licensing\\MyFiles";   /////DEBUG ONLY
                        ////StringBuilder fileContent = new StringBuilder();

                        if (!string.IsNullOrEmpty(m_Dir))
                        {
                            if (Lib.ValidateDirectory(m_taskId, m_Dir, m_cimvScope))
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                      0,
                                                      "Task Id {0}: Attempting to retrieve file from directory {1}.",
                                                      m_taskId,
                                                      m_Dir);

                                ////Console.WriteLine("RR DEBUG Dir={0}", m_Dir);

                                using (ManagementObject moDir = new ManagementObject(@"Win32_Directory='" + m_Dir + @"'")) {
                                    moDir.Scope = m_cimvScope;
                                    //moDir.Get();   //// DEBUG RR this is for what

                                    foreach (ManagementObject b in moDir.GetRelated("CIM_DataFile"))
                                    {
                                        ////Console.WriteLine("DEBUG: Object in the given dir : {0}", b.ClassPath);

                                        string FileName = b[@"Name"].ToString();
                                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                              0,
                                                              "Task Id {0}: DataFile name {1}.",
                                                              m_taskId,
                                                              FileName);

                                        ////Console.WriteLine("RR DEBUG DataFileName={0}", FileName);

                                        //license file must have a .lic extension
                                        if (FileName.EndsWith(".lic"))
                                        {
                                            using (IRemoteProcess rp =
                                                       RemoteProcess.GetRemoteFile(m_taskId, m_cimvScope, FileName, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) {
                                                //
                                                // Launch the remote process.
                                                // This method will block until the entire remote process operation completes.
                                                ResultCodes rc = rp.Launch();
                                                Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                                      0,
                                                                      "Task Id {0}: Remote file ({2}) retrieval operation completed with result code {1}.",
                                                                      m_taskId,
                                                                      rc.ToString(),
                                                                      FileName);

                                                fileContent.Append("<BDNA_FileName>").Append(FileName)
                                                .Append("<BDNA_FileContent>").Append(rp.Stdout);
                                            }
                                        }
                                    }

                                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                          0,
                                                          "Task Id {0}: Remote directoy's files content read with result code {1}.",
                                                          m_taskId,
                                                          resultCode);
                                }
                            }
                            else
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                      0,
                                                      "Task Id {0}: Directory {1} does not exist.",
                                                      m_taskId,
                                                      m_Dir);
                                resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_ACCESS_FILE_PROPERTY;
                            }
                        }
                    }

                    this.BuildDataRow(@"LicenseFileContent", fileContent);
                }
            } catch (ManagementException me) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Insufficient privilege to access file property station.exe.\nMessage: {1}",
                                      m_taskId,
                                      me.Message);
                if (me.InnerException != null)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Inner Exception Message: {1}.",
                                          m_taskId,
                                          me.InnerException.Message);
                }
                resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR;
            } catch (Exception ex) {
                if (ResultCodes.RC_SUCCESS == resultCode)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in CitrixLicensing.  Elapsed time {1}.\n{2}Result code changed to RC_PROCESSING_EXECEPTION.",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                    resultCode = ResultCodes.RC_PROCESSING_EXCEPTION;
                }
                else
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in CitrixLicensing.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }
            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script CitrixLicensingFileContentScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  resultCode.ToString());

            return(new CollectionScriptResults
                       (resultCode, 0, null, null, null, false, m_dataRow.ToString()));
        }
예제 #11
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        ///
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(
            long taskId,
            long cleId,
            long elementId,
            long databaseTimestamp,
            long localTimestamp,
            IDictionary <string, string> attributes,
            IDictionary <string, string> scriptParameters,
            IDictionary <string, object> connection,
            string tftpPath,
            string tftpPath_login,
            string tftpPath_password,
            ITftpDispatcher tftpDispatcher)
        {
            m_executionTimer    = Stopwatch.StartNew();
            m_taskId            = taskId.ToString();
            m_cleId             = cleId;
            m_elementId         = elementId;
            m_databaseTimestamp = databaseTimestamp;
            m_localTimestamp    = localTimestamp;
            m_attributes        = attributes;
            m_scriptParameters  = scriptParameters;

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASParseServerIndexScript.",
                                  m_taskId);
            try
            {
                ManagementScope cimvScope    = null;
                ManagementScope defaultScope = null;

                // Check ManagementScope CIMV
                if (null == connection)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to WindowsWASParseServerIndexScript is null.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey(@"cimv2"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for CIMV namespace is not present in connection object.",
                                          m_taskId);
                }
                else if (!connection.ContainsKey(@"default"))
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Management scope for Default namespace is not present in connection object.",
                                          m_taskId);
                }
                else
                {
                    cimvScope    = connection[@"cimv2"] as ManagementScope;
                    defaultScope = connection[@"default"] as ManagementScope;

                    if (!cimvScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to CIMV namespace failed.",
                                              m_taskId);
                    }
                    else if (!defaultScope.IsConnected)
                    {
                        resultCode = ResultCodes.RC_WMI_CONNECTION_FAILED;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Connection to Default namespace failed.",
                                              m_taskId);
                    }
                }

                //Check Script attributes
                if (resultCode.Equals(ResultCodes.RC_SUCCESS))
                {
                    if (scriptParameters.ContainsKey("profilePath"))
                    {
                        m_profileHome = scriptParameters[@"profilePath"];
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing parameter WAS Profile Path parameter.",
                                              m_taskId);
                    }
                    if (scriptParameters.ContainsKey("cellName"))
                    {
                        m_cell = scriptParameters[@"cellName"];
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing parameter WAS Cell Name parameter.",
                                              m_taskId);
                    }
                    if (scriptParameters.ContainsKey("nodeName"))
                    {
                        m_node = scriptParameters[@"nodeName"];
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing parameter WAS Node Name parameter.",
                                              m_taskId);
                    }
                    if (scriptParameters.ContainsKey("appsrv_Name"))
                    {
                        m_server = scriptParameters[@"appsrv_Name"];
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing parameter WAS Server Name parameter.",
                                              m_taskId);
                    }
                }
                // Check Remote Process Temp Directory
                if (resultCode.Equals(ResultCodes.RC_SUCCESS))
                {
                    if (!connection.ContainsKey(@"TemporaryDirectory"))
                    {
                        connection[@"TemporaryDirectory"] = @"%TMP%";
                    }
                    else
                    {
                        if (!connection[@"TemporaryDirectory"].Equals(@"%TMP%"))
                        {
                            if (!Lib.ValidateDirectory(m_taskId, connection[@"TemporaryDirectory"].ToString(), cimvScope))
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Error,
                                                      0,
                                                      "Task Id {0}: Temporary directory {1} is not valid.",
                                                      m_taskId,
                                                      connection[@"TemporaryDirectory"].ToString());
                                resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;  //@TODO: change to RC_TEMP_DIRECTORY_NOT_EXIST
                            }
                            else
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                      0,
                                                      "Task Id {0}: User specified temp directory has been validated.",
                                                      m_taskId);
                            }
                        }
                    }
                }

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    // Gather Variables Xml path for the cell and node
                    StringBuilder nVarPath = new StringBuilder();
                    nVarPath.Append(m_profileHome).Append(@"\config\cells\").Append(m_cell).Append(@"\nodes\").Append(m_node).Append(@"\variables.xml").Append(@"=nodeVarData");
                    BuildDataRow(s_nodeVarPath, nVarPath);

                    // Get the resources file path
                    StringBuilder rsrcPath = new StringBuilder();
                    rsrcPath.Append(m_profileHome).Append(@"\config\cells\").Append(m_cell).Append(@"\nodes\").Append(m_node).Append(@"\servers\").Append(m_server).Append(@"\resources.xml").Append(@"=rsrcFileData");
                    BuildDataRow(s_rsrcFilePath, rsrcPath);

                    // Get the virtual hosts file path
                    StringBuilder virtHostsPath = new StringBuilder();
                    virtHostsPath.Append(m_profileHome).Append(@"\config\cells\").Append(m_cell).Append(@"\virtualhosts.xml").Append(@"=virtHostsFileData");
                    BuildDataRow(s_virtHostsFilePath, virtHostsPath);

                    // Parse ServerIndex file
                    StringBuilder fileContent = new StringBuilder();
                    StringBuilder serverIndx  = new StringBuilder();
                    serverIndx.Append(m_profileHome).Append(@"\config\cells\").Append(m_cell).Append(@"\nodes\").Append(m_node).Append(@"\serverindex.xml");

                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Attempting to retrieve file {1}.",
                                          m_taskId,
                                          serverIndx.ToString());

                    if (Lib.ValidateFile(m_taskId, serverIndx.ToString(), cimvScope))
                    {
                        using (IRemoteProcess rp =
                                   RemoteProcess.GetRemoteFile(m_taskId, cimvScope, serverIndx.ToString(), connection, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher))
                        {
                            // Launch the remote process.
                            // This method will block until the entire remote process operation completes.
                            resultCode = rp.Launch();
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Remote file retrieval operation completed with result code {1}.",
                                                  m_taskId,
                                                  resultCode.ToString());
                            fileContent.Append(rp.Stdout);
                        }
                        // Parse ServerIndex file content
                        resultCode = parseServerIndxFile(fileContent.ToString(), m_server);
                    }
                    else
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: WAS Server Index file: {1} does not exist.",
                                              m_taskId,
                                              serverIndx.ToString());
                        resultCode = ResultCodes.RC_SUCCESS;
                    }
                }
            }
            catch (Exception ex)
            {
                Lib.LogException(m_taskId,
                                 m_executionTimer,
                                 "Unhandled exception in WindowsWASParseServerIndexScript",
                                 ex);
                resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE;
            }

            CollectionScriptResults result = new CollectionScriptResults(resultCode,
                                                                         0,
                                                                         null,
                                                                         null,
                                                                         null,
                                                                         false,
                                                                         m_dataRow.ToString());

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASProfileFootprintScript2.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  result.ResultCode.ToString());
            return(result);
        }