/// <summary> /// Execute an arbitrary command remotely. /// </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_executionTimer = Stopwatch.StartNew(); string commandLine = string.Empty; //string returnAttribute = null; string returnAttribute = string.Empty; ResultCodes resultCode = ResultCodes.RC_PROCESSING_EXCEPTION; Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script Extend_IBM_WindowsWebSphereMQ_Server_QueueManagerStatic_script.", 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 Extend_IBM_WindowsWebSphereMQ_Server_QueueManagerStatic_script 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); } // We have to massage the script parameter set, replace // any keys with a colon by just the part after the colon. Dictionary <string, string> d = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> kvp in scriptParameters) { string[] sa = kvp.Key.Split(s_collectionParameterSetDelimiter, StringSplitOptions.RemoveEmptyEntries); Debug.Assert(sa.Length > 0); d[sa[sa.Length - 1]] = kvp.Value; } scriptParameters = d; //Check input parameter and set what output attribute to return if (scriptParameters.ContainsKey("qmDisplayData_commandLine")) { commandLine = scriptParameters[@"qmDisplayData_commandLine"]; returnAttribute = "qmDisplayData"; } else if (scriptParameters.ContainsKey("channelsStatus_commandLine")) { commandLine = scriptParameters[@"channelsStatus_commandLine"]; returnAttribute = "channelsStatus"; } else if (scriptParameters.ContainsKey("channelsDisplayData_commandLine")) { commandLine = scriptParameters[@"channelsDisplayData_commandLine"]; returnAttribute = "channelsDisplayData"; } else if (scriptParameters.ContainsKey("queuesDisplayData_commandLine")) { commandLine = scriptParameters[@"queuesDisplayData_commandLine"]; returnAttribute = "queuesDisplayData"; } else if (scriptParameters.ContainsKey("channelDetailDisplayData_commandLine")) { commandLine = scriptParameters[@"channelDetailDisplayData_commandLine"]; returnAttribute = "channelDetailDisplayData"; } else if (scriptParameters.ContainsKey("queueDetailDisplayData_commandLine")) { commandLine = scriptParameters[@"queueDetailDisplayData_commandLine"]; returnAttribute = "queueDetailDisplayData"; } else { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing script parameter.", m_taskId); } //Check commandLine parameter //if (!scriptParameters.ContainsKey("commandLine")) if (string.IsNullOrEmpty(commandLine)) { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing command Line parameter.", m_taskId); } else { // Both Working directory and temporary need to be collected as part of Windows Credential. // BUG 14064 has been filed to track this problem. // Check working and temporary directory parameter if (!connection.ContainsKey(@"WorkingDirectory") || string.IsNullOrEmpty(connection[@"WorkingDirectory"].ToString())) { connection[@"WorkingDirectory"] = @"%TMP%"; } if (!connection.ContainsKey(@"TemporaryDirectory") || string.IsNullOrEmpty(connection[@"TemporaryDirectory"].ToString())) { connection[@"TemporaryDirectory"] = @"%TMP%"; } Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempting to retrieve command output {1}.", m_taskId, commandLine); String batchFileContent = this.BuildBatchFile(connection[@"WorkingDirectory"].ToString(), commandLine); String collectedData = ""; using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile( m_taskId, // Task Id to log against. cimvScope, // assuming Remote process uses cimv2 management scope batchFileContent, // batch file connection, // connection dictionary. 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}: Batch file executed completed with result code {1}.", m_taskId, resultCode.ToString()); if (resultCode == ResultCodes.RC_SUCCESS) { collectedData = rp.Stdout.ToString(); if (string.IsNullOrEmpty(collectedData)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Script completed sucessfully with no data to return.", m_taskId); resultCode = ResultCodes.RC_PROCESSING_EXCEPTION; } else if (!collectedData.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. Partial result: {1}", m_taskId, collectedData); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else { collectedData = collectedData.Substring(0, collectedData.Length - @"Execution completed.\r\n".Length); string strFormattedString = this.formatCommandResult(collectedData.ToString()); m_outputData.Append(elementId).Append(',') //.Append(attributes[@"commandResult"]).Append(',') .Append(attributes[returnAttribute]).Append(',') .Append(scriptParameters[@"CollectorId"]).Append(',') .Append(m_taskId).Append(',') .Append(databaseTimestamp + m_executionTimer.ElapsedMilliseconds).Append(',') .Append(returnAttribute).Append(',') //.Append(BdnaDelimiters.BEGIN_TAG).Append(collectedData).Append(BdnaDelimiters.END_TAG); .Append(BdnaDelimiters.BEGIN_TAG).Append(strFormattedString ).Append(BdnaDelimiters.END_TAG); } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Error during command execution. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode); } } } } } catch (Exception ex) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in Extend_IBM_WindowsWebSphereMQ_Server_QueueManagerStatic_script. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script Extend_IBM_WindowsWebSphereMQ_Server_QueueManagerStatic_script. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode); return(new CollectionScriptResults (resultCode, 0, null, null, null, false, m_outputData.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_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 WindowsOracleInstanceLMSOptions3StaticScript.", 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 WindowsOracleInstanceLMSOptions3StaticScript 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("version")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing script parameter \"version\".", m_taskId); resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; } else { m_strVersion = scriptParameters["version"].Trim(); } 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 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()); } this.processLabelSecurityCollectedData(); if (!ver8_pattern.IsMatch(m_strVersion)) { this.processDatabaseVaultCollectedData(); this.processAuditVaultCollectedData(); } foreach (KeyValuePair <string, string> kvp in m_collectedData) { this.BuildDataRow(kvp.Key, kvp.Value); } } } } catch (Exception ex) { if (ResultCodes.RC_SUCCESS == resultCode) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsOracleInstanceLMSOptions3StaticScript. 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 WindowsOracleInstanceLMSOptions3StaticScript. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); } } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script WindowsOracleInstanceLMSOptions3StaticScript. 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> /// Execute nslookup command remotely. /// </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 WindowsWASHostsLookupScript.", 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 WindowsWASHostsLookupScript 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); } } //Check script parameter if (!scriptParameters.ContainsKey("hostsToLookup")) { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing parameter hostsToLookup.", m_taskId); } else { m_hostsToLookup = scriptParameters[@"hostsToLookup"]; } // Check Remote Process Temp Directory 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}: Temporary directory {1} has been validated.", m_taskId, connection[@"TemporaryDirectory"].ToString()); } } } if (resultCode == ResultCodes.RC_SUCCESS) { StringBuilder val = new StringBuilder(); String[] hosts = m_hostsToLookup.Split(','); foreach (string host in hosts) { StringBuilder commandLine = new StringBuilder(); if (val.ToString().Length != 0) { val.Append(@"<BDNA,>"); } val.Append(host).Append(@"<BDNA,1>"); commandLine.Append(@"nslookup ").Append(host); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempting to retrieve command output {1}.", m_taskId, commandLine); String collectedData = ""; using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile( m_taskId, // Task Id to log against. cimvScope, // assuming Remote process uses cimv2 management scope commandLine.ToString(), // batch file connection, // connection dictionary. 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}: Batch file executed completed with result code {1}.", m_taskId, resultCode.ToString()); collectedData = rp.Stdout.ToString(); if (string.IsNullOrEmpty(collectedData)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Script completed sucessfully with no data to return.", m_taskId); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else { string[] collectedDataArr = collectedData.Split("\r\n".ToCharArray()); bool flag = false; for (int i = 0; i < collectedDataArr.Length; i++) { string output = collectedDataArr[i]; if (s_nameRegex.IsMatch(output)) { Match match = s_nameRegex.Match(output); string name = match.Groups["name"].ToString(); val.Append(@"DBHost_DNSHostName=").Append(name); flag = true; } if ((s_addrRegex.IsMatch(output)) && (flag)) { Match match = s_addrRegex.Match(output); string addr = match.Groups["address"].ToString(); val.Append(@"<BDNA,1>DBHost_IPAddr=").Append(addr); } } } } } m_dataRow.Append(m_elementId).Append(',') .Append(m_attributes["lookedUpHosts"]).Append(',') .Append(m_scriptParameters["CollectorId"]).Append(',') .Append(m_taskId).Append(',') .Append(m_databaseTimestamp + m_executionTimer.ElapsedMilliseconds).Append(',') .Append("lookedUpHosts").Append(',') .Append(BdnaDelimiters.BEGIN_TAG).Append(val).Append(BdnaDelimiters.END_TAG); } } catch (Exception ex) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsWASHostsLookupScript. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script WindowsWASHostsLookupScript. Elapsed time {1}. Result code {2}.", m_taskId, m_executionTimer.Elapsed.ToString(), resultCode); return(new CollectionScriptResults (resultCode, 0, null, null, null, false, m_dataRow.ToString())); }
/// <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}: Remote process operation 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}: Remote processExec completed with result <{1}>.", m_taskId, rp.Stdout.ToString()); collectedData = rp.Stdout.ToString(); //string output = 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(); Stopwatch executionTimer = Stopwatch.StartNew(); ResultCodes resultCode = ResultCodes.RC_SUCCESS; StringBuilder dataRow = new StringBuilder(); Lib.Logger.TraceEvent(TraceEventType.Start, 0, "Task Id {0}: Collection script WindowsSiebelServerDataCollectionScript.", 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 WindowsSiebelServerDataCollectionScript 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); } } // // Check Siebel Credential if (resultCode == ResultCodes.RC_SUCCESS) { string[] connectionVariables = new String[] { @"SiebelUserName", @"SiebelUserPassword", @"TemporaryDirectory", @"siebelSrvrmgrPath" }; resultCode = this.ValidateConnectionParameters(connection, connectionVariables); } // // Check Parameter variables. if (resultCode == ResultCodes.RC_SUCCESS) { string[] paramVariables = new String[] { @"installDirectory", @"gatewayServerName", @"serverName", @"enterpriseName", @"siebelServerCommand" }; resultCode = this.ValidateScriptParameters(scriptParameters, paramVariables); } // // Check Temporary Directory string tempDir = connection[@"TemporaryDirectory"].ToString(); resultCode = this.ValidateTemporaryDirectory(cimvScope, ref tempDir); // Execute Siebel Command string strBatchFileContent = BuildBatchFile(connection[@"siebelSrvrmgrPath"].ToString(), scriptParameters[@"gatewayServerName"], scriptParameters[@"serverName"], scriptParameters[@"enterpriseName"], connection[@"SiebelUserName"].ToString(), connection[@"SiebelUserPassword"].ToString(), scriptParameters[@"siebelServerCommand"], scriptParameters[@"outputDisplayColumns"]); string stdout = null; using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile (taskId.ToString(), 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) { if (rp.Stdout != null && rp.Stdout.Length > 0) { stdout = rp.Stdout.ToString(); string commandOutput = null; if (!stdout.Contains(@"Execution completed")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Data 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 { // // package command output result. if (ResultCodes.RC_SUCCESS == ParseCommandOutput(stdout, scriptParameters[@"siebelServerCommand"], scriptParameters[@"outputDisplayColumns"], out commandOutput)) { if (!attributes.ContainsKey(s_returnAttribute)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Attribute \"{1}\" missing from attributeSet.", m_taskId, s_returnAttribute); } else { dataRow.Append(elementId).Append(',') .Append(attributes[s_returnAttribute]).Append(',') .Append(scriptParameters[@"CollectorId"]).Append(',') .Append(taskId).Append(',') .Append(databaseTimestamp + executionTimer.ElapsedMilliseconds).Append(',') .Append(s_returnAttribute).Append(',') .Append(BdnaDelimiters.BEGIN_TAG).Append(commandOutput).Append(BdnaDelimiters.END_TAG); } } } } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: No data returned.\nResult code changed to RC_PROCESSING_EXCEPTION.", taskId.ToString()); 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()); } } //// post processing?? //if (resultCode == ResultCodes.RC_SUCCESS && string.IsNullOrEmpty( > 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 WindowsSiebelServerDataCollectionScript. Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId, executionTimer.Elapsed.ToString(), ex.ToString()); resultCode = ResultCodes.RC_PROCESSING_EXCEPTION; } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsSiebelServerDataCollectionScript. Elapsed time {1}.\n{2}", m_taskId, executionTimer.Elapsed.ToString(), ex.ToString()); } } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script WindowsSiebelServerDataCollectionScript. Elapsed time {1}. Result code {2}.", m_taskId, executionTimer.Elapsed.ToString(), resultCode.ToString()); return(new CollectionScriptResults(resultCode, 0, null, null, null, false, 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_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 WindowsWASIsInstanceRunningScript.", 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 WindowsWASIsInstanceRunningScript 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); } } //Check WAS Profile path attribute if (!scriptParameters.ContainsKey("installDirectory")) { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing Profile Path Script parameter.", m_taskId); } else { m_installHome = scriptParameters[@"installDirectory"]; } //Check Server Name attribute if (!scriptParameters.ContainsKey("appsrv_Name")) { resultCode = ResultCodes.RC_SCRIPT_PARAMETER_MISSING; Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Missing Server Name script parameter.", m_taskId); } else { m_server = scriptParameters[@"appsrv_Name"]; } // Check Remote Process Temp Directory 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}: Temporary directory {1} has been validated.", m_taskId, connection[@"TemporaryDirectory"].ToString()); } } } if (resultCode == ResultCodes.RC_SUCCESS) { // EXTRA code for wsadmin string strTempDir = connection["TemporaryDirectory"].ToString().Trim(); if (strTempDir.EndsWith(@"\")) { strTempDir = strTempDir.Substring(0, strTempDir.Length - 1); } string running = "False"; //string batchFile = m_profilePath.Trim() + @"\bin\serverStatus.bat " + m_server + @" -user bdna -password bdna"; string s1 = m_installHome.Trim(); string s2 = s1.Replace(" ", "^ "); string batchFile = s2 + @"\bin\serverStatus.bat " + m_server; //Console.WriteLine(batchFile); using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile(m_taskId, cimvScope, batchFile.ToString(), 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()); string[] arrOutputLine = rp.Stdout.ToString().Split("\r\n".ToCharArray()); for (int i = 0; i < arrOutputLine.Length; i++) { string output = arrOutputLine[i]; if (s_instanceRegex.IsMatch(output)) { Match match = s_instanceRegex.Match(output); string name = match.Groups["server"].ToString(); if (string.Equals(m_server, name)) { running = "True"; } } } } //Console.WriteLine(running); m_dataRow.Append(m_elementId).Append(',') .Append(m_attributes["appSrv_isRunning"]).Append(',') .Append(m_scriptParameters["CollectorId"]).Append(',') .Append(m_taskId).Append(',') .Append(m_databaseTimestamp + m_executionTimer.ElapsedMilliseconds).Append(',') .Append("appSrv_isRunning").Append(',') .Append(BdnaDelimiters.BEGIN_TAG).Append(running).Append(BdnaDelimiters.END_TAG); } } catch (Exception ex) { if (ResultCodes.RC_SUCCESS == resultCode) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsWASIsInstanceRunningScript. Elapsed time {1}.\n{2}\nResult code changed to RC_PROCESSING_EXCEPTION.", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Unhandled exception in WindowsWASIsInstanceRunningScript. Elapsed time {1}.\n{2}", m_taskId, m_executionTimer.Elapsed.ToString(), ex.ToString()); } } Lib.Logger.TraceEvent(TraceEventType.Stop, 0, "Task Id {0}: Collection script WindowsWASIsInstanceRunningScript. 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> /// Spawn a remote process to execute the L3 validation /// batch file and process the results. /// </summary> /// /// <param name="scope">WMI connection to target host.</param> /// <param name="batchFile">Batch file contents to execute.</param> /// <param name="schemaName">Schema name to validate.</param> /// <param name="scriptParameters">Script parameters to use (contains temporary directory /// parameter).</param> /// <param name="tftpDispatcher">TFTP dispatcher singleton.</param> /// /// <returns>Operation result code.</returns> private ResultCodes ExecuteRemoteProcess( ManagementScope scope, string batchFile, string schemaName, IDictionary <string, object> scriptParameters, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { ResultCodes resultCode = ResultCodes.RC_SUCCESS; string stdout = String.Empty; Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempt to establish L3 connection using {1}.", m_taskId, schemaName); using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile(m_taskId, scope, batchFile, scriptParameters, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) { Stopwatch sw = Stopwatch.StartNew(); resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote process operation completed with result code {1}. Elapsed time {2}.", m_taskId, resultCode.ToString(), sw.Elapsed.ToString()); stdout = rp.Stdout.ToString(); if (ResultCodes.RC_SUCCESS == resultCode) { if (null != stdout && 0 < stdout.Length) { if (stdout.Contains("ORA-01017")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Oracle L3 credential invalid.\nResult code changed to RC_PROCESSING_EXCEPTION.\nSTDOUT/STDERR:\n{1}", m_taskId, stdout); resultCode = ResultCodes.RC_HOST_CONNECT_FAILED; } else if (stdout.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, stdout); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else if (!stdout.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, stdout); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } else if (!stdout.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.\n{1}", m_taskId, stdout); } } if (ResultCodes.RC_SUCCESS == resultCode) { // // If we didn't get the output expected from execution // of the batch file. Force the result code to some // error value so that we try the next credential set. if (0 >= stdout.Length || !s_bdnaRegex.IsMatch(stdout)) { resultCode = ResultCodes.RC_LOGIN_FAILED; // @todo Did login really fail? Perhaps this s/b processing exception } } return(resultCode); }
/// <summary> /// Spawn a remote process to execute a simple command remotely to ensure success of collction. /// </summary> /// /// <param name="scope">WMI connection to target host.</param> /// <param name="tftpDispatcher">TFTP dispatcher singleton.</param> /// /// <returns>Operation result code.</returns> private ResultCodes ExecuteRemoteProcess( ManagementScope scope, string batchFile, string SiebelUserName, IDictionary <string, object> scriptParameters, string tftpPath, string tftpPath_login, string tftpPath_password, ITftpDispatcher tftpDispatcher) { ResultCodes resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; string stdout = String.Empty; Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Attempt to execute remote command connection.", m_taskId); using (IRemoteProcess rp = RemoteProcess.ExecuteBatchFile(m_taskId, scope, batchFile, scriptParameters, tftpPath, tftpPath_login, tftpPath_password, tftpDispatcher)) { Stopwatch sw = Stopwatch.StartNew(); resultCode = rp.Launch(); Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, "Task Id {0}: Remote process operation completed with result code {1}. Elapsed time {2}.", m_taskId, resultCode.ToString(), sw.Elapsed.ToString()); stdout = rp.Stdout.ToString(); if (ResultCodes.RC_SUCCESS == resultCode) { if (null != stdout && 0 < stdout.Length) { if (!stdout.Contains(@"Execution completed")) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, "Task Id {0}: Data returned is shorter than expected, possibly due to transfer failure.", m_taskId); resultCode = ResultCodes.RC_REMOTE_COMMAND_EXECUTION_ERROR; } // // Check for siebel login error code. if (stdout.Contains(@"Failed to connect server") || s_invalidSiebelUsernamePasswordRegex.IsMatch(stdout)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, @"Task Id {0}: Incorrect Siebel username or password supplied.\nSTDOUT/STDERR:\n{1}", m_taskId, stdout); resultCode = ResultCodes.RC_LOGIN_FAILED; } else if (stdout.Contains(@"SBL-ADM-02071") || s_invalidSibelEnterpriseRegex.IsMatch(stdout)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, @"Task Id {0}: Invalid Siebel Enterprise name.\nSTDOUT/STDERR:\n{1}", m_taskId, stdout); resultCode = ResultCodes.RC_LOGIN_FAILED; } else if (stdout.Contains(@"Fatal error") || s_invalidSiebelGatewayRegex.IsMatch(stdout)) { Lib.Logger.TraceEvent(TraceEventType.Error, 0, @"Task Id {0}: Invalid Siebel Gateway Server.\nSTDOUT/STDERR:\n{1}", m_taskId, stdout); resultCode = ResultCodes.RC_LOGIN_FAILED; } else { Lib.Logger.TraceEvent(TraceEventType.Verbose, 0, @"Task Id {0}: Login successful with username {1}", m_taskId, SiebelUserName); resultCode = ResultCodes.RC_SUCCESS; } } 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.\n{1}", m_taskId, stdout); } } if (ResultCodes.RC_SUCCESS == resultCode) { // // If we didn't get the output expected from execution // of the batch file. Force the result code to some // error value so that we try the next credential set. stdout = stdout.Replace("\r\n", ""); if (0 >= stdout.Length || !s_bdnaRegex.IsMatch(stdout)) { resultCode = ResultCodes.RC_LOGIN_FAILED; // @todo Did login really fail? Perhaps this s/b processing exception } } return(resultCode); }