Ejemplo n.º 1
0
        public String ToString(ResultCodes code)
        {
            StringBuilder resultCodeToString = new StringBuilder();

            do
            {
                if (code == ResultCodes.NuiIntializationFailed)
                {
                    resultCodeToString.Append("Error - Unable to initialize the Kinect sensors. ");
                    resultCodeToString.Append("Make sure Kinect is connected to the computer");
                    break;
                }

                if (code == ResultCodes.OutOfMemory)
                {
                    resultCodeToString.Append("Error: System is out of memory");
                    break;
                }

            } while (false);

            return resultCodeToString.ToString();
        }
        /// <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();

            m_taskId = taskId.ToString();
            StringBuilder dataRow    = new StringBuilder();
            ResultCodes   resultCode = ResultCodes.RC_SUCCESS;

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

            try {
                ManagementScope cimvScope    = null;
                ManagementScope defaultScope = null;

                if (null == connection)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to InternetExplorerStaticScript 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);
                    }
                    else
                    {
                        IDictionary <string, string> queryResults = new Dictionary <string, string>();
                        using (ManagementClass wmiRegistry = new ManagementClass(defaultScope,
                                                                                 new ManagementPath(@"StdRegProv"),
                                                                                 null)) {
                            Debug.Assert(null != wmiRegistry);
                            resultCode = GetIEInstalledDirectory(wmiRegistry);
                        }

                        if (!String.IsNullOrEmpty(m_ieInstallDirectory))
                        {
                            if (ResultCodes.RC_SUCCESS == resultCode)
                            {
                                resultCode = GetIEVersionAndInstallDate(cimvScope);
                            }

                            if (ResultCodes.RC_SUCCESS == resultCode)
                            {
                                GetServicePack();
                                dataRow.Append(elementId)
                                .Append(',')
                                .Append(attributes[@"IEDetails"])
                                .Append(',')
                                .Append(scriptParameters[@"CollectorId"])
                                .Append(',')
                                .Append(taskId)
                                .Append(',')
                                .Append(databaseTimestamp + executionTimer.ElapsedMilliseconds)
                                .Append(',')
                                .Append(@"IEDetails")
                                .Append(',')
                                .Append(BdnaDelimiters.BEGIN_TAG)
                                .Append(@"name=""Internet Explorer")
                                .Append(m_ieFullProductName)
                                .Append('"')
                                .Append(BdnaDelimiters.DELIMITER2_TAG)
                                .Append("servicePack=\"")
                                .Append(m_ieServicePack)
                                .Append('"')
                                .Append(BdnaDelimiters.DELIMITER2_TAG)
                                .Append("version=\"")
                                .Append(m_ieVersion)
                                .Append('"')
                                .Append(BdnaDelimiters.DELIMITER2_TAG)
                                .Append("installDirectory=\"")
                                .Append(m_ieInstallDirectory)
                                .Append('"')
                                .Append(BdnaDelimiters.DELIMITER2_TAG)
                                .Append("installDate=\"")
                                .Append(m_ieInstallDate)
                                .Append('"')
                                .Append(BdnaDelimiters.END_TAG);
                            }
                        }
                    }
                }
            } catch (ManagementException me) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Insufficient privilege to access file property iexplore.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_INSUFFICIENT_PRIVILEGE_TO_ACCESS_FILE_PROPERTY;
            } 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.LogException(m_taskId,
                                 executionTimer,
                                 "Unhandled exception in InternetExplorerStaticScript",
                                 ex);
                resultCode = ResultCodes.RC_PROCESSING_EXCEPTION;
            }

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

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script InternetExplorerStaticScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  executionTimer.Elapsed.ToString(),
                                  result.ResultCode.ToString());
            return(result);
        }
Ejemplo n.º 3
0
 public RegisterStudentResult(ResultCodes result, string message = null)
 {
     Result  = result;
     Message = message;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Execute command
        /// (Note that file path must be absolute path)
        /// </summary>
        /// <param name="filePath">File Path</param>
        /// <param name="collectedData">Collected Result.</param>
        /// <returns></returns>
        private ResultCodes ExecuteCommand(string userCommandLine, out string collectedData)
        {
            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            collectedData = string.Empty;
            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}: Temporary directory {1} has been validated.",
                                              m_taskId,
                                              m_connection[@"TemporaryDirectory"].ToString());
                    }
                }
            }

            if (resultCode == ResultCodes.RC_SUCCESS)
            {
                string strTempDir = m_connection["TemporaryDirectory"].ToString().Trim();
                if (strTempDir.EndsWith(@"\"))
                {
                    strTempDir = strTempDir.Substring(0, strTempDir.Length - 1);
                }
                string        strBatchFileContent = buildBatchFile(userCommandLine);
                StringBuilder stdoutData          = new StringBuilder();
                using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile
                                               (m_taskId, m_cimvScope, strBatchFileContent, m_connection, m_tftpPath, m_tftpPath_login, m_tftpPath_password, m_tftpDispatcher)) {
                    //This method will block until the entire remote process operation completes.
                    resultCode = rp.Launch();

                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Command execution completed with result code {1}.",
                                          m_taskId,
                                          resultCode.ToString());

                    if (rp != null && rp.Stdout != null && resultCode == ResultCodes.RC_SUCCESS)
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: Command execution completed with result <{1}>.",
                                              m_taskId,
                                              rp.Stdout.ToString());

                        collectedData = rp.Stdout.ToString();

                        //if (output.IndexOf(s_endTag) != -1) {
                        //    collectedData = output.Substring(0, output.Length - s_endTag.Length - 2);
                        //} else {
                        //    resultCode = ResultCodes.RC_PROCESS_EXEC_FAILED;
                        //    Lib.Logger.TraceEvent(TraceEventType.Error,
                        //                          0,
                        //                          "Task Id {0}: Remote execution error.\nSTDOUT.STDERR:\n{1}",
                        //                          m_taskId,
                        //                          rp.Stdout.ToString());
                        //}
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_PROCESS_EXEC_FAILED;
                    }
                }
            }
            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_connection        = connection;
            string strOracleHome = null, strSchemaName = null, strSchemaPassword = null;

            m_executionTimer = Stopwatch.StartNew();
            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

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

            try {
                // Check ManagementScope CIMV
                ManagementScope cimvScope = null;
                if (connection == null)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to WindowsOracleInstanceStaticScript 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
                {
                    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",
                                              m_taskId);
                    }
                }

                if (!scriptParameters.ContainsKey("OracleHome"))
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing script parameter \"OracleHome\".",
                                          m_taskId);
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                }
                else
                {
                    strOracleHome = scriptParameters["OracleHome"].Trim();
                    if (strOracleHome.EndsWith(@"\"))
                    {
                        strOracleHome = strOracleHome.Substring(0, strOracleHome.Length - 1);
                    }
                }

                if (!connection.ContainsKey("schemaName"))
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing script parameter \"schemaName\".",
                                          m_taskId);
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                }
                else
                {
                    strSchemaName = connection["schemaName"].ToString().Trim();
                }

                if (!connection.ContainsKey("schemaPassword"))
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing script parameter \"schemaPassword\".",
                                          m_taskId);
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                }
                else
                {
                    strSchemaPassword = connection["schemaPassword"].ToString().Trim();
                }


                if (ResultCodes.RC_SUCCESS == resultCode)
                {
                    // Check Remote Process Temp Directory
                    if (!connection.ContainsKey("TemporaryDirectory"))
                    {
                        connection["TemporaryDirectory"] = @"%TMP%";
                    }
                    else
                    {
                        if (!m_connection[@"TemporaryDirectory"].Equals(@"%TMP%"))
                        {
                            if (!Lib.ValidateDirectory(m_taskId, m_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}: Temporary directory {1} has been validated.",
                                                      m_taskId,
                                                      connection[@"TemporaryDirectory"].ToString());
                            }
                        }
                    }
                }

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    string strTempDir = connection["TemporaryDirectory"].ToString().Trim();
                    if (strTempDir.EndsWith(@"\"))
                    {
                        strTempDir = strTempDir.Substring(0, strTempDir.Length - 1);
                    }

                    string        strBatchFileContent = buildBatchFile(strTempDir, strOracleHome, strSchemaName, strSchemaPassword);
                    StringBuilder stdoutData          = new StringBuilder();
                    using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile
                                                   (m_taskId, cimvScope, strBatchFileContent, connection, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) {
                        //This method will block until the entire remote process operation completes.
                        resultCode = rp.Launch();
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: Remote process operation completed with result code {1}.",
                                              m_taskId,
                                              resultCode.ToString());
                        if (resultCode == ResultCodes.RC_SUCCESS)
                        {
                            stdoutData.Append(rp.Stdout);
                            if (rp.Stdout != null && rp.Stdout.Length > 0)
                            {
                                if (rp.Stdout.ToString().Contains("ORA-01017"))
                                {
                                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                                          0,
                                                          "Task Id {0}: Oracle L3 credential is invalid.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}",
                                                          m_taskId,
                                                          rp.Stdout.ToString());
                                    resultCode = ResultCodes.RC_HOST_CONNECT_FAILED;
                                }
                                else if (rp.Stdout.ToString().Contains("ERROR-"))
                                {
                                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                                          0,
                                                          "Task Id {0}: Batch file execution exception.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}",
                                                          m_taskId,
                                                          rp.Stdout.ToString());
                                    resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR;
                                }
                                else if (!rp.Stdout.ToString().Contains(@"BDNA"))
                                {
                                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                                          0,
                                                          "Task Id {0}: SQLPLUS exception, no proper data returned.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}",
                                                          m_taskId,
                                                          rp.Stdout.ToString());
                                    resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR;
                                }
                                else if (!rp.Stdout.ToString().Contains(@"Execution completed"))
                                {
                                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                                          0,
                                                          "Task Id {0}: Exception with batch file return data.\nData returned is shorter than expected, possibly due to transfer failure.\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                                          m_taskId);

                                    resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR;
                                }
                            }
                            else
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Error,
                                                      0,
                                                      "Task Id {0}: No data returned.\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                                      m_taskId);
                                resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR;
                            }
                        }
                        else
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Error,
                                                  0,
                                                  "Task Id {0}: Remote execution error.\nSTDOUT.STDERR:\n{1}",
                                                  m_taskId,
                                                  rp.Stdout.ToString());
                        }
                    }
                    if (resultCode == ResultCodes.RC_SUCCESS && stdoutData.Length > 0)
                    {
                        foreach (KeyValuePair <string, QueryTableEntry> entry in s_queryTable)
                        {
                            entry.Value.ResultHandler(this, entry.Key, stdoutData.ToString());
                        }
                    }
                }
            }
            catch (Exception ex) {
                if (ResultCodes.RC_SUCCESS == resultCode)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in WindowsOracleInstanceStaticScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          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 WindowsOracleInstanceStaticScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsOracleInstanceStaticScript.  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()));
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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, 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_executionTimer    = Stopwatch.StartNew();
            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            try {
                Lib.Logger.TraceEvent(TraceEventType.Start,
                                      0,
                                      "Task Id {0}: Collection script SAPL3DetailsScript.",
                                      m_taskId);

                if (connection == null)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                }
                else
                {
                    //Check host attributes
                    if (connection.ContainsKey(@"address"))
                    {
                        m_strApplicationServer = connection[@"address"] as String;
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing SAP Application Server connection parameter.",
                                              m_taskId);
                    }

                    //Check InstanceNumber attributes
                    if (connection.ContainsKey(@"systemNumber"))
                    {
                        m_strInstanceNumber = connection[@"systemNumber"] as String;
                        if (m_strInstanceNumber.Length != 2)
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Error,
                                                  0,
                                                  "Task Id {0}: Invalid System number <{1}>.\nSystem Number should always be two digits even if the number is 00.",
                                                  m_taskId,
                                                  m_strInstanceNumber);
                            resultCode = ResultCodes.RC_INVALID_PARAMETER_TYPE;
                        }
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing SAP system number connection parameter.",
                                              m_taskId);
                    }

                    //Check SAP Credential
                    if (connection.ContainsKey(@"sapUserName") && connection.ContainsKey(@"sapUserPassword"))
                    {
                        m_strSAPUserName     = connection[@"sapUserName"] as String;
                        m_strSAPUserPassword = connection[@"sapUserPassword"] as String;
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing SAP User name/password connection parameter.",
                                              m_taskId);
                    }
                }

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    using (SAPGuiConnection oConn = new SAPGuiConnection()) {
                        if (!String.IsNullOrEmpty(SAPConnectionString))
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Connecting to remote machine using {1}, SAP user name {2}.",
                                                  m_taskId,
                                                  SAPConnectionString,
                                                  m_strSAPUserName);
                            Stopwatch sw = Stopwatch.StartNew();
                            oConn.Connect(SAPConnectionString, this.m_strSAPUserName, this.m_strSAPUserPassword);
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Connection to {1} complete.  Elapsed time {2}.\n{3}",
                                                  m_taskId,
                                                  m_strApplicationServer,
                                                  sw.Elapsed.ToString(),
                                                  oConn.logData.ToString());

                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Collecting server information from remote SAP server",
                                                  m_taskId);
                            sw.Reset();
                            sw.Start();
                            SAPGuiSession          oSess = oConn.Session;
                            SAPServerInfoCollector oServerInfoCollector = new SAPServerInfoCollector(ref oSess);
                            oServerInfoCollector.Collect();
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Collection of server information complete.  Elapsed time {1}.\n{2}",
                                                  m_taskId,
                                                  sw.Elapsed.ToString(),
                                                  oServerInfoCollector.logData.ToString());
                            foreach (KeyValuePair <string, string> kvp in oServerInfoCollector.ResultDictionary)
                            {
                                this.BuildDataRow(kvp.Key, kvp.Value);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in SAPL3DetailsScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          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 SAPL3DetailsScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script SAPL3DetailsScript.  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()));
        }
Ejemplo n.º 8
0
 public CPException(ResultCodes result)
 {
     this.Result      = result;
     this.Description = GetDescription(result);
 }
Ejemplo n.º 9
0
        public static string GetDescription(ResultCodes ResultCode)
        {
            string descr = "";

            if (ResultCode == ResultCodes.E_INVALID_WINID)
            {
                descr = "Invalid window ID";
            }
            else if (ResultCode == ResultCodes.E_NOTFOUND)
            {
                descr = "Not found";
            }
            else if (ResultCode == ResultCodes.E_WINTYPEMISMATCH)
            {
                descr = "Window type mismatch";
            }
            else if (ResultCode == ResultCodes.E_INVALID_ARGS)
            {
                descr = "Invalid argument";
            }
            else if (ResultCode == ResultCodes.E_INVALID_ARCHIVE_VERSION)
            {
                descr = "Invalid archive version";
            }
            else if (ResultCode == ResultCodes.E_ARCHIVE_NOTFOUND)
            {
                descr = "Archive not found";
            }
            else if (ResultCode == ResultCodes.E_WINID_ALLREADYUSED)
            {
                descr = "Window ID already used";
            }
            else if (ResultCode == ResultCodes.E_INVALID_FORMAT)
            {
                descr = "Invalid archive format";
            }
            else if (ResultCode == ResultCodes.E_FILE_NOTEXIST)
            {
                descr = "The specified file does not exist";
            }
            else if (ResultCode == ResultCodes.E_WIN_CANNOT_SHOW_OR_REMOVE)
            {
                descr = "Cannot show or remove the window in the way specified";
            }
            else if (ResultCode == ResultCodes.E_PARS_NOT_ENOUGH)
            {
                descr = "Not enough parameters supplied";
            }
            else if (ResultCode == ResultCodes.E_TOMANY_PARS_SUPPLIED)
            {
                descr = "Too may parameters supplied";
            }
            else if (ResultCode == ResultCodes.E_INVALID_METHODNAME)
            {
                descr = "Invalid RMC method name";
            }
            else if (ResultCode == ResultCodes.E_INVALID_OBJECTNAME)
            {
                descr = "Invalid RMC object name";
            }
            else if (ResultCode == ResultCodes.E_BAD_FORMAT)
            {
                descr = "Bad parameter format";
            }
            else if (ResultCode == ResultCodes.E_UNSUPPORTED_DISPLAY_FORMAT)
            {
                descr = "Unsupported display format";
            }
            else if (ResultCode == ResultCodes.E_NO_TIMING_SELECTED)
            {
                descr = "No timing has been selected";
            }
            else if (ResultCode == ResultCodes.E_NO_INPUT_SELECTED)
            {
                descr = "No input has been selected";
            }
            else if (ResultCode == ResultCodes.E_NO_DISPLAY_INFO_AVAILABLE)
            {
                descr = "No display information available";
            }
            else if (ResultCode == ResultCodes.E_ENGINE_ALREADY_RUNNING)
            {
                descr = "Engine is already running";
            }
            else if (ResultCode == ResultCodes.E_NO_AVAILABLE_ENGINE)
            {
                descr = "There is no available engine";
            }
            else if (ResultCode == ResultCodes.E_NO_DEVICE_SELECTED)
            {
                descr = "No device has been selected";
            }
            else
            {
                descr = "Unknown error";
            }
            return(descr);
        }
Ejemplo n.º 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)
        {
            Stopwatch     executionTimer = Stopwatch.StartNew();
            string        taskIdString   = taskId.ToString();
            StringBuilder dataRow        = new StringBuilder();
            ResultCodes   resultCode     = ResultCodes.RC_SUCCESS;

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

            try
            {
                if (null == connection)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Connection object passed to RemoveWindowsProfileScript is null.",
                                          taskIdString);
                }
                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.",
                                          taskIdString);
                }
                else
                {
                    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);
                    }
                    else
                    {
                        string userName = connection[@"userName"] as string;
                        Debug.Assert(null != userName);

                        int domainSeparatorPosition = userName.IndexOf('\\');

                        if (-1 != domainSeparatorPosition)
                        {
                            userName = userName.Substring(domainSeparatorPosition + 1);
                        }

                        string profileDirectory    = @"c:\Documents and Settings\" + userName;
                        uint   wmiMethodResultCode = 0;
                        resultCode = Lib.DeleteDirectory(taskIdString, profileDirectory, cimvScope, out wmiMethodResultCode);
                    }
                }
            }
            catch (Exception ex)
            {
                Lib.LogException(taskIdString,
                                 executionTimer,
                                 "Unhandled exception in RemoveWindowsProfileScript",
                                 ex);
                resultCode = ResultCodes.RC_PROCESSING_EXCEPTION;
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script RemoveWindowsProfileScript.  Elapsed time {1}.  Result code {2}.",
                                  taskIdString,
                                  executionTimer.Elapsed.ToString(),
                                  resultCode.ToString());
            return(new CollectionScriptResults(resultCode, 0, null, null, null, false, dataRow.ToString()));
        }
Ejemplo n.º 11
0
 public Extras(string envelopeXdr, string resultXdr, ResultCodes resultCodes)
 {
     EnvelopeXdr       = envelopeXdr;
     ResultXdr         = resultXdr;
     ExtrasResultCodes = resultCodes;
 }
        /// <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;
            string strOracleHome = null, validatedInstances = null;

            string[] strRunningInstances = null;

            m_executionTimer = Stopwatch.StartNew();
            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script WindowsOracleInstallationEditionScript.",
                                  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 WindowsOracleInstallationEditionScript 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 Oracle Home attribute
                if (!scriptParameters.ContainsKey("OracleHome"))
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing script parameter \"OracleHome\".",
                                          m_taskId);
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                }
                else
                {
                    strOracleHome = scriptParameters["OracleHome"];
                }

                // 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}: Temporary directory {1} has been validated.",
                                                  m_taskId,
                                                  m_connection[@"TemporaryDirectory"].ToString());
                        }
                    }
                }

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    string version = string.Empty, edition = string.Empty;
                    resultCode = GetOracleServerVersion(strOracleHome, out version);
                    if (!string.IsNullOrEmpty(version))
                    {
                        resultCode = GetOracleServerEdition(strOracleHome, out edition);
                        if (!string.IsNullOrEmpty(edition))
                        {
                            BuildDataRow(@"edition", edition);
                        }
                    }
                }
            } catch (Exception ex) {
                if (ResultCodes.RC_SUCCESS == resultCode)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in WindowsOracleInstallationEditionScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          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 WindowsOracleInstallationEditionScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsOracleInstallationEditionScript.  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()));
        }
        /// <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_executionTimer    = Stopwatch.StartNew();
            ResultCodes             resultCode   = ResultCodes.RC_BAD_COLLECTION_SCRIPT;
            DbConnection            dbConnection = null;
            CollectionScriptResults result       = null;

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

            try {
                if (connection == null)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                }
                else
                {
                    //Check connection attributes
                    if (connection.ContainsKey("dbConnection"))
                    {
                        dbConnection = connection[@"dbConnection"] as DbConnection;
                    }
                    else
                    {
                        resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Missing dbConnection script parameter.",
                                              m_taskId);
                    }
                }
                if (dbConnection == null)
                {
                    resultCode = ResultCodes.RC_NULL_CONNECTION_OBJECT;
                }
                else if (dbConnection.State != ConnectionState.Open)
                {
                    resultCode = ResultCodes.RC_HOST_CONNECT_FAILED;
                }
                else
                {
                    using (dbConnection) {
                        resultCode = GetDeviceDetails(dbConnection);
                    }
                }

                // Return RC_SUCCESS even if the query failed, as the database
                // may be inaccessible
                resultCode = ResultCodes.RC_SUCCESS;

                StringBuilder dataRow = new StringBuilder();
                dataRow.Append(elementId)
                .Append(',')
                .Append(m_attributes[@"deviceDetails"])
                .Append(',')
                .Append(m_scriptParameters[@"CollectorId"])
                .Append(',')
                .Append(m_taskId)
                .Append(',')
                .Append(m_databaseTimestamp + m_executionTimer.ElapsedMilliseconds)
                .Append(',')
                .Append(@"deviceDetails")
                .Append(',')
                .Append(BdnaDelimiters.BEGIN_TAG)
                .Append(m_deviceDetails.ToString())
                .Append(BdnaDelimiters.END_TAG);
                result = new CollectionScriptResults(resultCode, 0, null, null, null, false, dataRow.ToString());
            } catch (Exception e) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Unhandled exception in WDMOnMSSQLDeviceDetailsStaticScript.\n{1}",
                                      m_taskId,
                                      e.ToString());
                result = new CollectionScriptResults
                             (ResultCodes.RC_PROCESS_EXEC_FAILED, 0, null, null, null, false, null);
            }

            Debug.Assert(null != result);
            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Connection script WDMOnMSSQLDeviceDetailsStaticScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  result.ResultCode.ToString());
            return(result);
        }
        private ResultCodes GetDeviceDetails(DbConnection dbConnection)
        {
            ResultCodes resultCode  = ResultCodes.RC_PROCESSING_EXCEPTION;
            Stopwatch   sw          = new Stopwatch();
            int         recordCount = 0;

            try {
                Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                      0,
                                      "Task Id {0}: Executing device details query.",
                                      m_taskId);
                sw.Start();

                m_databaseName = m_scriptParameters["databaseName"];
                Lib.Logger.TraceEvent(TraceEventType.Information,
                                      0,
                                      "Task Id {0}: Connecting to database {1}.",
                                      m_taskId,
                                      m_databaseName);
                dbConnection.ChangeDatabase(m_databaseName);

                DbCommand cmd = dbConnection.CreateCommand();
                cmd.CommandText =
                    @"select client.ClientID, client.Name, network.IP, network.MAC, " +
                    @"platform.Description as Platform, os.Description as OS, " +
                    @"client.Image, hardware.CPU, hardware.CPUSpeed, " +
                    @"hardware.RAM, storage.TotalSpace, hardware.Serial, " +
                    @"hardware.BIOS, hardware.Manufactured " +
                    @"from Client client, ClientHardware hardware, " +
                    @"ClientNetwork network, ClientStorage storage, " +
                    @"Platform platform, OSType os " +
                    @"where client.ClientID = hardware.ClientID " +
                    @"and client.ClientID = network.ClientID " +
                    @"and client.ClientID = storage.ClientID " +
                    @"and hardware.PlatformID = platform.PlatformID " +
                    @"and client.OSTypeID = os.OSTypeID ";
                cmd.CommandType = CommandType.Text;

                DbDataReader reader = cmd.ExecuteReader();
                Debug.Assert(null != reader);
                using (reader) {
                    for (recordCount = 0; reader.Read(); ++recordCount)
                    {
                        if (m_deviceDetails.Length > 0)
                        {
                            m_deviceDetails.Append(BdnaDelimiters.DELIMITER_TAG);
                        }
                        m_deviceDetails.Append("ClientID=").Append(reader[@"ClientID"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("Name=").Append(reader[@"Name"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("IPAddress=").Append(reader[@"IP"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("MACAddress=").Append(reader[@"MAC"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("Platform=").Append(reader[@"Platform"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("OS=").Append(reader[@"OS"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("Image=").Append(reader[@"Image"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("CPU=").Append(reader[@"CPU"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("CPUSpeed=").Append(reader[@"CPUSpeed"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("RAM=").Append(reader[@"RAM"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("MediaSize=").Append(reader[@"TotalSpace"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("SerialNumber=").Append(reader[@"Serial"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("BIOS=").Append(reader[@"BIOS"].ToString()).Append(BdnaDelimiters.DELIMITER1_TAG);
                        m_deviceDetails.Append("ManufacturedOn=").Append(reader[@"Manufactured"].ToString());
                    }
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Processing device details complete.",
                                          m_taskId);
                }
                resultCode = ResultCodes.RC_SUCCESS;
            } catch (DbException dbEx) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Device detail query failed. Elapsed time {1}.\n{2}",
                                      m_taskId,
                                      sw.Elapsed.ToString(),
                                      FormatDbException(dbEx));
            } catch (Exception ex) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Device detail query failed. Elapsed time {1}.\nRecords processed {2}\n{3}",
                                      m_taskId,
                                      sw.Elapsed.ToString(),
                                      recordCount.ToString(),
                                      ex.ToString());
            }

            return(resultCode);
        }
Ejemplo n.º 15
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_connection        = connection;
            m_executionTimer    = Stopwatch.StartNew();

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

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

                //Check VM_Guid attribute
                if (scriptParameters.ContainsKey("VM_Guid"))
                {
                    m_VM_Guid = scriptParameters[@"VM_Guid"];
                }
                else
                {
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing parameter VM_Guid attribute.",
                                          m_taskId);
                }
                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    /*                         ConnectionOptions connectionOptions = new ConnectionOptions();
                     *
                     *                       connectionOptions.Username = "******";
                     *
                     *                       connectionOptions.Password = @"Simple.0";
                     *                       ManagementScope m_virtualizeScope = new ManagementScope(@"\\Hyper-v9140\root\virtualization", connectionOptions);
                     *                       m_virtualizeScope.Connect();     */
                    String      queryString             = @"SELECT * FROM Msvm_VirtualSystemSettingData WHERE InstanceID like '%" + m_VM_Guid + "%'";
                    ObjectQuery query                   = new ObjectQuery(queryString);
                    ManagementObjectSearcher   searcher = null;
                    ManagementObjectCollection moc      = null;
                    if (m_virtualizeScope != null)
                    {
                        searcher = new ManagementObjectSearcher(m_virtualizeScope, query);
                        moc      = searcher.Get();
                        using (searcher)
                        {
                            resultCode = Lib.ExecuteWqlQuery(m_taskId, searcher, out moc);
                        }
                    }
                    if (m_virtualizev2Scope != null && ResultCodes.RC_SUCCESS != resultCode && ResultCodes.RC_WMI_QUERY_TIMEOUT != resultCode)
                    {
                        searcher = new ManagementObjectSearcher(m_virtualizev2Scope, query);
                        moc      = searcher.Get();
                        using (searcher)
                        {
                            resultCode = Lib.ExecuteWqlQuery(m_taskId, searcher, out moc);
                        }
                    }
                    StringBuilder sbVmInfo = new StringBuilder();
                    String        base_board_serial_number = "";
                    String        bios_guid          = "";
                    String        bios_serial_number = "";
                    String        guid = "";
                    sbVmInfo.Append("<BDNA,A>");
                    if (ResultCodes.RC_SUCCESS == resultCode && null != moc)
                    {
                        using (moc)
                        {
                            foreach (ManagementObject mo in moc)
                            {
                                base_board_serial_number = (String)mo["BaseBoardSerialNumber"];
                                bios_guid          = (String)mo["BIOSGUID"];
                                bios_serial_number = (String)mo["BIOSSerialNumber"];
                                guid = (String)mo["InstanceID"];
                                guid = guid.Replace("Microsoft:", "");
                                guid = guid.Substring(0, 36);
                                sbVmInfo.Append(@"<BDNA,>Guid=""" + guid + @"""<BDNA,1>base_board_serial_number =""" + base_board_serial_number + @"""<BDNA,1>bios_guid=""" + bios_guid + @"""<BDNA,1>bios_serial_number=""" + bios_serial_number + @"""");
                            }

                            //
                            // Package data into CLE format to be returned.
                            if (sbVmInfo.Length > 0)
                            {
                                //       BuildDataRow(s_attributeName, sbVmInfo.ToString());
                                BuildDataRow(s_attributeName, sbVmInfo.ToString());
                            }
                        }
                    }
                }
            }
            catch (ManagementException mex)
            {
                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: ManagementException in HyperV_BiosInfoScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          mex.ToString());
                    resultCode = ResultCodes.RC_PROCESSING_EXCEPTION;
                }
            }
            catch (Exception ex)
            {
                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in HyperV_BiosInfoScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          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 HyperV_BiosInfoScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script HyperV_BiosInfoScript.  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()));
        }
        /// <summary>
        /// Validate running instances
        /// </summary>
        /// <param name="strOracleHomeDir">directory path</param>
        /// <returns>Instance that is running on that installation.</returns>
        private ResultCodes validateOracleRunningInstance(string strOracleHomeDir, out string strInstances)
        {
            string commandLine = @"cmd /q /e:off /C " + strOracleHomeDir.Trim() + @"\BIN\LSNRCTL.EXE status";

            strInstances = null;
            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            try {
                StringBuilder stdoutData = new StringBuilder();
                using (IRemoteProcess rp = RemoteProcess.NewRemoteProcess(
                           m_taskId,                          // Task Id to log against.
                           m_cimvScope,                       // assuming Remote process uses cimv2 management scope
                           commandLine,                       // script supplied command line.
                           null,                              // Optional working directory
                           StdioRedirection.STDOUT,           // Flags for what stdio files you want
                           m_connection,                      // connection dictionary.
                           m_tftpPath,
                           m_tftpPath_login,
                           m_tftpPath_password,
                           m_tftpDispatcher)) {
                    //This method will block until the entire remote process operation completes.
                    resultCode = rp.Launch();
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Remote process operation completed with result code {1}.",
                                          m_taskId,
                                          resultCode.ToString());

                    if (rp != null && rp.Stdout != null && resultCode == ResultCodes.RC_SUCCESS)
                    {
                        strInstances = parseRunningInstances(rp.Stdout.ToString());
                    }
                    else
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Invalid Oracle home: {1}",
                                              m_taskId,
                                              strOracleHomeDir);
                    }
                }
            }
            catch (Exception ex) {
                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in WindowsOracleInstallationDynamicScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          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 WindowsOracleInstallationDynamicScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }
            return(resultCode);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Parse WAS Server Index File.
        /// </summary>
        /// <param name="strFileContent">File Content</param>
        private ResultCodes parseServerIndxFile(string srvIndxContent, string server)
        {
            ResultCodes resultCode = ResultCodes.RC_INSUFFICIENT_PRIVILEGE_TO_READ_REMOTE_FILE;

            if (String.IsNullOrEmpty(srvIndxContent))
            {
                return(resultCode);
            }
            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                  0,
                                  "Task Id {0}: Begin parsing WAS Server Index file.",
                                  m_taskId,
                                  server);
            try
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(srvIndxContent);
                XmlNodeList   nodes    = xDoc.GetElementsByTagName("serverEntries");
                StringBuilder portData = new StringBuilder();
                foreach (XmlNode node in nodes)
                {
                    string sName = node.Attributes["serverName"].Value;
                    string sType = node.Attributes["serverType"].Value;

                    if (string.Equals(server, sName))
                    {
                        StringBuilder st = new StringBuilder();
                        st.Append(sType);
                        BuildDataRow(s_serverType, st);
                        XmlNodeList cNodes = node.ChildNodes;
                        foreach (XmlNode child in cNodes)
                        {
                            if (string.Equals(child.Name, "specialEndpoints"))
                            {
                                StringBuilder pValue  = new StringBuilder();
                                string        pName   = child.Attributes["endPointName"].Value;
                                XmlNodeList   epNodes = child.ChildNodes;
                                foreach (XmlNode ep in epNodes)
                                {
                                    if (string.Equals(ep.Name, "endPoint"))
                                    {
                                        string        pNum = ep.Attributes["port"].Value;
                                        StringBuilder port = new StringBuilder();
                                        port.Append(pNum);
                                        pValue.Append(@"PortName=").Append(pName).Append(@"<BDNA,1>").Append(@"PortNumber=").Append(pNum);

                                        /*if (string.Equals(pName, "WC_defaulthost")) {
                                         *  BuildDataRow(s_port, port);
                                         * } */
                                        if (portData.Length > 0)
                                        {
                                            portData.Append(BdnaDelimiters.DELIMITER_TAG);
                                        }
                                        portData.Append(pValue.ToString());
                                    }
                                }
                            }
                        }

                        if (portData.Length > 0)
                        {
                            BuildDataRow(s_portsUsed, portData);
                        }
                    }
                }
                resultCode = ResultCodes.RC_SUCCESS;
            }
            catch (XmlException xex)
            {
                Lib.LogException(m_taskId,
                                 m_executionTimer,
                                 "Unhandled exception in WindowsWASParseServerIndexScript",
                                 xex);
            }
            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_tftpPath          = tftpPath;
            m_tftpPath_login    = tftpPath_login;
            m_tftpPath_password = tftpPath_password;
            m_tftpDispatcher    = tftpDispatcher;
            m_connection        = connection;
            string strOracleHome = null, validatedInstances = null;

            string[] strRunningInstances = null;

            m_executionTimer = Stopwatch.StartNew();
            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Collection script WindowsOracleInstallationDynamicScript.",
                                  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 WindowsOracleInstallationDynamicScript 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 Oracle Home attribute
                if (!scriptParameters.ContainsKey("OracleHome"))
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing script parameter \"OracleHome\".",
                                          m_taskId);
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                }
                else
                {
                    strOracleHome = scriptParameters["OracleHome"];
                }

                if (!scriptParameters.ContainsKey("runningInstances"))
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Missing script parameter \"runningInstances\".",
                                          m_taskId);
                    resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING;
                }
                else if (!String.IsNullOrEmpty(scriptParameters["runningInstances"]))
                {
                    strRunningInstances = scriptParameters["runningInstances"]
                                          .Split(new String[] { BdnaDelimiters.DELIMITER_TAG }, StringSplitOptions.RemoveEmptyEntries);
                }

                // 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}: Temporary directory {1} has been validated.",
                                                  m_taskId,
                                                  m_connection[@"TemporaryDirectory"].ToString());
                        }
                    }
                }

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    // find all instance from give Oracle installation.
                    string strAllInstance = null;
                    resultCode = validateOracleRunningInstance(strOracleHome, out strAllInstance);
                    if (!String.IsNullOrEmpty(strAllInstance))
                    {
                        validatedInstances = strAllInstance.ToUpper();
                    }

                    //validate given instance with verified instance list.
                    foreach (string strName in strRunningInstances)
                    {
                        string strInstance = BdnaDelimiters.DELIMITER_TAG + strName + BdnaDelimiters.DELIMITER_TAG;
                        if (validatedInstances.Contains(strInstance.ToUpper()))
                        {
                            if (m_outputData.Length > 1)
                            {
                                m_outputData.Append(BdnaDelimiters.DELIMITER_TAG);
                            }
                            m_outputData.Append(strName);
                        }
                    }
                    if (m_outputData.Length > 0)
                    {
                        BuildDataRow("validatedInstances", m_outputData.ToString());
                    }
                }
            }
            catch (Exception ex) {
                if (ResultCodes.RC_SUCCESS == resultCode)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in WindowsOracleInstallationDynamicScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          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 WindowsOracleInstallationDynamicScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsOracleInstallationDynamicScript.  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()));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Connect method invoked by WinCs.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="connectionParameterSets">List of credential sets to use for connecting to the
        ///     remote database server.</param>
        /// <param name="tftpDispatcher">TFTP transfer request listener for dispatching TFTP transfer
        ///     requests.</param>
        ///
        /// <returns>Operation results.</returns>
        public ConnectionScriptResults Connect(
            long taskId,
            IDictionary <string, string>[] connectionParameterSets,
            string tftpPath,
            string tftpPath_login,
            string tftpPath_password,
            ITftpDispatcher tftpDispatcher)
        {
            Stopwatch executionTimer = Stopwatch.StartNew();
            string    taskIdString   = taskId.ToString();

            Lib.Logger.TraceEvent(TraceEventType.Start,
                                  0,
                                  "Task Id {0}: Connection script HyperVConnWincsScript.",
                                  taskIdString);
            ConnectionScriptResults result = null;

            if (null == connectionParameterSets)
            {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Null credential set passed to HyperVConnWincsScript",
                                      taskIdString);
                result = new ConnectionScriptResults(null,
                                                     ResultCodes.RC_NULL_PARAMETER_SET,
                                                     0,
                                                     -1);
            }
            else
            {
                try  {
                    ResultCodes resultCode = ResultCodes.RC_HOST_CONNECT_FAILED;
                    Lib.Logger.TraceEvent(TraceEventType.Information,
                                          0,
                                          "Task Id {0}: Executing HyperVConnWincsScript with {1} credential sets.",
                                          taskIdString,
                                          connectionParameterSets.Length.ToString());
                    IDictionary <string, string>[] orderedConnectionParameterSets = this.reorderCredentials(connectionParameterSets);
                    //
                    // Loop to process credential sets until a successful
                    // WMI connection is made.
                    for (int i = 0;
                         orderedConnectionParameterSets.Length > i;
                         ++i)
                    {
                        ConnectionOptions co = new ConnectionOptions();
                        co.Impersonation    = ImpersonationLevel.Impersonate;
                        co.Authentication   = AuthenticationLevel.Packet;
                        co.Timeout          = Lib.WmiConnectTimeout;
                        co.EnablePrivileges = true;  // @todo configuration

                        string userName = orderedConnectionParameterSets[i][@"userName"];
                        string password = orderedConnectionParameterSets[i][@"password"];

                        if (null != userName && null != password && !("." == userName && "." == password))
                        {
                            co.Username = userName;
                            co.Password = password;
                        }

                        Lib.Logger.TraceEvent(TraceEventType.Information,
                                              0,
                                              "Task Id {0}: Processing credential set {1}: user=\"{2}\".",
                                              taskIdString,
                                              i.ToString(),
                                              userName);

                        if (string.IsNullOrEmpty(userName))
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Information,
                                                  0,
                                                  "Task Id {0}: Unexpected Error: Receiving null username at Credential set {1}: user=\"{2}\".",
                                                  taskIdString,
                                                  i.ToString(),
                                                  userName);
                            continue;
                        }

                        Stopwatch      sw = new Stopwatch();
                        ManagementPath mp = null;

                        try  {
                            string server = orderedConnectionParameterSets[i][@"address"];
                            string domain = string.Empty;
                            if (orderedConnectionParameterSets[i].ContainsKey(@"osWkgrpDomain"))
                            {
                                domain = orderedConnectionParameterSets[i][@"osWkgrpDomain"];
                                if (domain == @"__BDNA_DEFAULT__")
                                {
                                    domain = "";
                                }
                            }
                            Lib.Logger.TraceEvent(TraceEventType.Information,
                                                  0,
                                                  "Task Id {0}: Attempting connection to computer in domain {1}.",
                                                  taskIdString,
                                                  domain);

                            //
                            // Create a scope for the cimv2 namespace.
                            mp               = new ManagementPath();
                            mp.Server        = server;
                            mp.NamespacePath = ManagementScopeNames.CIMV;

                            ManagementScope cimvScope = new ManagementScope(mp, co);
                            Lib.Logger.TraceEvent(TraceEventType.Information,
                                                  0,
                                                  "Task Id {0}: Attempting connection to namespace {1}.",
                                                  taskIdString,
                                                  mp.ToString());
                            sw.Start();
                            cimvScope.Connect();
                            sw.Stop();
                            Debug.Assert(cimvScope.IsConnected);
                            Lib.Logger.TraceEvent(TraceEventType.Information,
                                                  0,
                                                  "Task Id {0}: Connect to {1} succeeded. Elapsed time {2}.",
                                                  taskIdString,
                                                  mp.ToString(),
                                                  sw.Elapsed.ToString());

                            //
                            // Create a scope for the default namespace.
                            mp               = new ManagementPath();
                            mp.Server        = server;
                            mp.NamespacePath = ManagementScopeNames.DEFAULT;

                            ManagementScope defaultScope = new ManagementScope(mp, co);
                            Lib.Logger.TraceEvent(TraceEventType.Information,
                                                  0,
                                                  "Task Id {0}: Attempting connection to namespace {1}.",
                                                  taskIdString,
                                                  mp.ToString());
                            sw.Reset();
                            defaultScope.Connect();
                            sw.Stop();
                            Debug.Assert(defaultScope.IsConnected);
                            Lib.Logger.TraceEvent(TraceEventType.Information,
                                                  0,
                                                  "Task Id {0}: Connect to {1} succeeded. Elapsed time {2}.",
                                                  taskIdString,
                                                  mp.ToString(),
                                                  sw.Elapsed.ToString());

                            ManagementScope tsScope = null;
                            try   {
                                //
                                // Create a scope for the TerminalServices namespace.
                                mp                = new ManagementPath();
                                mp.Server         = server;
                                mp.NamespacePath  = @"root\CIMV2\TerminalServices";
                                co.Authentication = AuthenticationLevel.PacketPrivacy;
                                tsScope           = new ManagementScope(mp, co);
                                Lib.Logger.TraceEvent(TraceEventType.Information,
                                                      0,
                                                      "Task Id {0}: Attempting connection to namespace {1}.",
                                                      taskIdString,
                                                      mp.ToString());
                                sw.Reset();
                                tsScope.Connect();
                                sw.Stop();
                                Lib.Logger.TraceEvent(TraceEventType.Information,
                                                      0,
                                                      "Task Id {0}: Connect to {1} succeeded. Elapsed time {2}.",
                                                      taskIdString,
                                                      mp.ToString(),
                                                      sw.Elapsed.ToString());
                            } catch (Exception ex) {
                                tsScope = null;
                                Lib.LogException(taskIdString,
                                                 sw,
                                                 String.Format("Connect to {0} failed", mp.ToString()),
                                                 ex);
                            }

                            ManagementScope virtualizScope = null;
                            try   {
                                //
                                // Create a scope for the virtualization namespace.
                                mp                = new ManagementPath();
                                mp.Server         = server;
                                mp.NamespacePath  = @"root\virtualization";
                                co.Authentication = AuthenticationLevel.PacketPrivacy;
                                virtualizScope    = new ManagementScope(mp, co);
                                Lib.Logger.TraceEvent(TraceEventType.Information,
                                                      0,
                                                      "Task Id {0}: Attempting connection to namespace {1}.",
                                                      taskIdString,
                                                      mp.ToString());
                                sw.Reset();
                                virtualizScope.Connect();
                                sw.Stop();
                                Lib.Logger.TraceEvent(TraceEventType.Information,
                                                      0,
                                                      "Task Id {0}: Connect to {1} succeeded. Elapsed time {2}.",
                                                      taskIdString,
                                                      mp.ToString(),
                                                      sw.Elapsed.ToString());
                            }   catch (Exception ex)   {
                                virtualizScope = null;
                                Lib.LogException(taskIdString,
                                                 sw,
                                                 String.Format("Connect to {0} failed", mp.ToString()),
                                                 ex);
                            }


                            ManagementScope virtualizv2Scope = null;
                            try   {
                                //
                                // Create a scope for the virtualization\v2 namespace.
                                mp                = new ManagementPath();
                                mp.Server         = server;
                                mp.NamespacePath  = @"root\virtualization\v2";
                                co.Authentication = AuthenticationLevel.PacketPrivacy;
                                virtualizv2Scope  = new ManagementScope(mp, co);
                                Lib.Logger.TraceEvent(TraceEventType.Information,
                                                      0,
                                                      "Task Id {0}: Attempting connection to namespace {1}.",
                                                      taskIdString,
                                                      mp.ToString());
                                sw.Reset();
                                virtualizv2Scope.Connect();
                                sw.Stop();
                                Lib.Logger.TraceEvent(TraceEventType.Information,
                                                      0,
                                                      "Task Id {0}: Connect to {1} succeeded. Elapsed time {2}.",
                                                      taskIdString,
                                                      mp.ToString(),
                                                      sw.Elapsed.ToString());
                            }   catch (Exception ex)   {
                                virtualizv2Scope = null;
                                Lib.LogException(taskIdString,
                                                 sw,
                                                 String.Format("Connect to {0} failed", mp.ToString()),
                                                 ex);
                            }

                            // We have everything we need.  Create a dictionary
                            // to return as the "connection" and get out of
                            // loop.
                            Dictionary <string, object> connectionDic = new Dictionary <string, object>();
                            foreach (KeyValuePair <string, string> kvp in orderedConnectionParameterSets[i])
                            {
                                connectionDic.Add(kvp.Key, kvp.Value);
                            }
                            connectionDic[@"cimv2"]   = cimvScope;
                            connectionDic[@"default"] = defaultScope;
                            if (tsScope != null)
                            {
                                connectionDic[@"TerminalServices"] = tsScope;
                            }
                            if (virtualizScope != null)
                            {
                                connectionDic[@"virtualization"] = virtualizScope;
                            }
                            if (virtualizv2Scope != null)
                            {
                                connectionDic[@"v2"] = virtualizv2Scope;
                            }
                            result = new ConnectionScriptResults(connectionDic,
                                                                 ResultCodes.RC_SUCCESS,
                                                                 0,
                                                                 i);
                            break;
                        }   catch (ManagementException me)   {
                            if (ManagementStatus.AccessDenied == me.ErrorCode)
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Error,
                                                      0,
                                                      "Task Id {0}: Connect to {1} failed.  Elapsed time {2}.\nWMI Error Code {3}",
                                                      taskIdString,
                                                      mp.ToString(),
                                                      sw.Elapsed.ToString(),
                                                      me.ErrorCode.ToString());
                                resultCode = ResultCodes.RC_LOGIN_FAILED;
                            }
                            else
                            {
                                Lib.LogManagementException(taskIdString,
                                                           sw,
                                                           String.Format("Connect to {0} failed.", mp.ToString()),
                                                           me);
                                //break ;
                            }
                        }    catch (UnauthorizedAccessException uae)   {
                            Lib.Logger.TraceEvent(TraceEventType.Error,
                                                  0,
                                                  "Task Id {0}: Connect to {1} failed.  Elapsed time {2}.\nMessage: {3}.",
                                                  taskIdString,
                                                  mp.ToString(),
                                                  sw.Elapsed.ToString(),
                                                  uae.Message);
                            resultCode = ResultCodes.RC_LOGIN_FAILED;
                        }   catch (COMException ce)   {
                            if (0x800706BA == (UInt32)ce.ErrorCode)
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Error,
                                                      0,
                                                      "Task Id {0}: Connect to {1} failed.  Elapsed time {2}.\nCOM Exception {3}.\n" +
                                                      "WMI port (135) may be closed or DCOM may not be properly configured",
                                                      taskIdString,
                                                      mp.ToString(),
                                                      sw.Elapsed.ToString(),
                                                      ce.Message);
                            }
                            else if (0x80040154 == (UInt32)ce.ErrorCode)
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Error,
                                                      0,
                                                      "Task Id {0}: Connect to {1} failed.  Elapsed time {2}.\nCOM Exception {3}.\n" +
                                                      "WMI Management Class not registered. WMI provider not found on the remote machine.",
                                                      taskIdString,
                                                      mp.ToString(),
                                                      sw.Elapsed.ToString(),
                                                      ce.Message);
                            }
                            else
                            {
                                Lib.LogException(taskIdString,
                                                 sw,
                                                 String.Format("Connect to {0} failed", mp.ToString()),
                                                 ce);
                            }
                        }   catch (Exception ex)   {
                            Lib.LogException(taskIdString,
                                             sw,
                                             String.Format("Connect to {0} failed", mp.ToString()),
                                             ex);
                        }
                    }

                    //
                    // Connect failed after all credentials attempted.
                    if (null == result)
                    {
                        result = new ConnectionScriptResults(null,
                                                             resultCode,
                                                             0,
                                                             orderedConnectionParameterSets.Length);
                    }
                }   catch (Exception e)   {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in HyperVConnWincsScript.\n{1}",
                                          taskIdString,
                                          e.ToString());

                    //
                    // This is really an unanticipated fail safe.  We're
                    // going to report that *no* credentials were tried, which
                    // actually may not be true...
                    result = new ConnectionScriptResults(null,
                                                         ResultCodes.RC_PROCESSING_EXCEPTION,
                                                         0,
                                                         -1);
                }
            }

            Debug.Assert(null != result);
            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Connection script HyperVConnWincsScript.  Elapsed time {1}.  Result code {2}.",
                                  taskIdString,
                                  executionTimer.Elapsed.ToString(),
                                  result.ResultCode.ToString());
            return(result);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Creates a Process Result with the provided Result Code
 /// </summary>
 /// <param name="resultCode"></param>
 public ProcessResult(ResultCodes resultCode)
 {
     ResultCode = resultCode;
 }
Ejemplo n.º 21
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_connection        = connection;
            m_executionTimer    = Stopwatch.StartNew();

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

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

                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    /*                         ConnectionOptions connectionOptions = new ConnectionOptions();
                     *
                     *                       connectionOptions.Username = "******";
                     *
                     *                       connectionOptions.Password = @"Simple.0";
                     *                       ManagementScope m_virtualizeScope = new ManagementScope(@"\\Hyper-v9140\root\virtualization", connectionOptions);
                     *                       m_virtualizeScope.Connect();     */
                    ObjectQuery query = new ObjectQuery("SELECT * FROM MsVM_ComputerSystem WHERE Caption LIKE 'Virtual%' ");
                    ManagementObjectSearcher   searcher = null;
                    ManagementObjectCollection moc      = null;
                    if (m_virtualizeScope != null)
                    {
                        searcher = new ManagementObjectSearcher(m_virtualizeScope, query);
                        moc      = searcher.Get();
                        using (searcher)
                        {
                            resultCode = Lib.ExecuteWqlQuery(m_taskId, searcher, out moc);
                        }
                    }
                    if (m_virtualizev2Scope != null && ResultCodes.RC_SUCCESS != resultCode && ResultCodes.RC_WMI_QUERY_TIMEOUT != resultCode)
                    {
                        searcher = new ManagementObjectSearcher(m_virtualizev2Scope, query);
                        moc      = searcher.Get();
                        using (searcher)
                        {
                            resultCode = Lib.ExecuteWqlQuery(m_taskId, searcher, out moc);
                        }
                    }
                    StringBuilder sbVmInfo        = new StringBuilder();
                    long          runningVMsCount = 0;
                    if (ResultCodes.RC_SUCCESS == resultCode && null != moc)
                    {
                        using (moc)
                        {
                            foreach (ManagementObject mo in moc)
                            {
                                sbVmInfo.Append("<BDNA,>");
                                sbVmInfo.Append(@"ElementName=""" + mo.GetPropertyValue("ElementName").ToString() + @"""");
                                sbVmInfo.Append("<BDNA,1>");
                                sbVmInfo.Append(@"UpTime=""" + mo.GetPropertyValue("OnTimeInMilliseconds").ToString() + @"""");
                                sbVmInfo.Append("<BDNA,1>");
                                sbVmInfo.Append(@"GUID=""" + mo.GetPropertyValue("Name").ToString() + @"""");
                                sbVmInfo.Append("<BDNA,1>");
                                String state = mo.GetPropertyValue("EnabledState").ToString();

                                if (state.Equals(Convert.ToString(0)))
                                {
                                    state = "Unknown";
                                }
                                else if (state.Equals(Convert.ToString(2)))
                                {
                                    state = "Enabled";
                                    runningVMsCount++;
                                }
                                else if (state.Equals(Convert.ToString(3)))
                                {
                                    state = "Disabled";
                                }
                                else if (state.Equals(Convert.ToString(32768)))
                                {
                                    state = "Paused";
                                }
                                else if (state.Equals(Convert.ToString(32769)))
                                {
                                    state = "Suspended";
                                }
                                else if (state.Equals(Convert.ToString(32770)))
                                {
                                    state = "Starting";
                                }
                                else if (state.Equals(Convert.ToString(32771)))
                                {
                                    state = "Snapshotting";
                                }
                                else if (state.Equals(Convert.ToString(32773)))
                                {
                                    state = "Saving";
                                }
                                else if (state.Equals(Convert.ToString(32774)))
                                {
                                    state = "Stopping";
                                }
                                else if (state.Equals(Convert.ToString(32776)))
                                {
                                    state = "Pausing";
                                }
                                else if (state.Equals(Convert.ToString(32777)))
                                {
                                    state = "Resuming";
                                }
                                sbVmInfo.Append(@"State=""" + state + @"""");
                            }
                            sbVmInfo.Append("<BDNA,C>");
                            sbVmInfo.Append(@"runningVMsCount=""" + runningVMsCount + @"""");
                            sbVmInfo.Append("<BDNA,C>");


                            //                     Console.WriteLine(sbVmInfo);
                            //                    System.IO.File.WriteAllText("d:\\testscript.txt", sbVmInfo.ToString());


                            //
                            // Package data into CLE format to be returned.
                            if (sbVmInfo.Length > 0)
                            {
                                //       BuildDataRow(s_attributeName, sbVmInfo.ToString());
                                BuildDataRow(s_attributeName, sbVmInfo.ToString());
                            }
                        }
                    }
                }
            }
            catch (ManagementException mex)
            {
                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: no configuration files(c:\\programdata\\microsoft\\windows\\hyper-v\\virtual machines\\*.xml) in exception in HyperV_VMStateScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          mex.ToString());
                    resultCode = ResultCodes.RC_PROCESSING_EXCEPTION;
                }
            }
            catch (Exception ex)
            {
                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in HyperV_VMStateScript.  Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.",
                                          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 HyperV_VMStateScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script HyperV_VMStateScript.  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()));
        }
Ejemplo n.º 22
0
 public ResultCodeException(ResultCodes code, params (string language, string message)[] errormessages)
Ejemplo n.º 23
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 WinFilePropertiesScript.",
                                  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 RSOPPropertiesScriptis 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 (resultCode == ResultCodes.RC_SUCCESS)
                {
                    string collectedData = string.Empty;

                    resultCode = ExecuteCommand(GPO_COMMAND_R, out collectedData);
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Command GPRESULT /R executed with result <{1}>",
                                          m_taskId,
                                          collectedData);

                    Match matchInvalidArg1 = null, matchInvalidArg2 = null, matchInvalidCmd = null;
                    if (!string.IsNullOrEmpty(collectedData))
                    {
                        matchInvalidArg1 = s_invalidArgumentRegex.Match(collectedData);
                        matchInvalidArg2 = s_invalidArgument2Regex.Match(collectedData);
                        matchInvalidCmd  = s_invalidCommandRegex.Match(collectedData);

                        if (matchInvalidArg1.Success || matchInvalidArg2.Success || matchInvalidCmd.Success)
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Error,
                                                  0,
                                                  "Task Id {0}: Command GPRESULT /R failed <{1}>",
                                                  m_taskId,
                                                  collectedData);
                            collectedData = string.Empty;
                            resultCode    = ExecuteCommand(GPO_COMMAND, out collectedData);
                            Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                                  0,
                                                  "Task Id {0}: Command GPRESULT executed with result <{1}>",
                                                  m_taskId,
                                                  collectedData);
                        }
                        if (!string.IsNullOrEmpty(collectedData))
                        {
                            matchInvalidArg1 = s_invalidArgumentRegex.Match(collectedData);
                            matchInvalidArg2 = s_invalidArgument2Regex.Match(collectedData);
                            matchInvalidCmd  = s_invalidCommandRegex.Match(collectedData);
                            if (matchInvalidArg1.Success || matchInvalidArg2.Success || matchInvalidCmd.Success)
                            {
                                Lib.Logger.TraceEvent(TraceEventType.Error,
                                                      0,
                                                      "Task Id {0}: Command GPRESULT /R failed <{1}>",
                                                      m_taskId,
                                                      collectedData);
                                collectedData = string.Empty;
                            }
                            else
                            {
                                string header = string.Empty, computerSettings = string.Empty, userSettings = string.Empty;
                                if (collectedData.Contains(COMPUTER_SETTINGS))
                                {
                                    int headerIndex      = collectedData.IndexOf(COMPUTER_SETTINGS);
                                    int userSettingIndex = collectedData.IndexOf(USER_SETTINGS);
                                    header           = collectedData.Substring(0, headerIndex);
                                    computerSettings = collectedData.Substring(0, userSettingIndex);
                                    userSettings     = header + collectedData.Substring(userSettingIndex, collectedData.Length - userSettingIndex);
                                }
                                else if (collectedData.Contains(USER_GROUP_POLICY))
                                {
                                    int headerIndex          = collectedData.IndexOf(USER_GROUP_POLICY);
                                    int computerSettingIndex = collectedData.IndexOf(COMPUTER_GROUP_POLICY);
                                    int userSettingIndex     = collectedData.IndexOf(USER_GROUP_POLICY);
                                    header           = collectedData.Substring(0, userSettingIndex);
                                    computerSettings = header + collectedData.Substring(computerSettingIndex);
                                    userSettings     = collectedData.Substring(0, computerSettingIndex);
                                }

                                if (string.IsNullOrEmpty(computerSettings) && !string.IsNullOrEmpty(collectedData))
                                {
                                    computerSettings = collectedData;
                                }
                                BuildDataRow(@"rsopComputerSettings", computerSettings);
                                BuildDataRow(@"rsopUserSettings", userSettings);
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in WinFilePropertiesScript.  Elapsed time {1}.\nResult code changed to RC_PROCESSING_EXCEPTION.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex);
                    resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR;
                }
                else
                {
                    Lib.LogException(m_taskId,
                                     m_executionTimer,
                                     "Unhandled exception in WinFilePropertiesScript",
                                     ex);
                }
                BuildDataRow(@"fileProperties", @"NotFound");
                resultCode = ResultCodes.RC_SUCCESS;
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WinFilePropertiesScript.  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()));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Validate Oracle installation
        /// </summary>
        /// <param name="strOracleHomeDir">directory path</param>
        /// <returns>version of validated oracle installation, null if error.</returns>
        private ResultCodes validateOracleInstallation(string strOracleHomeDir, out string strVersion)
        {
            strVersion = null;
            ResultCodes resultCode  = ResultCodes.RC_SUCCESS;
            string      commandLine = @"cmd /q /e:off /C " + strOracleHomeDir + @"\BIN\SQLPLUS -V";

            try {
                using (IRemoteProcess rp = RemoteProcess.NewRemoteProcess(
                           m_taskId,                           // Task Id to log against.
                           m_cimvScope,                        // assuming Remote process uses cimv2 management scope
                           commandLine,                        // script supplied command line.
                           null,                               // Optional working directory
                           StdioRedirection.STDOUT,            // Flags for what stdio files you want
                           m_connection,                       // Data to pass for stdin.
                           m_tftpPath,
                           m_tftpPath_login,
                           m_tftpPath_password,
                           m_tftpDispatcher)) {
                    resultCode = rp.Launch();
                    Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                          0,
                                          "Task Id {0}: Remote process operation completed with result code {1}.",
                                          m_taskId,
                                          resultCode.ToString());

                    if (rp != null && rp.Stdout.Length > 0 && resultCode == ResultCodes.RC_SUCCESS)
                    {
                        strVersion = parseOracleHomeVersion(rp.Stdout.ToString());
                    }
                    else
                    {
                        Lib.Logger.TraceEvent(TraceEventType.Error,
                                              0,
                                              "Task Id {0}: Execution error with SQLPLUS -V\n{1}",
                                              m_taskId,
                                              rp.Stdout.ToString());
                    }
                }
            }
            catch (Exception ex) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Executing command <{1}> resulted in an exception.\n{2}",
                                      m_taskId,
                                      commandLine,
                                      ex.ToString());
            }


            // Try svrmgrl for earlier release of Oracle.
            try {
                if (String.IsNullOrEmpty(strVersion))
                {
                    commandLine = @"cmd /q /e:off /C " + strOracleHomeDir + @"\BIN\SVRMGRL -?";
                    using (IRemoteProcess rp = RemoteProcess.NewRemoteProcess(
                               m_taskId,                        // Task Id to log against.
                               m_cimvScope,                     // assuming Remote process uses cimv2 management scope
                               commandLine,                     // script supplied command line.
                               null,                            // Optional working directory
                               StdioRedirection.STDOUT,         // Flags for what stdio files you want
                               m_connection,                    // Data to pass for stdin.
                               m_tftpPath,
                               m_tftpPath_login,
                               m_tftpPath_password,
                               m_tftpDispatcher)) {
                        resultCode = rp.Launch();
                        Lib.Logger.TraceEvent(TraceEventType.Verbose,
                                              0,
                                              "Task Id {0}: Remote process operation completed with result code {1}.",
                                              m_taskId,
                                              resultCode.ToString());

                        if (rp != null && rp.Stdout.Length > 0 && resultCode == ResultCodes.RC_SUCCESS)
                        {
                            strVersion = parseOracleHomeVersionEarlierRelease(rp.Stdout.ToString());
                        }
                        else
                        {
                            Lib.Logger.TraceEvent(TraceEventType.Error,
                                                  0,
                                                  "Task Id {0}: Execution error with SVRMGRL -?\n{1}",
                                                  m_taskId,
                                                  rp.Stdout.ToString());
                        }
                    }
                }
            }
            catch (Exception ex) {
                Lib.Logger.TraceEvent(TraceEventType.Error,
                                      0,
                                      "Task Id {0}: Executing command <{1}> resulted in an exception.\n{2}",
                                      m_taskId,
                                      commandLine,
                                      ex.ToString());
            }
            return(resultCode);
        }