public PolicyAlert(Message msg) : base(msg) { var policyName = Helpers.XenObjectFromMessage(msg) is VMSS vmss?vmss.Name() : ""; Time = msg.TimestampLocal(); Type = FromPriority(msg.priority); if (Type != PolicyAlertType.Error) { _title = string.Format(Message.FriendlyBody(msg.name), policyName); _description = _title; return; } //Parse the message body to get the errors per VM var vmFailures = new List <string>(); using (var sr = new StringReader(msg.body)) { string line; while ((line = sr.ReadLine()) != null) { var match = VmErrorRegex.Match(line); if (!match.Success) { continue; } var vmName = match.Groups[1].Value.Trim(); var errorCode = match.Groups[3].Value .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim().TrimStart('\'').TrimEnd('\'')).FirstOrDefault(); if (!string.IsNullOrEmpty(errorCode)) { string errorMessage = new Failure(errorCode).Message; vmFailures.Add(string.Format(Messages.VMSS_ALERT_VM_ERROR_FORMAT, vmName, errorMessage)); } } } if (vmFailures.Count > 0) { _title = string.Format(Messages.VM_SNAPSHOT_SCHEDULE_FAILED, Message.FriendlyName(Message.MessageType.VMSS_SNAPSHOT_FAILED.ToString()), vmFailures.Count); var sb = new StringBuilder(); sb.AppendFormat(Message.FriendlyBody(msg.name), policyName); vmFailures.ForEach(f => sb.AppendLine().Append(f)); _description = sb.ToString(); } else { _title = Message.FriendlyName(Message.MessageType.VMSS_SNAPSHOT_FAILED.ToString()); _description = string.Format(Message.FriendlyBody(msg.name), policyName); } }
public static Bitmap GetImage(this PolicyAlertType paType) { switch (paType) { case PolicyAlertType.Error: return(Images.StaticImages._000_error_h32bit_16); case PolicyAlertType.Warn: return(Images.StaticImages._075_WarningRound_h32bit_16); case PolicyAlertType.Info: return(Images.StaticImages._075_TickRound_h32bit_16); default: throw new ArgumentOutOfRangeException(nameof(paType), paType, null); } }
public static string GetString(this PolicyAlertType paType) { switch (paType) { case PolicyAlertType.Error: return(Messages.FAILED); case PolicyAlertType.Warn: return(Messages.WARNING); case PolicyAlertType.Info: return(Messages.SUCCEEDED); default: throw new ArgumentOutOfRangeException(nameof(paType), paType, null); } }