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

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

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

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

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

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

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

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

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

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

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASProfileFootprintScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  result.ResultCode.ToString());
            return(result);
        }
        /// <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 WindowsWASNodeandCoreGroupScript.",
                                  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 WindowsWASNodeandCoreGroupScript 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 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 (resultCode == ResultCodes.RC_SUCCESS)
                {
                    StringBuilder ngDir  = new StringBuilder();
                    StringBuilder ngList = new StringBuilder();
                    ngDir.Append((string)m_profileHome).Append(@"\config\cells\").Append((string)m_cell).Append(@"\nodegroups");
                    StringCollection ngNames = findGroups(ngDir.ToString());

                    foreach (string ng in ngNames)
                    {
                        if (!String.IsNullOrEmpty(ng))
                        {
                            if (ngList.Length > 0)
                            {
                                ngList.Append(BdnaDelimiters.DELIMITER_TAG);
                            }
                            ngList.Append(ng);
                        }
                    }

                    if (ngList.Length > 0)
                    {
                        BuildDataRow(s_nodeGroup, ngList.ToString());
                    }

                    // Process Cluster Info
                    StringBuilder clstDir  = new StringBuilder();
                    StringBuilder clstList = new StringBuilder();
                    clstDir.Append((string)m_profileHome).Append(@"\config\cells\").Append((string)m_cell).Append(@"\clusters");
                    StringCollection clstNames = findGroups(clstDir.ToString());

                    foreach (string clst in clstNames)
                    {
                        if (!String.IsNullOrEmpty(clst))
                        {
                            if (clstList.Length > 0)
                            {
                                clstList.Append(BdnaDelimiters.DELIMITER_TAG);
                            }
                            clstList.Append(clst);
                        }
                    }

                    if (clstList.Length > 0)
                    {
                        BuildDataRow(s_cluster, clstList.ToString());
                        BuildDataRow(s_isCluster, "True");
                    }
                    else
                    {
                        BuildDataRow(s_isCluster, "False");
                    }

                    // Process CoreGroup Info
                    StringBuilder cgDir  = new StringBuilder();
                    StringBuilder cgList = new StringBuilder();
                    cgDir.Append((string)m_profileHome).Append(@"\config\cells\").Append((string)m_cell).Append(@"\coregroups");
                    StringCollection cgNames = findGroups(cgDir.ToString());

                    foreach (string cg in cgNames)
                    {
                        if (!String.IsNullOrEmpty(cg))
                        {
                            if (cgList.Length > 0)
                            {
                                cgList.Append(BdnaDelimiters.DELIMITER_TAG);
                            }
                            cgList.Append(cg);
                        }
                    }

                    if (cgList.Length > 0)
                    {
                        BuildDataRow(s_coreGroup, cgList.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                if (resultCode == ResultCodes.RC_SUCCESS)
                {
                    Lib.Logger.TraceEvent(TraceEventType.Error,
                                          0,
                                          "Task Id {0}: Unhandled exception in WindowsWASNodeandCoreGroupScript.  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 WindowsWASNodeandCoreGroupScript.  Elapsed time {1}.\n{2}",
                                          m_taskId,
                                          m_executionTimer.Elapsed.ToString(),
                                          ex.ToString());
                }
            }

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASNodeandCoreGroupScript.  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()));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(long taskId, long cleId, long elementId, long databaseTimestamp,
                                                   long localTimestamp, IDictionary <string, string> attributes, IDictionary <string, string> scriptParameters,
                                                   IDictionary <string, object> connection, string tftpPath, string tftpPath_login,
                                                   string tftpPath_password, ITftpDispatcher tftpDispatcher)
        {
            m_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 WindowsWASGetServersScript.",
                                  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 WindowsWASGetServersScript 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 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 (resultCode == ResultCodes.RC_SUCCESS)
                {
                    StringBuilder servDir    = new StringBuilder();
                    StringBuilder serverList = new StringBuilder();
                    servDir.Append((string)m_profileHome).Append(@"\config\cells\").Append((string)m_cell).Append(@"\nodes\").Append((string)m_node).Append(@"\servers");
                    StringCollection servNames = findServerDirs(servDir.ToString());

                    foreach (string srv in servNames)
                    {
                        if (!String.IsNullOrEmpty(srv))
                        {
                            if (serverList.Length > 0)
                            {
                                serverList.Append(BdnaDelimiters.DELIMITER_TAG);
                            }
                            serverList.Append(srv);
                        }
                    }

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

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASGetServersScript.  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()));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        ///
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(
            long taskId,
            long cleId,
            long elementId,
            long databaseTimestamp,
            long localTimestamp,
            IDictionary <string, string> attributes,
            IDictionary <string, string> scriptParameters,
            IDictionary <string, object> connection,
            string tftpPath,
            string tftpPath_login,
            string tftpPath_password,
            ITftpDispatcher tftpDispatcher)
        {
            m_executionTimer    = Stopwatch.StartNew();
            m_taskId            = taskId.ToString();
            m_cleId             = cleId;
            m_elementId         = elementId;
            m_databaseTimestamp = databaseTimestamp;
            m_localTimestamp    = localTimestamp;
            m_attributes        = attributes;
            m_scriptParameters  = scriptParameters;

            ResultCodes resultCode = ResultCodes.RC_SUCCESS;

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

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

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

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

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

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

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

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

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

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

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

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

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

            Lib.Logger.TraceEvent(TraceEventType.Stop,
                                  0,
                                  "Task Id {0}: Collection script WindowsWASGetFileScript.  Elapsed time {1}.  Result code {2}.",
                                  m_taskId,
                                  m_executionTimer.Elapsed.ToString(),
                                  result.ResultCode.ToString());
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Perform collection task specific processing.
        /// </summary>
        ///
        /// <param name="taskId">Database assigned task Id.</param>
        /// <param name="cleId">Database Id of owning Collection Engine.</param>
        /// <param name="elementId">Database Id of element being collected.</param>
        /// <param name="databaseTimestamp">Database relatvie task dispatch timestamp.</param>
        /// <param name="localTimestamp">Local task dispatch timestamp.</param>
        /// <param name="attributes">Map of attribute names to Id for attributes being collected.</param>
        /// <param name="scriptParameters">Collection script specific parameters (name/value pairs).</param>
        /// <param name="connection">Connection script results (null if this script does not
        ///     require a remote host connection).</param>
        /// <param name="tftpDispatcher">Dispatcher for TFTP transfer requests.</param>
        ///
        /// <returns>Collection results.</returns>
        public CollectionScriptResults ExecuteTask(
            long taskId,
            long cleId,
            long elementId,
            long databaseTimestamp,
            long localTimestamp,
            IDictionary <string, string> attributes,
            IDictionary <string, string> scriptParameters,
            IDictionary <string, object> connection,
            string tftpPath,
            string tftpPath_login,
            string tftpPath_password,
            ITftpDispatcher tftpDispatcher)
        {
            m_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);
        }