示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
        }
示例#4
0
 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);
     }
 }
示例#5
0
 private static void SendReportSMS(ServiceStateUnit unit)
 {
     var body = string.Format("Error in service {0}", unit.Name);
     SMSNotifier.Instance.SendMessage(body);
 }
示例#6
0
        private static void SendReportSMS(ServiceStateUnit unit)
        {
            var body = string.Format("Error in service {0}", unit.Name);

            SMSNotifier.Instance.SendMessage(body);
        }
示例#7
0
        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;
            }
        }
示例#8
0
        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;
            }
        }