public async Task RecordAsync(NcMonitor monitor, MonitorResult result) { var record = monitorManager.LastOpenedMonitorRecord(monitor.Id); if (result.IsSuccess) { if ((record != null && record.EndDate == null) || monitor.StatusEnum() != MonitorStatus.OK) {//ukonceni zaznamu if (record != null) { await monitorManager.UpdateEndDateAsync(record, DateTime.Now); } await notificator.AddNotifyUpAsync(monitor);//poslani notifikace o tom ze web bezi, staci poslat pouze jendou. await monitorManager.SetStatusAndResetLastTestCycleIntervalAsync(monitor, MonitorStatus.OK); } } else { //nastala chyba if (record == null || record.EndDate != null || monitor.StatusEnum() != MonitorStatus.Error) { //neexistuje zadny zaznam nebo jsou vsechny uzavreny await monitorManager.SetStatusAndResetLastTestCycleIntervalAsync(monitor, MonitorStatus.Error); await AddNewRecordAsync(monitor, result); } //posilani notifikaci se provadi stale dokud je monitor v chybovem stavu await notificator.AddNotifyDownAsync(monitor); } }
/// <summary> /// Prida notifikaci o vypadku do fronty. /// </summary> /// <param name="monitor"></param> /// <returns></returns> public async Task AddNotifyDownAsync(NcMonitor monitor) { NcMonitorRecord monitorRecord = monitorManager.LastOpenedMonitorRecord(monitor.Id); if (monitorRecord == null) {//vsechny zaznamy jsou j*z uzavreny, uz neni error. return; } await NotifyAsync(monitor, $"[MONITORING DOWN] {monitor.Name}", $"Monitor '{monitor.Name}' for url '{monitor.Url}' with verificaiton rule '{monitor.VerificationEnum()}={monitor.VerificationValue}' is now down." + $"\n\nRecord note: {monitorRecord.Note}", notifyUp : false); }