/// <summary> /// Read chassis log with Timestamp /// </summary> /// <param name="start">Start Timestamp</param> /// <param name="end">End Timestamp</param> /// <returns>Chassis Log</returns> public ChassisLogResponse ReadChassisLogWithTimestamp(DateTime start, DateTime end) { ChassisLogResponse response = new ChassisLogResponse(); response.completionCode = Contracts.CompletionCode.Unknown; response.statusDescription = String.Empty; response.logEntries = new List<LogEntry>(); Tracer.WriteUserLog("Invoked ReadChassisLogWithTimestamp()"); Tracer.WriteInfo("Invoked ReadChassisLogWithTimestamp()"); DateTime endTimeWhenTimeofDayNotPresented = end; DateTime startTimeWhenTimeofDayNotPresented = start; // Check that end is later than start if(DateTime.Compare(start, end)==0 && start==default(DateTime)) { endTimeWhenTimeofDayNotPresented = DateTime.MaxValue; startTimeWhenTimeofDayNotPresented = DateTime.MinValue; } else if (DateTime.Compare(start, end) >= 0) { response.completionCode = Contracts.CompletionCode.ParameterOutOfRange; response.statusDescription = "endTimestamp must be later or equal to startTimestamp"; return response; } // When the user do not present time of the day in the 'end' parameter, it defaults to beginning of the day 00:00:00 hours // The assumed intention of the user is to get all logs from the 'end' date, therefore collect logs until end of the day (23:59:59 hours) if (endTimeWhenTimeofDayNotPresented.Hour == 0 && endTimeWhenTimeofDayNotPresented.Minute == 0 && endTimeWhenTimeofDayNotPresented.Second == 0) { endTimeWhenTimeofDayNotPresented = endTimeWhenTimeofDayNotPresented.Add(new TimeSpan(23, 59, 59)); } try { response.logEntries = UserLogXmllinqHelper.GetFilteredLogEntries(startTimeWhenTimeofDayNotPresented, endTimeWhenTimeofDayNotPresented, ConfigLoaded.UserLogMaxEntries); if (response.logEntries != null) { response.completionCode = Contracts.CompletionCode.Success; } else { response.completionCode = Contracts.CompletionCode.Failure; response.statusDescription = "No log entries returned within the requested time period"; } } catch (Exception e) { Tracer.WriteError(e.Message); response.completionCode = Contracts.CompletionCode.Failure; response.statusDescription = String.Format("ReadChassisLog failed with exception:{0} ", e.Message); } return response; }
/// <summary> /// Read Blade Log for specified blade with timestamp /// TO DO M2 - Modify to include timestamp /// </summary> /// <param name="bladeId">Blade ID</param> /// <param name="startTimestamp">Start Timestamp</param> /// <param name="endTimestamp">End Timestamp</param> /// <returns>Blade log for specified blade</returns> public ChassisLogResponse ReadBladeLogWithTimestamp(int bladeId, DateTime startTimestamp, DateTime endTimestamp) { Tracer.WriteUserLog("Invoked ReadBladeLogWithTimestamp(bladeId: {0}, StartTimestamp: {1}, EndTimestamp: {2}", bladeId, startTimestamp, endTimestamp); ChassisLogResponse response = new ChassisLogResponse(); ChassisLogResponse filteredResponse = new ChassisLogResponse(); filteredResponse.logEntries = new List<LogEntry>(); filteredResponse.completionCode = Contracts.CompletionCode.Unknown; filteredResponse.statusDescription = String.Empty; response.completionCode = Contracts.CompletionCode.Unknown; response.statusDescription = String.Empty; Contracts.ChassisResponse varResponse = ValidateRequest("ReadBladeLogWithTimestamp", bladeId); if (varResponse.completionCode != Contracts.CompletionCode.Success) { response.completionCode = varResponse.completionCode; response.statusDescription = varResponse.statusDescription; return response; } // Check that endTimestamp is equal or later than startTimestamp if (DateTime.Compare(startTimestamp, endTimestamp) > 0) { response.completionCode = Contracts.CompletionCode.ParameterOutOfRange; response.statusDescription = "endTimestamp must be later or equal to startTimestamp"; return response; } // When the user does not present time of the day in the 'end' parameter, it defaults to beginning of the day 00:00:00 hours // The assumed intention of the user is to get all logs from the 'end' date, therefore collect logs until end of the day (23:59:59 hours) DateTime endTimestampAdjusted = endTimestamp; if (endTimestamp.Hour == 0 && endTimestamp.Minute == 0 && endTimestamp.Second == 0) { endTimestampAdjusted = endTimestampAdjusted.Add(new TimeSpan(23, 59, 59)); } response = ReadBladeLog(bladeId); try { if (response.completionCode == Contracts.CompletionCode.Success) { for (int i = 0; i < response.logEntries.Count(); i++) { if (response.logEntries[i].eventTime >= startTimestamp && response.logEntries[i].eventTime <= endTimestampAdjusted) { filteredResponse.logEntries.Add(response.logEntries[i]); } } filteredResponse.completionCode = Contracts.CompletionCode.Success; } else { filteredResponse.completionCode = Contracts.CompletionCode.Failure; filteredResponse.statusDescription = Contracts.CompletionCode.Failure.ToString(); } } catch (Exception ex) { Tracer.WriteError("ReadLogWithTimestamp failed for BladeID:{0}, with the exception {1}", bladeId, ex.Message); filteredResponse.completionCode = Contracts.CompletionCode.Failure; filteredResponse.statusDescription = Contracts.CompletionCode.Failure.ToString() + ": " + ex.Message; } return filteredResponse; }
/// <summary> /// Read Chassis Log /// </summary> /// <returns>returns logPacket structure poluated. If null then failure</returns> public ChassisLogResponse ReadChassisLog() { ChassisLogResponse response = new ChassisLogResponse(); response.completionCode = Contracts.CompletionCode.Unknown; response.statusDescription = String.Empty; response.logEntries = new List<LogEntry>(); Tracer.WriteUserLog("Invoked ReadChassisLog()"); Tracer.WriteInfo("Invoked ReadChassisLog()"); try { response.logEntries = UserLogXmllinqHelper.GetFilteredLogEntries(DateTime.MinValue, DateTime.MaxValue, ConfigLoaded.UserLogMaxEntries); if (response.logEntries != null) { response.completionCode = Contracts.CompletionCode.Success; } else { response.completionCode = Contracts.CompletionCode.Failure; response.statusDescription = "No log entries returned"; } } catch (Exception e) { Tracer.WriteError(e.Message); response.completionCode = Contracts.CompletionCode.Failure; response.statusDescription = String.Format("ReadChassisLog failed with exception:{0} ", e.Message); } return response; }
/// <summary> /// command specific implementation /// argVal command class member has all user-entered command argument indicators and parameter values /// Currently just prints all argument indicators and argument values /// </summary> internal override void commandImplementation() { ChassisLogResponse myResponse = new ChassisLogResponse(); dynamic myNumberEntries = null; if (!this.argVal.TryGetValue('n', out myNumberEntries)) { myNumberEntries = WcsCliConstants.readsclogNumberEntries; } try { if (this.argVal.ContainsKey('i')) { dynamic mySledId = null; this.argVal.TryGetValue('i', out mySledId); myResponse = WcsCli2CmConnectionManager.channel.ReadBladeLog((int)mySledId); } } catch (Exception ex) { SharedFunc.ExceptionOutput(ex); return; } if (myResponse == null) { Console.WriteLine(WcsCliConstants.serviceResponseEmpty); return; } if (myResponse.completionCode == Contracts.CompletionCode.Success) { List<string> myStrings = new List<string>(); Console.WriteLine(WcsCliConstants.readsclogHeader); myStrings.Add("Timestamp"); myStrings.Add("Entry"); printTabSeperatedStrings(myStrings); uint index = 0; foreach (LogEntry lg in myResponse.logEntries) { if (index > myNumberEntries) { break; } myStrings.RemoveAll(item => (1 == 1)); myStrings.Add(lg.eventTime.ToString()); myStrings.Add(lg.eventDescription); printTabSeperatedStrings(myStrings); index++; } } else if (myResponse.completionCode == Contracts.CompletionCode.Failure) { Console.WriteLine(WcsCliConstants.commandFailure); } else if (myResponse.completionCode == Contracts.CompletionCode.Timeout) { Console.WriteLine(WcsCliConstants.commandTimeout); } else { Console.WriteLine("Command failed with the completion code: {0}", myResponse.completionCode.ToString()); } }
/// <summary> /// Read blade log, for given blade number /// </summary> /// <param name="bladeId">Blade ID(1-48)</param> /// <returns>returns logPacket structure poluated. If null then failure</returns> public ChassisLogResponse ReadBladeLog(int bladeId) { Tracer.WriteInfo("Received Readbladelog({0})", bladeId); Tracer.WriteUserLog("Invoked ReadBladelog(bladeId: {0})", bladeId); // Blade spec limits number of SEL entries to 226 uint maxSelEntries = 226; // Initialize response ChassisLogResponse selLog = new ChassisLogResponse(); selLog.logEntries = new List<LogEntry>(); selLog.completionCode = Contracts.CompletionCode.Unknown; selLog.statusDescription = String.Empty; Contracts.ChassisResponse varResponse = ValidateRequest("ReadBladeLog", bladeId); if (varResponse.completionCode != Contracts.CompletionCode.Success) { selLog.completionCode = varResponse.completionCode; selLog.statusDescription = varResponse.statusDescription; return selLog; } Ipmi.SystemEventLog selRecord = WcsBladeFacade.GetSel((byte)bladeId); Tracer.WriteInfo("Blade {0} ReadBladeLog Return: {1}", bladeId, selRecord.CompletionCode); if (selRecord.CompletionCode != 0 && selRecord.CompletionCode != 0xCB) { Tracer.WriteWarning("ReadBladeLog on blade {0} failed with completion code {1:X}", bladeId, selRecord.CompletionCode); selLog.completionCode = ChassisManagerUtil.GetContractsCompletionCodeMapping((byte)selRecord.CompletionCode); selLog.statusDescription = selLog.completionCode.ToString(); } else { try { // Event time and description lists List<DateTime> eventTimeList = new List<DateTime>(); List<string> eventDescriptionList = new List<string>(); int startingIndex = 0; ushort minRecordId = ushort.MaxValue; Ipmi.SystemEventLogMessage eventLog; string eventDescription; string spacer = ConfigLoaded.EventLogStrSpacer + ConfigLoaded.EventLogStrSeparator + ConfigLoaded.EventLogStrSpacer; // Separate log entries into time and description arrays for (int index = 0; index < selRecord.EventLog.Count; index++) { if (index >= maxSelEntries) { break; } // Extract event data eventLog = selRecord.EventLog[index]; EventLogData eventLogData = ExtractEventMessage(eventLog); // Format event description according to record type if (eventLog.EventFormat == Ipmi.EventMessageFormat.SystemEvent) { // Get sensor details. string sensor = string.Format(ConfigLoaded.EventLogStrSensor, eventLog.SensorType.ToString(), WcsBladeFacade.GetSensorDescription((byte)bladeId, eventLog.GeneratorId[0], eventLog.SensorNumber), eventLog.SensorNumber); // Get Event Data Message string eventData = string.Format(ConfigLoaded.EventData, eventLog.EventPayload); // Add entry to array eventDescription = ( // Record ID and Type "RecordID: " + eventLog.RecordId + " Record Type: " + string.Format("0x{0:X}", eventLog.RecordType) + spacer + // Generator ID "GenID: " + Ipmi.IpmiSharedFunc.ByteArrayToHexString(eventLog.GeneratorId) + spacer + // Description and message eventLogData.Description + spacer + eventLogData.EventMessage + spacer + // Sensor Type and Number sensor + spacer + eventLog.EventDir.ToString() + spacer + // Event Data eventData); } else if (eventLog.EventFormat == Ipmi.EventMessageFormat.OemTimeStamped) { // Add entry to array eventDescription = ( // Record ID and Type "RecordID: " + eventLog.RecordId + " Record Type: " + string.Format("0x{0:X}", eventLog.RecordType) + spacer + // Description and message eventLogData.Description + spacer + eventLogData.EventMessage); } else if (eventLog.EventFormat == Ipmi.EventMessageFormat.OemNonTimeStamped) { // Add entry to array eventDescription = ( // Record ID and Type "RecordID: " + eventLog.RecordId + " Record Type: " + string.Format("0x{0:X}", eventLog.RecordType) + spacer + // Description and message eventLogData.Description + spacer + eventLogData.EventMessage); } else { eventDescription = string.Empty; } // Track starting index of the entry with the smallest Record ID if (eventLog.RecordId < minRecordId) { minRecordId = eventLog.RecordId; startingIndex = index; } // Add event time to list eventTimeList.Add(eventLog.EventDate); eventDescriptionList.Add(eventDescription); } // Add SEL entries to response starting with the one with the smallest Record ID int entryIdx = startingIndex; for (int entryAdded = 0; entryAdded < eventTimeList.Count; entryAdded++) { LogEntry logEntry = new LogEntry(); logEntry.eventTime = eventTimeList[entryIdx]; logEntry.eventDescription = eventDescriptionList[entryIdx]; selLog.logEntries.Add(logEntry); // Go to next entry and handle wraparound entryIdx++; if (entryIdx == eventTimeList.Count) entryIdx = 0; } selLog.completionCode = Contracts.CompletionCode.Success; Tracer.WriteInfo("ReadBladeLog on blade " + bladeId + " returned " + selLog.logEntries.Count() + " entries out of " + selRecord.EventLog.Count + " found on BMC"); } catch (Exception ex) { Tracer.WriteError("ReadBladeLog on blade " + bladeId + " failed with exception: " + ex); selLog.completionCode = Contracts.CompletionCode.Failure; selLog.statusDescription = selLog.completionCode.ToString() + ": " + ex.Message; } } return selLog; }
private void VerifyReadChassisLog(ref bool chassisPassed, WCSSecurityRole user) { string currentApi = "ReadChassisLog"; string logParentDirectory = @"\\" + defaultCMName + @"\c$\"; string[] userLogPaths = new string[] { null, null }; ChassisLogResponse chassisLog = new ChassisLogResponse(); CmTestLog.Info("TestChannelContext user " + (int)user); this.TestChannelContext = this.ListTestChannelContexts[(int)user]; chassisLog = this.TestChannelContext.ReadChassisLog(); chassisPassed &= ChassisManagerTestHelper.AreEqual(CompletionCode.Success, chassisLog.completionCode, currentApi + ": Completion Code success for user " + user.ToString()); if (StartStopCmService("stop")) CmTestLog.Success(currentApi + ": Stopped Chassis Manager Service"); else { CmTestLog.Failure(currentApi + ": Unable to stop Chassis Manager Service. Will not check log entry contents"); chassisPassed = false; return; } // Check Log entries are populated in ChassisLogResponse and not greater than 50 entries if (chassisLog.logEntries.Count < 1) { CmTestLog.Failure(currentApi + ": Command does not return Log Entries"); chassisPassed = false; ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Stopped Chassis Manager Service"); return; } else if (chassisLog.logEntries.Count > 50) { CmTestLog.Failure(currentApi + ": Command returns more than 50 Log Entries"); chassisPassed = false; ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Stopped Chassis Manager Service"); return; } else CmTestLog.Success(currentApi + ": Command returns between 1 and 50 Log Entries"); IntPtr token = IntPtr.Zero; // Impersonate remote user bool successLogon = LogonUser(defaultAdminUserName, defaultCMName, defaultAdminPassword, (int)DwLogonType.NewCredentials, (int)DwLogonProvider.WinNT50, ref token); if (successLogon) { using (WindowsImpersonationContext context = WindowsIdentity.Impersonate(token)) { // Verify that User Logs exist to compare log entries with ChassisLogResponse if (!Directory.Exists(logParentDirectory)) { CmTestLog.Failure(currentApi + ": Directory to User Log files does not exist"); chassisPassed = false; ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Stopped Chassis Manager Service"); return; } foreach (string filePath in Directory.GetFiles(logParentDirectory)) { Match fileMatch00 = Regex.Match(filePath, @"ChassisManagerUserLog00\.svclog"); Match fileMatch01 = Regex.Match(filePath, @"ChassisManagerUserLog01\.svclog"); if (fileMatch00.Success) userLogPaths[0] = filePath; else if (fileMatch01.Success) userLogPaths[1] = filePath; } if (userLogPaths[0] == null && userLogPaths[1] == null) { CmTestLog.Failure(currentApi + ": Could not find user logs"); chassisPassed = false; ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Started Chassis Manager Service"); return; } // Compare and match log entries in ChassisLogResponse to User Logs in Chassis Manager int entryCount = 0; bool allEntriesPassed = true; foreach (LogEntry entry in chassisLog.logEntries) { if (entry.eventDescription == null && entry.eventTime == null) { CmTestLog.Failure(currentApi + string.Format(": Log Entry {0} returns no data for either eventDescription or eventTime or both", entryCount)); allEntriesPassed = false; entryCount++; continue; } // Find log entry in either UserLog00 or UserLog01 int userLogCount = 0; bool userLogEntryFound = false; string propertyValue; foreach (string userLogPath in userLogPaths) { if (userLogPath == null) { CmTestLog.Info(currentApi + string.Format(": User Log {0} does not exist", userLogCount)); userLogCount++; continue; } XmlReaderSettings xmlSettings = new XmlReaderSettings(); xmlSettings.ConformanceLevel = ConformanceLevel.Fragment; XmlReader userLogReader = XmlReader.Create(userLogPath, xmlSettings); try { while (!userLogEntryFound) { while (userLogReader.Read()) { if (userLogReader.Name == "ApplicationData") break; } if (userLogReader.Name != "ApplicationData") { userLogReader.Close(); break; } // Read User Log Entry and condition both strings for comparison propertyValue = userLogReader.ReadElementContentAsString(); propertyValue = propertyValue.Replace(@"\", ""); propertyValue = propertyValue.Replace(@"(", ""); propertyValue = propertyValue.Replace(@")", ""); entry.eventDescription = entry.eventDescription.Replace(@"\", ""); entry.eventDescription = entry.eventDescription.Replace(@"(", ""); entry.eventDescription = entry.eventDescription.Replace(@")", ""); Match eventTimeMatch = Regex.Match(propertyValue, entry.eventTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); Match eventDescriptionMatch = Regex.Match(propertyValue, entry.eventDescription); if (eventTimeMatch.Success && eventDescriptionMatch.Success) { CmTestLog.Success(currentApi + string.Format(": Found eventTime match and eventDescription match for entry {0} in user log {1}", entryCount, userLogCount)); userLogEntryFound = true; } } } catch (Exception exc) { if (exc.Message.Contains(@"Not enough )'s")) { CmTestLog.Info(currentApi + string.Format(": Entry {0} throwing exception 'Not enough )'s' in User Log {1}", entryCount, userLogCount)); userLogCount++; continue; } else throw new Exception(exc.Message); } if (!userLogEntryFound) { CmTestLog.Info(currentApi + string.Format(": User Log {0} does not contain entry {1}", userLogCount, entryCount)); userLogReader.Close(); userLogCount++; continue; } userLogReader.Close(); userLogCount++; } if (!userLogEntryFound) { CmTestLog.Failure(currentApi + string.Format(": Entry {0} was not found in either user logs", entryCount)); allEntriesPassed = false; entryCount++; continue; } chassisPassed &= allEntriesPassed; entryCount++; } ChassisManagerTestHelper.IsTrue(allEntriesPassed, currentApi + string.Format(": All Log Entries passed", entryCount)); // Revert back to original user context.Undo(); } } else { CmTestLog.Failure("UserLogon: User failed to be created"); chassisPassed = false; } ChassisManagerTestHelper.IsTrue(StartStopCmService("start"), currentApi + ": Started Chassis Manager Service"); }
/// <summary> /// command specific implementation /// argVal command class member has all user-entered command argument indicators and parameter values /// Currently just prints all argument indicators and argument values /// </summary> internal override void commandImplementation() { ChassisLogResponse myResponse = new ChassisLogResponse(); try { myResponse = WcsCli2CmConnectionManager.channel.ReadChassisLog(); } catch (Exception ex) { SharedFunc.ExceptionOutput(ex); return; } if (myResponse == null) { Console.WriteLine(WcsCliConstants.serviceResponseEmpty); return; } if (myResponse.completionCode == Contracts.CompletionCode.Success) { List<string> myStrings = new List<string>(); Console.WriteLine(WcsCliConstants.readnclogHeader); myStrings.Add("Timestamp"); myStrings.Add("Entry"); printTabSeperatedStrings(myStrings); foreach (LogEntry lg in myResponse.logEntries) { myStrings.RemoveAll(item => (1 == 1)); myStrings.Add(lg.eventTime.ToString()); myStrings.Add(lg.eventDescription.ToString()); printTabSeperatedStrings(myStrings); } } else if (myResponse.completionCode == Contracts.CompletionCode.Failure) { Console.WriteLine(WcsCliConstants.commandFailure); } else if (myResponse.completionCode == Contracts.CompletionCode.Timeout) { Console.WriteLine(WcsCliConstants.commandTimeout); } else { Console.WriteLine("Command failed with the completion code: {0}", myResponse.completionCode.ToString()); } }
/// <summary> /// command specific implementation /// argVal command class member has all user-entered command argument indicators and parameter values /// Currently just prints all argument indicators and argument values /// </summary> internal override void commandImplementation() { ChassisLogResponse myResponse = new ChassisLogResponse(); dynamic startDateString = null; dynamic endDateString = null; DateTime startDate = new DateTime(); DateTime endDate = new DateTime(); // Initialize the start date for querying logs - default to start of .NET time when not provided by user if (!this.argVal.TryGetValue('s', out startDateString)) { startDate = DateTime.MinValue; } else { DateTime.TryParse(((string)startDateString).Replace(":", "-"), out startDate); } // Initialize the end date for querying logs - default to end of .NET time when not provided by user if (!this.argVal.TryGetValue('e', out endDateString)) { endDate = DateTime.MaxValue; } else { DateTime.TryParse(((string)endDateString).Replace(":", "-"), out endDate); } // Call appropriate chassis user log API based on presented inputs try { if (this.argVal.ContainsKey('s') || this.argVal.ContainsKey('e')) { myResponse = WcsCli2CmConnectionManager.channel.ReadChassisLogWithTimestamp(startDate, endDate); } else { myResponse = WcsCli2CmConnectionManager.channel.ReadChassisLog(); } } catch (Exception ex) { SharedFunc.ExceptionOutput(ex); return; } if (ResponseValidation.ValidateResponse(null, myResponse, false)) { Console.WriteLine(WcsCliConstants.commandSuccess); List<string> myStrings = new List<string>(); Console.WriteLine(WcsCliConstants.readChassisLogHeader); myStrings.Add("Timestamp\t"); myStrings.Add("Entry"); printTabSeparatedStrings(myStrings); foreach (LogEntry lg in myResponse.logEntries) { myStrings.RemoveAll(item => (1 == 1)); myStrings.Add(lg.eventTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); myStrings.Add(lg.eventDescription.ToString()); printTabSeparatedStrings(myStrings); } } }
/// <summary> /// Read blade log, for given blade number /// </summary> /// <param name="bladeId">Blade ID(1-48)</param> /// <returns>returns logPacket structure poluated. If null then failure</returns> public ChassisLogResponse ReadBladeLog(int bladeId) { Tracer.WriteInfo("Received Readbladelog({0})", bladeId); Tracer.WriteUserLog("Invoked ReadBladelog(bladeId: {0})", bladeId); // Blade spec limits number of SEL entries to 226 uint noSelEntries = 226; // Initialize response ChassisLogResponse selLog = new ChassisLogResponse(); selLog.logEntries = new List<LogEntry>(); selLog.completionCode = Contracts.CompletionCode.Unknown; selLog.statusDescription = String.Empty; Contracts.ChassisResponse varResponse = ValidateRequest("ReadBladeLog", bladeId); if (varResponse.completionCode != Contracts.CompletionCode.Success) { selLog.completionCode = varResponse.completionCode; selLog.statusDescription = varResponse.statusDescription; return selLog; } Ipmi.SystemEventLog selRecord = WcsBladeFacade.GetSel((byte)bladeId); Tracer.WriteInfo("Blade {0} ReadBladeLog Return: {1}", bladeId, selRecord.CompletionCode); if (selRecord.CompletionCode != 0 && selRecord.CompletionCode != 0xCB) { Tracer.WriteWarning("blade Get SEL Failed with Completion code {0:X}", selRecord.CompletionCode); selLog.completionCode = ChassisManagerUtil.GetContractsCompletionCodeMapping((byte)selRecord.CompletionCode); selLog.statusDescription = selLog.completionCode.ToString(); } else { try { DateTime[] eventTime = new DateTime[selRecord.EventLog.Count]; string[] eventDescription = new string[selRecord.EventLog.Count]; Ipmi.SystemEventLogMessage eventLog; string spacer = ConfigLoaded.EventLogStrSpacer + ConfigLoaded.EventLogStrSeparator + ConfigLoaded.EventLogStrSpacer; // Separate log entries into time and description arrays for (int index = 0; index < selRecord.EventLog.Count; index++) { if (index >= noSelEntries) { break; } // Extract event data eventLog = selRecord.EventLog[index]; EventLogData eventData = ExtractEventMessage(eventLog); // Get sensor details. string sensor = string.Format(ConfigLoaded.EventLogStrSensor, eventLog.SensorType.ToString(), WcsBladeFacade.GetSensorDescription((byte)bladeId, eventLog.GeneratorId[0], eventLog.SensorNumber), eventLog.SensorNumber); // Get Event Error Message string error = string.Format(ConfigLoaded.EventLogStrError, eventLog.EventPayload); // Add entry to array eventTime[index] = eventLog.EventDate; eventDescription[index] = ("GenID: " + Ipmi.IpmiSharedFunc.ByteArrayToHexString(eventLog.GeneratorId) + spacer + eventLog.EventDir.ToString() + spacer + eventData.Description + spacer + eventData.EventMessage + spacer + sensor + spacer + error); } // Sort log entries by time Array.Sort<DateTime, string>(eventTime, eventDescription); // Convert array elements into list for response for (int index = 0; index < eventTime.Length; index++) { LogEntry logEntry = new LogEntry(); logEntry.eventTime = eventTime[index]; logEntry.eventDescription = eventDescription[index]; selLog.logEntries.Add(logEntry); } selLog.completionCode = Contracts.CompletionCode.Success; Tracer.WriteInfo("Readbladelog returned " + selLog.logEntries.Count() + " entries. Of " + selRecord.EventLog.Count + " found on BMC"); } catch (Exception ex) { Tracer.WriteError("ReadBladeLog failed with exception: " + ex); selLog.completionCode = Contracts.CompletionCode.Failure; selLog.statusDescription = selLog.completionCode.ToString() + ": " + ex.Message; } } return selLog; }
/// <summary> /// command specific implementation /// argVal command class member has all user-entered command argument indicators and parameter values /// Currently just prints all argument indicators and argument values /// </summary> internal override void commandImplementation() { ChassisLogResponse myResponse = new ChassisLogResponse(); dynamic myNumberEntries = null; if (!this.argVal.TryGetValue('n', out myNumberEntries)) { myNumberEntries = WcsCliConstants.readBladeLogNumberOfEntries; } try { if (this.argVal.ContainsKey('i')) { dynamic mySledId = null; this.argVal.TryGetValue('i', out mySledId); myResponse = WcsCli2CmConnectionManager.channel.ReadBladeLog((int)mySledId); } } catch (Exception ex) { SharedFunc.ExceptionOutput(ex); return; } if (ResponseValidation.ValidateResponse(null, myResponse, false)) { Console.WriteLine(WcsCliConstants.commandSuccess); // Print header List<string> myStrings = new List<string>(); Console.WriteLine(WcsCliConstants.readBladeLogHeader); myStrings.Add("Timestamp\t"); myStrings.Add("Entry"); printTabSeparatedStrings(myStrings); // Print all SEL entries up to the number specified by the user int numEntriesToPrint = ((int)myNumberEntries > myResponse.logEntries.Count) ? myResponse.logEntries.Count : (int)myNumberEntries; for (int index = 0; index < numEntriesToPrint; index++) { myStrings.RemoveAll(item => (1 == 1)); myStrings.Add(myResponse.logEntries[index].eventTime.ToString()); myStrings.Add(myResponse.logEntries[index].eventDescription); printTabSeparatedStrings(myStrings); } } }
/// <summary> /// Read blade log, for given blade number /// </summary> /// <param name="bladeId">Blade ID(1-48)</param> /// <returns>returns logPacket structure poluated. If null then failure</returns> public ChassisLogResponse ReadBladeLog(int bladeId) { Tracer.WriteInfo("Received Readbladelog({0})", bladeId); Tracer.WriteUserLog("Invoked ReadBladelog(bladeId: {0})", bladeId); uint noEntries = 100; ChassisLogResponse selLog = new ChassisLogResponse(); selLog.logEntries = new List<LogEntry>(); selLog.completionCode = Contracts.CompletionCode.Unknown; selLog.statusDescription = String.Empty; Contracts.ChassisResponse varResponse = ValidateRequest("ReadBladeLog", bladeId); if (varResponse.completionCode != Contracts.CompletionCode.Success) { selLog.completionCode = varResponse.completionCode; selLog.statusDescription = varResponse.statusDescription; return selLog; } Ipmi.SystemEventLog selRecord = WcsBladeFacade.GetSel((byte)bladeId); // Code added to write output to the console window. Tracer.WriteInfo("Blade {0} ReadBladeLog Return: {1}", bladeId, selRecord.CompletionCode); if (selRecord.CompletionCode != 0) { Tracer.WriteWarning("blade Get SEL Failed with Completion code {0:X}", selRecord.CompletionCode); selLog.completionCode = ChassisManagerUtil.GetContractsCompletionCodeMapping((byte)selRecord.CompletionCode); selLog.statusDescription = selLog.completionCode.ToString(); } else { try { string spacer = ConfigLoaded.EventLogStrSpacer + ConfigLoaded.EventLogStrSeparator + ConfigLoaded.EventLogStrSpacer; foreach (Ipmi.SystemEventLogMessage eventLog in selRecord.EventLog) { if (selLog.logEntries.Count() >= noEntries) { break; } EventLogData eventData = ExtractEventMessage(eventLog); // Get sensor details. string sensor = string.Format(ConfigLoaded.EventLogStrSensor, eventLog.SensorType.ToString(), WcsBladeFacade.GetSensorDescription((byte)bladeId, (byte)eventLog.SensorNumber), eventLog.SensorNumber); // Get Event Error Message string error = string.Format(ConfigLoaded.EventLogStrError, eventLog.EventPayload); LogEntry logEntry = new LogEntry(); logEntry.eventTime = eventLog.EventDate; logEntry.eventDescription = (eventLog.EventDir.ToString() + spacer + eventData.Description + spacer + eventData.EventMessage + spacer + sensor + spacer + error); selLog.logEntries.Add(logEntry); } selLog.completionCode = Contracts.CompletionCode.Success; Tracer.WriteInfo("Readbladelog returned " + selLog.logEntries.Count() + " entries."); } catch (Exception ex) { Tracer.WriteError("ReadBladeLog failed with exception: " + ex); selLog.completionCode = Contracts.CompletionCode.Failure; selLog.statusDescription = selLog.completionCode.ToString() + ": " + ex.Message; } } return selLog; }
/// <summary> /// Read Blade Log for specified blade with timestamp /// TO DO M2 - Modify to include timestamp /// </summary> /// <param name="bladeId">Blade ID</param> /// <param name="logType">log type</param> /// <param name="start">Start Timestamp</param> /// <param name="end">End Timestamp</param> /// <returns>Blade log for specified blade</returns> public ChassisLogResponse ReadBladeLogWithTimestamp(int bladeId, DateTime start, DateTime end) { Tracer.WriteUserLog("Invoked ReadBladeLogWithTimestamp(bladeId: {0}, StartTimestamp: {1}, EndTimestamp: {2}", bladeId, start, end); ChassisLogResponse response = new ChassisLogResponse(); ChassisLogResponse filteredResponse = new ChassisLogResponse(); filteredResponse.logEntries = new List<LogEntry>(); filteredResponse.completionCode = Contracts.CompletionCode.Unknown; filteredResponse.statusDescription = String.Empty; response.completionCode = Contracts.CompletionCode.Unknown; response.statusDescription = String.Empty; Contracts.ChassisResponse varResponse = ValidateRequest("ReadBladeLogWithTimestamp", bladeId); if (varResponse.completionCode != Contracts.CompletionCode.Success) { response.completionCode = varResponse.completionCode; response.statusDescription = varResponse.statusDescription; return response; } response = ReadBladeLog(bladeId); try { if (response.completionCode == Contracts.CompletionCode.Success) { for (int i = 0; i < response.logEntries.Count(); i++) { if (response.logEntries[i].eventTime >= start && response.logEntries[i].eventTime <= end) { filteredResponse.logEntries.Add(response.logEntries[i]); } } filteredResponse.completionCode = Contracts.CompletionCode.Success; } else { filteredResponse.completionCode = Contracts.CompletionCode.Failure; filteredResponse.statusDescription = Contracts.CompletionCode.Failure.ToString(); } } catch (Exception ex) { Tracer.WriteError("ReadLogWithTimestamp failed for BladeID :{0}, with the exception {1}", bladeId, ex.Message); filteredResponse.completionCode = Contracts.CompletionCode.Failure; filteredResponse.statusDescription = Contracts.CompletionCode.Failure.ToString() + ": " + ex.Message; } return filteredResponse; }
/// <summary> /// ***TODO M2*** Read chassis log with Timestamp /// </summary> /// <param name="start">Start Timestamp</param> /// <param name="end">End Timestamp</param> /// <returns>Chassis Log</returns> public ChassisLogResponse ReadChassisLogWithTimestamp(DateTime start, DateTime end) { ChassisLogResponse response = new ChassisLogResponse(); ChassisLogResponse filteredResponse = new ChassisLogResponse(); filteredResponse.completionCode = Contracts.CompletionCode.Unknown; filteredResponse.statusDescription = String.Empty; response = ReadChassisLog(); filteredResponse.logEntries = new List<LogEntry>(); for (int i = 0; i < response.logEntries.Count(); i++) { if (response.logEntries[i].eventTime >= start && response.logEntries[i].eventTime <= end) { filteredResponse.logEntries.Add(response.logEntries[i]); } } // Get the completion code & status description from response object. filteredResponse.completionCode = response.completionCode; filteredResponse.statusDescription = response.statusDescription; return filteredResponse; }
/// <summary> /// Read Chassis Log /// </summary> /// <returns>returns logPacket structure poluated. If null then failure</returns> public ChassisLogResponse ReadChassisLog() { ChassisLogResponse response = new ChassisLogResponse(); response.completionCode = Contracts.CompletionCode.Unknown; response.statusDescription = String.Empty; Tracer.WriteUserLog("Invoked ReadChassisLog()"); try { if (Tracer.GetCurrentUserLogFilePath() != null) { // Open a filestream to read the user log FileStream fileStream = new FileStream( Tracer.GetCurrentUserLogFilePath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); List<string> entries = new List<string>(); //Read each log entry XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; XmlReader reader = XmlReader.Create(fileStream, settings); const int MAX_ENTRIES = 500; int traceEventCount = 0; while (reader.Read() && traceEventCount < MAX_ENTRIES) { try { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "E2ETraceEvent") { // Read each sub-entry in E2ETraceEvent XmlReader subReader = reader.ReadSubtree(); while (subReader.Read() && traceEventCount < MAX_ENTRIES) { reader.ReadToFollowing("ApplicationData"); if (reader.Read()) { entries.Add(reader.Value.Trim()); } } } } } catch (System.Xml.XmlException xm) { Tracer.WriteInfo("ReadChassisLog XML exception - ignoring it: " + xm.Message); } } // dispose the filestream. dispose internally calls Close(). fileStream.Dispose(); response.logEntries = new List<LogEntry>(); // For each entry get the timestamp and description int loopCount = 0; foreach (string entry in entries) { System.DateTime timeStamp = new System.DateTime(); string[] tokens = entry.Split(new char[] { ',' }); if (DateTime.TryParse(tokens[0], out timeStamp)) { LogEntry lg = new LogEntry(); lg.eventTime = timeStamp; lg.eventDescription = entry.Replace(tokens[0] + ",", ""); response.logEntries.Add(lg); } loopCount++; } response.completionCode = Contracts.CompletionCode.Success; } else { Tracer.WriteError("ReadChassisLog: Unable to get current trace file path"); response.completionCode = Contracts.CompletionCode.Failure; response.statusDescription = "ReadChassisLog: Unable to get current trace file path"; } } catch (Exception e) { Tracer.WriteError(e.Message); response.completionCode = Contracts.CompletionCode.Failure; response.statusDescription = String.Format("ReadChassisLog failed with exception:{0} ", e.Message); } return response; }