private static void SendReportEmail(ServiceStateUnit unit) { var from = AppConfig.GetStringParam("SMTP.MailFrom", "*****@*****.**"); var recps = AppConfig.GetStringParam("SMTP.Recepients", "*****@*****.**"); var body = string.Format("Состояние сервиса: {0}. Код ошибки: {1} ({2})", unit.LastServiceState.State, unit.LastServiceState.LastError, unit.LastServiceState.LastErrorOccured); var msg = new MailMessage(from, recps, string.Format("Ошибка сервиса {0}", unit.Name), body) { IsBodyHtml = false }; //msg.BodyEncoding = Encoding.Unicode; try { var client = new SmtpClient(); client.Send(msg); unit.UpdateLastReportedData(); Logger.InfoFormat(CultureProvider.Common.ToString(), "Письмо ({0}) отправлено", body); } catch (Exception ex) { Logger.Error("Ошибка доставки сообщения", ex); } }
public static void SendReports(ServiceStateUnit unit) { // проверка на дублирование отчета if (unit.HasBeenReported()) { var minutesPassed = unit.LastReportTime == new DateTime() ? int.MaxValue : (int)(DateTime.Now - unit.LastReportTime).TotalMinutes; if (minutesPassed < MinutesBetweenReportsOnSameError) { return; } } // проверка на день недели и время суток (выходной) if (IsDayOff()) { return; } SendReportEmail(unit); if (WatchWebServer.Instance.SendErrorMessage) { SendReportSMS(unit); } }
public static void SendReports(ServiceStateUnit unit) { // проверка на дублирование отчета if (unit.HasBeenReported()) { var minutesPassed = unit.LastReportTime == new DateTime() ? int.MaxValue : (int)(DateTime.Now - unit.LastReportTime).TotalMinutes; if (minutesPassed < MinutesBetweenReportsOnSameError) return; } // проверка на день недели и время суток (выходной) if (IsDayOff()) return; SendReportEmail(unit); if (WatchWebServer.Instance.SendErrorMessage) SendReportSMS(unit); }
private static void SendReportEmail(ServiceStateUnit unit) { var from = AppConfig.GetStringParam("SMTP.MailFrom", "*****@*****.**"); var recps = AppConfig.GetStringParam("SMTP.Recepients", "*****@*****.**"); var body = string.Format("Состояние сервиса: {0}. Код ошибки: {1} ({2})", unit.LastServiceState.State, unit.LastServiceState.LastError, unit.LastServiceState.LastErrorOccured); var msg = new MailMessage(from, recps, string.Format("Ошибка сервиса {0}", unit.Name), body) { IsBodyHtml = false }; //msg.BodyEncoding = Encoding.Unicode; try { var client = new SmtpClient(); client.Send(msg); unit.UpdateLastReportedData(); Logger.InfoFormat(CultureProvider.Common.ToString(), "Письмо ({0}) отправлено", body); } catch (Exception ex) { Logger.Error("Ошибка доставки сообщения", ex); } }
private static void SendReportSMS(ServiceStateUnit unit) { var body = string.Format("Error in service {0}", unit.Name); SMSNotifier.Instance.SendMessage(body); }
private static void SendReportSMS(ServiceStateUnit unit) { var body = string.Format("Error in service {0}", unit.Name); SMSNotifier.Instance.SendMessage(body); }
public static List <ServiceStateUnit> ReadUnits() { var units = new List <ServiceStateUnit>(); var serviceLocation = ExecutablePath.ExecPath; var settingsPath = serviceLocation + "\\settings.xml"; var xmlDoc = new XmlDocument(); try { xmlDoc.Load(settingsPath); } catch (Exception ex) { Logger.Error(string.Format("Невозможно открыть файл настроек {0}", settingsPath), ex); throw; } try { var docUnits = xmlDoc.SelectSingleNode("*/units"); // сервисы для наблюдения foreach (XmlNode node in docUnits.ChildNodes) { var binding = node.Attributes["binding"].Value; var name = node.Attributes["name"].Value; var severity = node.Attributes["severity"] == null ? GetReportSeverityFlagFromStr("") : GetReportSeverityFlagFromStr(node.Attributes["severity"].Value); var additionalObject = new Dictionary <string, string>(); // читаем дополнительные параметры if (node.Attributes["url"] != null) { additionalObject.Add("url", node.Attributes["url"].Value); } if (node.Attributes["regexp"] != null) { additionalObject.Add("regexp", node.Attributes["regexp"].Value); } var unit = new ServiceStateUnit(binding, severity, name, additionalObject); if (node.Attributes["code"] != null) { unit.Code = node.Attributes["code"].Value; } if (node.Attributes["updateTimoutSec"] != null) { unit.UpdateTimeoutSeconds = int.Parse(node.Attributes["updateTimoutSec"].Value); } units.Add(unit); } return(units); } catch (Exception ex) { Logger.Error(string.Format("Ошибка чтения файла настроек {0}", settingsPath), ex); throw; } }
public static List<ServiceStateUnit> ReadUnits() { var units = new List<ServiceStateUnit>(); var serviceLocation = ExecutablePath.ExecPath; var settingsPath = serviceLocation + "\\settings.xml"; var xmlDoc = new XmlDocument(); try { xmlDoc.Load(settingsPath); } catch (Exception ex) { Logger.Error(string.Format("Невозможно открыть файл настроек {0}", settingsPath), ex); throw; } try { var docUnits = xmlDoc.SelectSingleNode("*/units"); // сервисы для наблюдения foreach (XmlNode node in docUnits.ChildNodes) { var binding = node.Attributes["binding"].Value; var name = node.Attributes["name"].Value; var severity = node.Attributes["severity"] == null ? GetReportSeverityFlagFromStr("") : GetReportSeverityFlagFromStr(node.Attributes["severity"].Value); var additionalObject = new Dictionary<string, string>(); // читаем дополнительные параметры if (node.Attributes["url"] != null) additionalObject.Add("url", node.Attributes["url"].Value); if (node.Attributes["regexp"] != null) additionalObject.Add("regexp", node.Attributes["regexp"].Value); var unit = new ServiceStateUnit(binding, severity, name, additionalObject); if (node.Attributes["code"] != null) unit.Code = node.Attributes["code"].Value; if (node.Attributes["updateTimoutSec"] != null) unit.UpdateTimeoutSeconds = int.Parse(node.Attributes["updateTimoutSec"].Value); units.Add(unit); } return units; } catch (Exception ex) { Logger.Error(string.Format("Ошибка чтения файла настроек {0}", settingsPath), ex); throw; } }