Esempio n. 1
0
        public async Task <IActionResult> CreateMonitorAsync(MonitorDetails details)
        {
            try {
                var monitor = _monitorModelFactory.Create(details);
                await _monitorRepository.CreateAsync(monitor);

                var result = monitor.GetResultJson(Request.Host, Request.Scheme, Request.Path);
                return(Ok(result.ToString()));
            } catch (Exception ex) {
                _logger.LogError($"Something went wrong inside CreateMonitorAsync: {ex.Message}");
                return(StatusCode(500, "Internal server error."));
            }
        }
        public async Task NotifyAsync()
        {
            try {
                var allMonitors = await _monitorRepository.GetAllAsync();

                var allMonitorIds = allMonitors.Where(x => !x.MonitorDetails.IsDown).Select(x => x.Id);

                var allCheckIns = await _checkInRepository.GetAllAsync();

                var checkInedMonitorIds = allCheckIns.Select(x => x.MonitorId);

                var noCheckinsFor = allMonitorIds.Except(checkInedMonitorIds);

                foreach (var monitorId in noCheckinsFor)
                {
                    var problematicMonitor = allMonitors.Where(x => x.Id.Equals(monitorId)).First();

                    if (problematicMonitor != null)
                    {
                        problematicMonitor.MonitorDetails.IsDown = true;

                        await _monitorRepository.CreateAsync(problematicMonitor);

                        await _emailService.SendEmailAsync(problematicMonitor.MonitorDetails.Subscribers, "Cant find check in for process", "Looks like your process goes off");
                    }
                }
            } catch (Exception ex) {
                _logger.LogError($"Something went wrong inside MonitorStatusNotifyer: {ex.Message}");
            }
        }