private bool CheckInstance(string instanceName) { int processId = 0; if (!ProvisioningMonitoringConfig.TryGetPidFromInstanceName(instanceName, ref processId)) { return(false); } bool result; try { using (Process.GetProcessById(processId)) { result = true; } } catch (ArgumentException) { MSExchangeTenantMonitoring.RemoveInstance(instanceName); result = false; } return(result); }
private string GetFailureDetails(List <string> instances, string counterNameForAttempts) { List <string> cmdletNamesFromAttemptsCounterName = this.GetCmdletNamesFromAttemptsCounterName(counterNameForAttempts); if (cmdletNamesFromAttemptsCounterName.Count == 0 || instances == null) { return(string.Empty); } string result; try { List <string> list = new List <string>(); foreach (string instanceName in instances) { string item = null; if (ProvisioningMonitoringConfig.TryGetOrganizationNameFromInstanceName(instanceName, ref item)) { list.Add(item); } } if (list.Count == 0) { result = string.Empty; } else { TimeSpan timeSpan = IntervalCounterInstanceCache.UpdateInterval + IntervalCounterInstanceCache.UpdateInterval; DateTime t = this.startTime.Add(timeSpan.Negate()); StringBuilder stringBuilder = new StringBuilder(); using (EventLog eventLog = new EventLog()) { eventLog.Log = "MSExchange Management"; EventLogEntryCollection entries = eventLog.Entries; int count = entries.Count; for (int i = count - 1; i >= 0; i--) { EventLogEntry eventLogEntry = entries[i]; if (eventLogEntry.TimeGenerated < t) { break; } if (eventLogEntry.ReplacementStrings != null && eventLogEntry.ReplacementStrings.Length >= 14 && eventLogEntry.ReplacementStrings[0] != null && eventLogEntry.EntryType == EventLogEntryType.Error && cmdletNamesFromAttemptsCounterName.Contains(eventLogEntry.ReplacementStrings[0].ToLowerInvariant())) { foreach (string text in list.ToArray()) { if ((eventLogEntry.ReplacementStrings[1] != null && eventLogEntry.ReplacementStrings[1].IndexOf(text, StringComparison.OrdinalIgnoreCase) != -1) || (eventLogEntry.ReplacementStrings[7] != null && eventLogEntry.ReplacementStrings[7].IndexOf(text, StringComparison.OrdinalIgnoreCase) != -1)) { stringBuilder.AppendLine("Invocation: "); foreach (string value in eventLogEntry.ReplacementStrings) { stringBuilder.AppendLine(value); } list.Remove(text); break; } } if (list.Count == 0 || stringBuilder.Length > 10000) { break; } } } } if (stringBuilder.Length > 10000) { stringBuilder.Remove(10000, stringBuilder.Length - 10000); stringBuilder.Append("..."); } result = stringBuilder.ToString(); } } catch (Exception ex) { if (instances.Count > 10) { instances = instances.GetRange(0, 10); } ExManagementApplicationLogger.LogEvent(ManagementEventLogConstants.Tuple_FailToRetrieveErrorDetails, new string[] { counterNameForAttempts, string.Join(", ", instances.ToArray()), ex.ToString() }); result = string.Empty; } return(result); }