/// <summary> /// The execution of this command. /// </summary> /// <param name="items">The items.</param> /// <param name="command">The command.</param> /// <param name="schedule">The schedule.</param> public void Execute(Item[] items, Sitecore.Tasks.CommandItem command, Sitecore.Tasks.ScheduleItem schedule) { Sitecore.Diagnostics.Log.Info("[Sitecore.Healthcheck] Healthcheck Update started", this); var healthcheckService = new HealthcheckService(new ComponentFactory()); if (items != null && items.Length > 0) { foreach (var item in items) { healthcheckService.RunHealthcheck(item.ID.ToString()); } } else { healthcheckService.RunHealthcheck(); } Sitecore.Diagnostics.Log.Info("[Sitecore.Healthcheck] Healthcheck Update finished", this); Sitecore.Diagnostics.Log.Info("[Sitecore.Healthcheck] Send Email Report started", this); try { var repository = new HealthcheckRepository(); var components = repository.GetHealthcheck(); if (components.SelectMany(t => t.Components).Any(t => t.Status == Customization.HealthcheckStatus.Waiting)) { // If there is any pending remote check, lets wait 1 minute and retrieve it again Thread.Sleep(60 * 1000); components = repository.GetHealthcheck(); } if (items != null && items.Length > 0) { foreach (var component in components) { component.Components = component.Components.Where(t => items.Any(p => p.ID.ToString().Equals(t.Id, StringComparison.OrdinalIgnoreCase))).ToList(); } components = components.Where(t => t.Components != null && t.Components.Any()).ToList(); } var healthcheckReport = new HealthcheckReport(new EmailService()); healthcheckReport.SendEmailReport(components); } catch (Exception e) { Sitecore.Diagnostics.Log.Info("[Sitecore.Healthcheck] Error while sending the report", this); Sitecore.Diagnostics.Log.Info(e.Message, e.Source); } Sitecore.Diagnostics.Log.Info("[Sitecore.Healthcheck] Send Email Report finished", this); }
public HealthcheckServiceTest() { _appVersionPath = "./Unit/version.txt"; _shaPath = "./Unit/sha.txt"; _fileWrapperMock = new Mock <IFileWrapper>(); SetUpFakeFileSystem(); _cacheWrapper = new Mock <ICache>(); _healthcheckService = CreateHealthcheckService(_appVersionPath, _shaPath); }
public HealthcheckServiceTest() { _appVersionPath = "./Unit/version.txt"; _shaPath = "./Unit/sha.txt"; _fileWrapperMock = new Mock <IFileWrapper>(); _businessId = new BusinessId("businessId"); _mockUrlGenerator = new Mock <IStubToUrlConverter>(); _mockUrlGenerator.Setup(o => o.HealthcheckUrl()).Returns(healthcheckUrl); _configuration = new Mock <IApplicationConfiguration>(); _configuration.Setup(_ => _.GetContentApiAuthenticationKey()).Returns("AuthKey"); var httpResponseMessage = new HttpResponse(200, "{\"appVersion\":\"dev\",\"sha\":\"test-sha\",\"environment\":\"local\",\"redisValueData\":[]}", ""); _mockHttpClient .Setup(_ => _.Get(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >())) .ReturnsAsync(httpResponseMessage); SetUpFakeFileSystem(); _healthcheckService = CreateHealthcheckService(_appVersionPath, _shaPath, new FeatureToggles()); }
public async Task ShouldSetAppDependenciesToNullIfRequestToContentApi() { _mockHttpClient .Setup(_ => _.Get(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >())) .ReturnsAsync(default(HttpResponse)); var healthcheckService = new HealthcheckService(_appVersionPath, _shaPath, _fileWrapperMock.Object, new FeatureToggles(), _mockHttpClient.Object, _mockUrlGenerator.Object, "local", _configuration.Object, _businessId); var check = await healthcheckService.Get(); check.Dependencies.Should().NotBeNull(); check.Dependencies.Should().ContainKey("contentApi"); var dependency = check.Dependencies["contentApi"]; dependency.AppVersion.Should().Be("Not available"); dependency.SHA.Should().Be("Not available"); dependency.FeatureToggles.Should().BeNull(); dependency.Dependencies.Should().BeEmpty(); }