public override HealthCheck Check() { var clients = _downloadClientProvider.GetDownloadClients(); foreach (var client in clients) { try { var status = client.GetStatus(); var folders = status.OutputRootFolders; if (folders != null) { foreach (var folder in folders) { if (!folder.IsValid) { if (!status.IsLocalhost) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Remote download client {client.Definition.Name} places downloads in {folder.FullPath} but this is not a valid {_osInfo.Name} path. Review your remote path mappings and download client settings.", "#bad-remote-path-mapping")); } else if (_osInfo.IsDocker) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"You are using docker; download client {client.Definition.Name} places downloads in {folder.FullPath} but this is not a valid {_osInfo.Name} path. Review your remote path mappings and download client settings.", "#docker-bad-remote-path-mapping")); } else { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Local download client {client.Definition.Name} places downloads in {folder.FullPath} but this is not a valid {_osInfo.Name} path. Review your download client settings.", "#bad-download-client-settings")); } } if (!_diskProvider.FolderExists(folder.FullPath)) { if (_osInfo.IsDocker) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"You are using docker; download client {client.Definition.Name} places downloads in {folder.FullPath} but this directory does not appear to exist inside the container. Review your remote path mappings and container volume settings.", "#docker-bad-remote-path-mapping")); } else if (!status.IsLocalhost) { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Remote download client {client.Definition.Name} places downloads in {folder.FullPath} but this directory does not appear to exist. Likely missing or incorrect remote path mapping.", "#bad-remote-path-mapping")); } else { return(new HealthCheck(GetType(), HealthCheckResult.Error, $"Download client {client.Definition.Name} places downloads in {folder.FullPath} but Readarr cannot see this directory. You may need to adjust the folder's permissions.", "#permissions-error")); } } } } } catch (DownloadClientException ex) { _logger.Debug(ex, "Unable to communicate with {0}", client.Definition.Name); } catch (Exception ex) { _logger.Error(ex, "Unknown error occured in RemotePathMapping HealthCheck"); } } return(new HealthCheck(GetType())); }
private Boolean UpdateTrackedDownloads() { var downloadClients = _downloadClientProvider.GetDownloadClients(); var oldTrackedDownloads = GetTrackedDownloads().ToDictionary(v => v.TrackingId); var newTrackedDownloads = new Dictionary <String, TrackedDownload>(); var stateChanged = false; foreach (var downloadClient in downloadClients) { var downloadClientHistory = downloadClient.GetItems().ToList(); foreach (var downloadItem in downloadClientHistory) { var trackingId = String.Format("{0}-{1}", downloadClient.Definition.Id, downloadItem.DownloadClientId); TrackedDownload trackedDownload; if (newTrackedDownloads.ContainsKey(trackingId)) { continue; } if (!oldTrackedDownloads.TryGetValue(trackingId, out trackedDownload)) { trackedDownload = new TrackedDownload { TrackingId = trackingId, DownloadClient = downloadClient.Definition.Id, StartedTracking = DateTime.UtcNow, State = TrackedDownloadState.Unknown }; _logger.Debug("[{0}] Started tracking download with id {1}.", downloadItem.Title, trackingId); stateChanged = true; } trackedDownload.DownloadItem = downloadItem; newTrackedDownloads[trackingId] = trackedDownload; } } foreach (var trackedDownload in oldTrackedDownloads.Values.Where(v => !newTrackedDownloads.ContainsKey(v.TrackingId))) { if (trackedDownload.State != TrackedDownloadState.Removed) { trackedDownload.State = TrackedDownloadState.Removed; stateChanged = true; _logger.Debug("[{0}] Item with id {1} removed from download client directly (possibly by user).", trackedDownload.DownloadItem.Title, trackedDownload.TrackingId); } _logger.Debug("[{0}] Stopped tracking download with id {1}.", trackedDownload.DownloadItem.Title, trackedDownload.TrackingId); } _trackedDownloadCache.Set("tracked", newTrackedDownloads.Values.ToArray()); return(stateChanged); }
public override HealthCheck Check() { var downloadClients = _downloadClientProvider.GetDownloadClients().ToList(); if (!downloadClients.Any()) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "No download client is available")); } foreach (var downloadClient in downloadClients) { try { downloadClient.GetItems(); } catch (Exception ex) { _logger.Debug(ex, "Unable to communicate with {0}", downloadClient.Definition.Name); var message = $"Unable to communicate with {downloadClient.Definition.Name}."; return(new HealthCheck(GetType(), HealthCheckResult.Error, $"{message} {ex.Message}", "#unable-to-communicate-with-download-client")); } } return(new HealthCheck(GetType())); }
public override HealthCheck Check() { var downloadClients = _downloadClientProvider.GetDownloadClients().ToList(); if (!downloadClients.Any()) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, _localizationService.GetLocalizedString("DownloadClientCheckNoneAvailableMessage"), "#no_download_client_is_available")); } foreach (var downloadClient in downloadClients) { try { downloadClient.GetItems(); } catch (Exception ex) { _logger.Debug(ex, "Unable to communicate with {0}", downloadClient.Definition.Name); var message = string.Format(_localizationService.GetLocalizedString("DownloadClientCheckUnableToCommunicateMessage"), downloadClient.Definition.Name); return(new HealthCheck(GetType(), HealthCheckResult.Error, $"{message} {ex.Message}", "#unable_to_communicate_with_download_client")); } } return(new HealthCheck(GetType())); }
public override HealthCheck Check() { var clients = _downloadClientProvider.GetDownloadClients(); var rootFolders = _rootFolderService.All(); foreach (var client in clients) { try { var status = client.GetStatus(); var folders = status.OutputRootFolders; foreach (var folder in folders) { if (rootFolders.Any(r => r.Path.PathEquals(folder.FullPath))) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, string.Format("Download client {0} places downloads in the root folder {1}. You should not download to a root folder.", client.Definition.Name, folder.FullPath), "#downloads_in_root_folder")); } } } catch (DownloadClientException ex) { _logger.Debug(ex, "Unable to communicate with {0}", client.Definition.Name); } catch (Exception ex) { _logger.Error(ex, "Unknown error occured in DownloadClientRootFolderCheck HealthCheck"); } } return(new HealthCheck(GetType())); }
public override HealthCheck Check() { var downloadClients = _downloadClientProvider.GetDownloadClients().ToList(); if (!downloadClients.Any()) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "No download client is available")); } foreach (var downloadClient in downloadClients) { try { downloadClient.GetItems(); } catch (Exception ex) { var message = String.Format("Unable to communicate with {0}.", downloadClient.Definition.Name); _logger.Error(ex, message); return(new HealthCheck(GetType(), HealthCheckResult.Error, message + " " + ex.Message)); } } return(new HealthCheck(GetType())); }
public override HealthCheck Check() { var clients = _downloadClientProvider.GetDownloadClients(); var rootFolders = _rootFolderService.All(); foreach (var client in clients) { try { var status = client.GetStatus(); var folders = status.OutputRootFolders; if (folders != null) { foreach (var folder in folders) { if (rootFolders.Any(r => r.Path == folder.FullPath)) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, string.Format(_localizationService.GetLocalizedString("DownloadClientCheckDownloadingToRoot"), client.Definition.Name, folder.FullPath), "#downloads_in_root_folder")); } } } } catch (DownloadClientException ex) { _logger.Debug(ex, "Unable to communicate with {0}", client.Definition.Name); } catch (Exception ex) { _logger.Error(ex, "Unknown error occured in DownloadClientRootFolderCheck HealthCheck"); } } return(new HealthCheck(GetType())); }
public override HealthCheck Check() { var droneFactoryFolder = _configService.DownloadedEpisodesFolder; var downloadClients = _provideDownloadClient.GetDownloadClients().Select(v => new { downloadClient = v, status = v.GetStatus() }).ToList(); var downloadClientIsLocalHost = downloadClients.All(v => v.status.IsLocalhost); var downloadClientOutputInDroneFactory = !droneFactoryFolder.IsNullOrWhiteSpace() && downloadClients.Any(v => v.status.OutputRootFolders != null && v.status.OutputRootFolders.Contains(droneFactoryFolder, PathEqualityComparer.Instance)); if (!_configService.IsDefined("EnableCompletedDownloadHandling")) { // Migration helper logic if (!downloadClientIsLocalHost) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Multi-Computer unsupported)", "Migrating-to-Completed-Download-Handling#Unsupported-download-client-on-different-computer")); } if (downloadClients.All(v => v.downloadClient is Sabnzbd)) { // With Sabnzbd we can check if the category should be changed. if (downloadClientOutputInDroneFactory) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Sabnzbd - Conflicting Category)", "Migrating-to-Completed-Download-Handling#sabnzbd-conflicting-download-client-category")); } return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Sabnzbd)", "Migrating-to-Completed-Download-Handling#sabnzbd-enable-completed-download-handling")); } else if (downloadClients.All(v => v.downloadClient is Nzbget)) { // With Nzbget we can check if the category should be changed. if (downloadClientOutputInDroneFactory) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Nzbget - Conflicting Category)", "Migrating-to-Completed-Download-Handling#nzbget-conflicting-download-client-category")); } return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Nzbget)", "Migrating-to-Completed-Download-Handling#nzbget-enable-completed-download-handling")); } else { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible", "Migrating-to-Completed-Download-Handling")); } } if (!_configService.EnableCompletedDownloadHandling && droneFactoryFolder.IsNullOrWhiteSpace()) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling or configure Drone factory")); } if (_configService.EnableCompletedDownloadHandling && !droneFactoryFolder.IsNullOrWhiteSpace()) { if (_downloadTrackingService.GetCompletedDownloads().Any(v => droneFactoryFolder.PathEquals(v.DownloadItem.OutputPath) || droneFactoryFolder.IsParentPath(v.DownloadItem.OutputPath))) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Completed Download Handling conflict with Drone Factory (Conflicting History Item)", "Migrating-to-Completed-Download-Handling#conflicting-download-client-category")); } } return(new HealthCheck(GetType())); }
private void Refresh() { var downloadClients = _downloadClientProvider.GetDownloadClients(); var trackedDownload = new List <TrackedDownload>(); foreach (var downloadClient in downloadClients) { var clientTrackedDownloads = ProcessClientDownloads(downloadClient); trackedDownload.AddRange(clientTrackedDownloads.Where(c => c.State == TrackedDownloadStage.Downloading)); } _eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(trackedDownload)); }
public override HealthCheck Check() { List <ImportMechanismCheckStatus> downloadClients; try { downloadClients = _provideDownloadClient.GetDownloadClients().Select(v => new ImportMechanismCheckStatus { DownloadClient = v, Status = v.GetStatus() }).ToList(); } catch (Exception) { // One or more download clients failed, assume the health is okay and verify later return(new HealthCheck(GetType())); } var downloadClientIsLocalHost = downloadClients.All(v => v.Status.IsLocalhost); if (!_configService.IsDefined("EnableCompletedDownloadHandling")) { // Migration helper logic if (!downloadClientIsLocalHost) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Multi-Computer unsupported)", "Migrating_to_Completed_Download_Handling#Unsupported_download_client_on_different_computer")); } if (downloadClients.All(v => v.DownloadClient is Sabnzbd)) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Sabnzbd)", "Migrating_to_Completed_Download_Handling#sabnzbd_enable_completed_download_handling")); } if (downloadClients.All(v => v.DownloadClient is Nzbget)) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Nzbget)", "Migrating_to_Completed_Download_Handling#nzbget_enable_completed_download_handling")); } return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible", "Migrating_to_Completed_Download_Handling")); } if (!_configService.EnableCompletedDownloadHandling) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling")); } return(new HealthCheck(GetType())); }
public override HealthCheck Check() { var droneFactoryFolder = new OsPath(_configService.DownloadedEpisodesFolder); var downloadClients = _provideDownloadClient.GetDownloadClients().Select(v => new { downloadClient = v, status = v.GetStatus() }).ToList(); var downloadClientIsLocalHost = downloadClients.All(v => v.status.IsLocalhost); var downloadClientOutputInDroneFactory = !droneFactoryFolder.IsEmpty && downloadClients.Any(v => v.status.OutputRootFolders != null && v.status.OutputRootFolders.Any(droneFactoryFolder.Contains)); if (!_configService.IsDefined("EnableCompletedDownloadHandling")) { // Migration helper logic if (!downloadClientIsLocalHost) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Multi-Computer unsupported)", "Migrating-to-Completed-Download-Handling#Unsupported-download-client-on-different-computer")); } if (downloadClients.All(v => v.downloadClient is Sabnzbd)) { // With Sabnzbd we can check if the category should be changed. if (downloadClientOutputInDroneFactory) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Sabnzbd - Conflicting Category)", "Migrating-to-Completed-Download-Handling#sabnzbd-conflicting-download-client-category")); } return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Sabnzbd)", "Migrating-to-Completed-Download-Handling#sabnzbd-enable-completed-download-handling")); } if (downloadClients.All(v => v.downloadClient is Nzbget)) { // With Nzbget we can check if the category should be changed. if (downloadClientOutputInDroneFactory) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Nzbget - Conflicting Category)", "Migrating-to-Completed-Download-Handling#nzbget-conflicting-download-client-category")); } return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Nzbget)", "Migrating-to-Completed-Download-Handling#nzbget-enable-completed-download-handling")); } return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible", "Migrating-to-Completed-Download-Handling")); } if (!_configService.EnableCompletedDownloadHandling && droneFactoryFolder.IsEmpty) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling or configure Drone factory")); } return(new HealthCheck(GetType())); }
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria) { if (searchCriteria != null) { _logger.Debug("Skipping history check during search"); return(Decision.Accept()); } var downloadClients = _downloadClientProvider.GetDownloadClients(); foreach (var downloadClient in downloadClients.OfType <Sabnzbd>()) { _logger.Debug("Performing history status check on report"); foreach (var episode in subject.Episodes) { _logger.Debug("Checking current status of episode [{0}] in history", episode.Id); var mostRecent = _historyService.MostRecentForEpisode(episode.Id); if (mostRecent != null && mostRecent.EventType == HistoryEventType.Grabbed) { _logger.Debug("Latest history item is downloading, rejecting."); return(Decision.Reject("Download has not been imported yet")); } } return(Decision.Accept()); } foreach (var episode in subject.Episodes) { var bestQualityInHistory = _historyService.GetBestQualityInHistory(subject.Series.Profile, episode.Id); if (bestQualityInHistory != null) { _logger.Debug("Comparing history quality with report. History is {0}", bestQualityInHistory); if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.Profile, bestQualityInHistory, subject.ParsedEpisodeInfo.Quality)) { return(Decision.Reject("Existing file in history is of equal or higher quality: {0}", bestQualityInHistory)); } } } return(Decision.Accept()); }
public override HealthCheck Check() { var downloadClients = _downloadClientProvider.GetDownloadClients().ToList(); if (!downloadClients.Any()) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "No download client is available")); } try { foreach (var downloadClient in downloadClients) { downloadClient.GetItems(); } } catch (Exception e) { return(new HealthCheck(GetType(), HealthCheckResult.Error, "Unable to communicate with download client " + e.Message)); } return(new HealthCheck(GetType())); }
private void Refresh() { _refreshDebounce.Pause(); try { var downloadClients = _downloadClientProvider.GetDownloadClients(); var trackedDownloads = new List <TrackedDownload>(); foreach (var downloadClient in downloadClients) { var clientTrackedDownloads = ProcessClientDownloads(downloadClient); // Only track completed downloads if trackedDownloads.AddRange(clientTrackedDownloads.Where(DownloadIsTrackable)); } _eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(trackedDownloads)); } finally { _refreshDebounce.Resume(); } }
public override HealthCheck Check() { // We don't care about client folders if we are not handling completed files if (!_configService.EnableCompletedDownloadHandling) { return(new HealthCheck(GetType())); } var clients = _downloadClientProvider.GetDownloadClients(); foreach (var client in clients) { try { var status = client.GetStatus(); var folders = status.OutputRootFolders; foreach (var folder in folders) { if (!folder.IsValid) { if (!status.IsLocalhost) { return(new HealthCheck(GetType(), HealthCheckResult.Error, string.Format(_localizationService.GetLocalizedString("RemotePathMappingCheckWrongOSPath"), client.Definition.Name, folder.FullPath, _osInfo.Name), "#bad_remote_path_mapping")); } else if (_osInfo.IsDocker) { return(new HealthCheck(GetType(), HealthCheckResult.Error, string.Format(_localizationService.GetLocalizedString("RemotePathMappingCheckBadDockerPath"), client.Definition.Name, folder.FullPath, _osInfo.Name), "#docker_bad_remote_path_mapping")); } else { return(new HealthCheck(GetType(), HealthCheckResult.Error, string.Format(_localizationService.GetLocalizedString("RemotePathMappingCheckLocalWrongOSPath"), client.Definition.Name, folder.FullPath, _osInfo.Name), "#bad_download_client_settings")); } } if (!_diskProvider.FolderExists(folder.FullPath)) { if (_osInfo.IsDocker) { return(new HealthCheck(GetType(), HealthCheckResult.Error, string.Format(_localizationService.GetLocalizedString("RemotePathMappingCheckDockerFolderMissing"), client.Definition.Name, folder.FullPath), "#docker_bad_remote_path_mapping")); } else if (!status.IsLocalhost) { return(new HealthCheck(GetType(), HealthCheckResult.Error, string.Format(_localizationService.GetLocalizedString("RemotePathMappingCheckLocalFolderMissing"), client.Definition.Name, folder.FullPath), "#bad_remote_path_mapping")); } else { return(new HealthCheck(GetType(), HealthCheckResult.Error, string.Format(_localizationService.GetLocalizedString("RemotePathMappingCheckGenericPermissions"), client.Definition.Name, folder.FullPath), "#permissions_error")); } } } } catch (DownloadClientException ex) { _logger.Debug(ex, "Unable to communicate with {0}", client.Definition.Name); } catch (Exception ex) { _logger.Error(ex, "Unknown error occured in RemotePathMapping HealthCheck"); } } return(new HealthCheck(GetType())); }