Exemple #1
0
        private static void InternalHandleAlarm(AlarmConfigurationItemBase configItem, AlarmServiceStateItem state, string groupName, int count, string columnName, Func <string> getDetail)
        {
            var group = AlarmConfiguration.GetConfig().AlarmReceiverGroups.Values.FirstOrDefault(g => g.GroupName == groupName);

            if (group == null)
            {
                return;
            }
            var logMessgae = FormatMessage(AlarmConfiguration.GetConfig().LogMessageTemlate, configItem, count, columnName, null);

            CreateAlarmEvent(configItem);

            bool b = AlarmIsHandling(configItem.ConfigName);

            if (group.EnableMailMessage)
            {
                var mailPastTime = DateTime.Now - state.AlarmReceiverGroupLastMailMessageTime;
                if (b)
                {
                    AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm", "事件正在处理,暂停报警",
                                                             new ExtraInfo
                    {
                        DropDownListFilterItem1 = "事件正在处理,暂停邮件报警",
                        DropDownListFilterItem2 = configItem.ConfigName,
                    });
                }
                else if (state.AlarmReceiverGroupLastMailMessageTime == DateTime.MinValue || mailPastTime > group.MailMessageIntervalTimeSpan)
                {
                    var mailItems = group.AlarmReceivers.Select(r =>
                    {
                        var contact = GetMongodbAdminConfigurationItem(r.Value.Name);
                        if (contact != null && !string.IsNullOrEmpty(contact.MailAddress))
                        {
                            return(new MailItem
                            {
                                MailAddress = contact.MailAddress,
                                MailTitle = FormatMessage(AlarmConfiguration.GetConfig().MailTitleTemplate, configItem, count, columnName, getDetail),
                                MailBody = FormatMessage(AlarmConfiguration.GetConfig().MailBodyTemplate, configItem, count, columnName, getDetail),
                            });
                        }
                        return(null);
                    }).ToList();

                    mailItems.Where(item => item != null).ToList().ForEach(mailItem =>
                    {
                        mailMemoryQueueService.Enqueue(mailItem);
                        AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm",
                                                                 string.Format("{0} {1} > {2} 达到邮件发送条件 -> {3}", logMessgae, mailPastTime.ToString(), group.MailMessageIntervalTimeSpan.ToString(), mailItem.MailAddress),
                                                                 new ExtraInfo
                        {
                            DropDownListFilterItem1 = "达到邮件发送条件",
                            DropDownListFilterItem2 = configItem.ConfigName,
                        });
                    });
                    state.AlarmReceiverGroupLastMailMessageTime = DateTime.Now;
                }
                else
                {
                    AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm",
                                                             string.Format("{0} {1} <= {2} 没达到邮件发送条件", logMessgae, mailPastTime.ToString(), group.MailMessageIntervalTimeSpan.ToString()),
                                                             new ExtraInfo
                    {
                        DropDownListFilterItem1 = "没达到邮件发送条件",
                        DropDownListFilterItem2 = configItem.ConfigName,
                    });
                }
            }

            if (group.EnableMobileMessage)
            {
                var mobilePastTime = DateTime.Now - state.AlarmReceiverGroupLastMobileMessageTime;
                if (b)
                {
                    AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm", "事件正在处理,暂停报警",
                                                             new ExtraInfo
                    {
                        DropDownListFilterItem1 = "事件正在处理,暂停短信报警",
                        DropDownListFilterItem2 = configItem.ConfigName,
                    });
                }
                else if (state.AlarmReceiverGroupLastMobileMessageTime == DateTime.MinValue || mobilePastTime > group.MobileMessageIntervalTimeSpan)
                {
                    var mobileItems = group.AlarmReceivers.Select(r =>
                    {
                        var contact = GetMongodbAdminConfigurationItem(r.Value.Name);
                        if (contact != null && !string.IsNullOrEmpty(contact.MobileNumber))
                        {
                            return(new MobileItem
                            {
                                MobileNumber = contact.MobileNumber,
                                MobileMessage = FormatMessage(AlarmConfiguration.GetConfig().MobileMessageTemlate, configItem, count, columnName, getDetail),
                            });
                        }
                        ;
                        return(null);
                    }).ToList();

                    mobileItems.Where(item => item != null).ToList().ForEach(mobileItem =>
                    {
                        mobileMemoryQueueService.Enqueue(mobileItem);
                        AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm",
                                                                 string.Format("{0} {1} > {2} 达到短信发送条件 -> {3}", logMessgae, mobilePastTime.ToString(), group.MobileMessageIntervalTimeSpan.ToString(), mobileItem.MobileNumber),
                                                                 new ExtraInfo
                        {
                            DropDownListFilterItem1 = "达到短信发送条件",
                            DropDownListFilterItem2 = configItem.ConfigName,
                        });
                    });
                    state.AlarmReceiverGroupLastMobileMessageTime = DateTime.Now;
                }
                else
                {
                    AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm",
                                                             string.Format("{0} {1} <= {2} 没达到短信发送条件", logMessgae, mobilePastTime.ToString(), group.MobileMessageIntervalTimeSpan.ToString()), new ExtraInfo
                    {
                        DropDownListFilterItem1 = "没达到短信发送条件",
                        DropDownListFilterItem2 = configItem.ConfigName,
                    });
                }
            }
        }
Exemple #2
0
        private static void InternalHandleAlarm(AlarmConfigurationItemBase configItem, AlarmServiceStateItem state, string groupName, int count, string columnName, Func<string> getDetail)
        {
            var group = AlarmConfiguration.GetConfig().AlarmReceiverGroups.Values.FirstOrDefault(g => g.GroupName == groupName);
            if (group == null) return;
            var logMessgae = FormatMessage(AlarmConfiguration.GetConfig().LogMessageTemlate, configItem, count, columnName, null);

            CreateAlarmEvent(configItem);

            bool b = AlarmIsHandling(configItem.ConfigName);

            if (group.EnableMailMessage)
            {
                var mailPastTime = DateTime.Now - state.AlarmReceiverGroupLastMailMessageTime;
                if (b)
                {
                    AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm", "事件正在处理,暂停报警",
                        new ExtraInfo
                        {
                            DropDownListFilterItem1 = "事件正在处理,暂停邮件报警",
                            DropDownListFilterItem2 = configItem.ConfigName,
                        });
                }
                else if (state.AlarmReceiverGroupLastMailMessageTime == DateTime.MinValue || mailPastTime > group.MailMessageIntervalTimeSpan)
                {
                    var mailItems = group.AlarmReceivers.Select(r =>
                    {
                        var contact = GetMongodbAdminConfigurationItem(r.Value.Name);
                        if (contact != null && !string.IsNullOrEmpty(contact.MailAddress))
                        {
                            return new MailItem
                            {
                                MailAddress = contact.MailAddress,
                                MailTitle = FormatMessage(AlarmConfiguration.GetConfig().MailTitleTemplate, configItem, count, columnName, getDetail),
                                MailBody = FormatMessage(AlarmConfiguration.GetConfig().MailBodyTemplate, configItem, count, columnName, getDetail),
                            };
                        }
                        return null;
                    }).ToList();

                    mailItems.Where(item => item != null).ToList().ForEach(mailItem =>
                    {
                        mailMemoryQueueService.Enqueue(mailItem);
                        AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm",
                            string.Format("{0} {1} > {2} 达到邮件发送条件 -> {3}", logMessgae, mailPastTime.ToString(), group.MailMessageIntervalTimeSpan.ToString(), mailItem.MailAddress),
                            new ExtraInfo
                            {
                                DropDownListFilterItem1 = "达到邮件发送条件",
                                DropDownListFilterItem2 = configItem.ConfigName,
                            });
                    });
                    state.AlarmReceiverGroupLastMailMessageTime = DateTime.Now;
                }
                else
                {
                    AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm",
                        string.Format("{0} {1} <= {2} 没达到邮件发送条件", logMessgae, mailPastTime.ToString(), group.MailMessageIntervalTimeSpan.ToString()),
                        new ExtraInfo
                        {
                            DropDownListFilterItem1 = "没达到邮件发送条件",
                            DropDownListFilterItem2 = configItem.ConfigName,
                        });
                }
            }

            if (group.EnableMobileMessage)
            {
                var mobilePastTime = DateTime.Now - state.AlarmReceiverGroupLastMobileMessageTime;
                if (b)
                {
                    AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm", "事件正在处理,暂停报警",
                        new ExtraInfo
                        {
                            DropDownListFilterItem1 = "事件正在处理,暂停短信报警",
                            DropDownListFilterItem2 = configItem.ConfigName,
                        });
                }
                else if (state.AlarmReceiverGroupLastMobileMessageTime == DateTime.MinValue || mobilePastTime > group.MobileMessageIntervalTimeSpan)
                {
                    var mobileItems = group.AlarmReceivers.Select(r =>
                    {
                        var contact = GetMongodbAdminConfigurationItem(r.Value.Name);
                        if (contact != null && !string.IsNullOrEmpty(contact.MobileNumber))
                        {
                            return new MobileItem
                            {
                                MobileNumber = contact.MobileNumber,
                                MobileMessage = FormatMessage(AlarmConfiguration.GetConfig().MobileMessageTemlate, configItem, count, columnName, getDetail),
                            };
                        };
                        return null;
                    }).ToList();

                    mobileItems.Where(item => item != null).ToList().ForEach(mobileItem =>
                    {
                        mobileMemoryQueueService.Enqueue(mobileItem);
                        AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm",
                            string.Format("{0} {1} > {2} 达到短信发送条件 -> {3}", logMessgae, mobilePastTime.ToString(), group.MobileMessageIntervalTimeSpan.ToString(), mobileItem.MobileNumber),
                            new ExtraInfo
                            {
                                DropDownListFilterItem1 = "达到短信发送条件",
                                DropDownListFilterItem2 = configItem.ConfigName,
                            });
                    });
                    state.AlarmReceiverGroupLastMobileMessageTime = DateTime.Now;
                }
                else
                {
                    AppInfoCenterService.LoggingService.Info(AlarmConfigurationBase.ModuleName, "AlarmService", "InternalHandleAlarm",
                        string.Format("{0} {1} <= {2} 没达到短信发送条件", logMessgae, mobilePastTime.ToString(), group.MobileMessageIntervalTimeSpan.ToString()), new ExtraInfo
                        {
                            DropDownListFilterItem1 = "没达到短信发送条件",
                            DropDownListFilterItem2 = configItem.ConfigName,
                        });
                }
            }
        }