Example #1
0
        public async Task RunMonitor(int thresholdValue, string jobName)
        {
            var thresholdInfo = await _dbTargetRepository.GetThreshold();

            if (jobName == null)
            {
                return;
            }
            var info = thresholdInfo.ToList().FirstOrDefault(x => x.ServerName.ToLower() == jobName.ToLower());

            if (!string.IsNullOrEmpty(info.ServerName) && Enum.IsDefined(typeof(DatabaseType), info.DbType))
            {
                var oracleServer = new OracleServer(info.ServerName, _configuration, _logger);

                var dto = new ThresholdInfoDto {
                    ThresholdInfo = info, MonitorLog = new MonitorLog()
                };
                if (!oracleServer.IsConnected)
                {
                    _eventPublisher.Publish(info);
                    return;
                }
                var sharedPoolSize = await oracleServer.GetSharedPoolSize();

                dto.MonitorLog.ServerName = info.ServerName;
                dto.MonitorLog.CreateDate = DateTime.Now;
                dto.MonitorLog.Threshold  = thresholdValue;
                dto.MonitorLog.Usage      = sharedPoolSize.SizeByMB;
                if (sharedPoolSize.SizeByMB > thresholdValue)
                {
                    _eventPublisher.Publish(dto);
                }
            }
        }
Example #2
0
        public async Task SendMail(ThresholdInfo eventMessage, string templateName = "")
        {
            var messageTemplate = (await _dbTargetRepository.GetTemplate()).Where(x => x.TemplateName == templateName).ToList().FirstOrDefault();

            if (messageTemplate == null)
            {
                return;
            }
            var emailAccount = _mailConfig.Value.EmailAccount;
            var contacts     = await GetContactListByServerId(eventMessage.Id);

            var dto = new ThresholdInfoDto {
                ThresholdInfo = eventMessage, MonitorLog = null
            };
            var message = GetTemplateWithTkn(messageTemplate, dto);

            foreach (var contact in contacts)
            {
                if (!string.IsNullOrEmpty(contact.Email))
                {
                    _emailSender.SendEmail(emailAccount,
                                           message.Subject,
                                           message.Content,
                                           emailAccount.Email, emailAccount.DisplayName,
                                           contact.Email,
                                           contact.Name);
                }
            }
        }
Example #3
0
        public async Task SendSMS(ThresholdInfoDto eventMessage, string templateName = "")
        {
            var messageTemplate = (await _dbTargetRepository.GetTemplate()).Where(x => x.TemplateName == templateName).ToList().FirstOrDefault();

            if (messageTemplate == null)
            {
                return;
            }
            var contacts = await GetContactListByServerId(eventMessage.ThresholdInfo.Id);

            var message    = GetTemplateWithTkn(messageTemplate, eventMessage);
            var smsService = new SMSHttp();

            foreach (var contact in contacts)
            {
                if (!smsService.GetCredit())
                {
                    return;
                }
                var result = smsService.SendSMS(message.Subject, message.Content, contact.Cellphone, "");//DateTime.Now.ToString("yyyyMMddHHmmss")
                if (!result)
                {
                    //  await Log();
                }
            }
        }
Example #4
0
        private Template GetTemplateWithTkn(Template messageTemplate, ThresholdInfoDto eventMessage)
        {
            var    tokens  = GenerateTokens(messageTemplate, eventMessage);
            string subject = _tokenizer.Replace(messageTemplate.Subject, tokens, htmlEncode: false);
            string body    = _tokenizer.Replace(messageTemplate.Content, tokens, htmlEncode: true);

            messageTemplate.Subject = subject;
            messageTemplate.Content = body;
            return(messageTemplate);
        }
Example #5
0
        private IList <Token> GenerateTokens(Template messageTemplate, ThresholdInfoDto model)
        {
            IList <Token> list = new List <Token>();

            switch (messageTemplate.TemplateName)
            {
            case "DB.Warning":
                list.Add(new Token("ServerName", model.ThresholdInfo.ServerName));
                list.Add(new Token("Threshold", model.MonitorLog.Usage));
                return(list);

            case "DB.Status":
                list.Add(new Token("ServerName", model.ThresholdInfo.ServerName));
                break;
            }

            return(list);
        }