public static void Run() { try { log.Debug("--Run HealthCheck--"); if (GetFakeTenant() == 0) { log.ErrorFormat("Error! Could not create tenant alias = {0}", FakeTenantAlias); return; } GetFakeUserId(); var mainLoopPeriod = HealthCheckCfgSectionHandler.Instance.MainLoopPeriod; foreach (var service in HealthCheckCfgSectionHandler.Instance.ServiceNames) { log.DebugFormat("Add service {0} for checking.", service); serviceRepository.Add(service); TimerDictionary.TryAdd(service.ToString(), new Timer(IdleTimeout, service, TimeSpan.Zero, mainLoopPeriod)); } IDriveSpaceChecker spaceChecker = new DriveSpaceChecker(); TimerDictionary.TryAdd(spaceChecker.DriveName, new Timer(IdleTimeoutDriveSpace, spaceChecker.DriveName, TimeSpan.Zero, mainLoopPeriod)); } catch (Exception ex) { log.ErrorFormat("Error on HealthCheckRunner.Run. {0} {1}", ex, ex.InnerException != null ? ex.InnerException.Message : string.Empty); } }
private static void IdleTimeoutDriveSpace(object e) { try { var healthCheckSettings = HealthCheckSettingsAccessor.GetHealthCheckSettings(); /*var tenants = CoreContext.TenantManager.GetTenants().Where(t => t.TenantId != healthCheckSettings.FakeTenantId).ToList(); * if (tenants.Count() <= 0 || !CoreContext.TenantManager.GetTenantQuota(tenants.First().TenantId).HealthCheck) * { * log.Debug("Service wasn't started. There is no correct license for HealthCheck."); * return; * }*/ log.Debug("Begin IdleTimeoutDriveSpace"); CoreContext.TenantManager.SetCurrentTenant(healthCheckSettings.FakeTenantId); Thread.CurrentThread.CurrentCulture = CoreContext.TenantManager.GetCurrentTenant().GetCulture(); IDriveSpaceChecker spaceChecker = new DriveSpaceChecker(); spaceChecker.GetTotalAndFreeSpace(); var freeSpace = spaceChecker.TotalFreeSpace; if (freeSpace == -1) { log.Error("Not found drive name."); return; } var space = freeSpace / OneMb + " Mb"; var driveSpaceThreashold = HealthCheckCfgSectionHandler.Instance.DriveSpaceThreashold; if (freeSpace >= driveSpaceThreashold) { log.DebugFormat("It is enough free disk space, {0}.", space); alreadyNotifyAboutSmallDiskSpace = false; return; } // Send sms and e-mail about small free disk space log.WarnFormat("It isn't enough free disk space, {0}.", space); if (alreadyNotifyAboutSmallDiskSpace) { return; } if (!healthCheckSettings.SendNotify || (!healthCheckSettings.SendEmail && !healthCheckSettings.SendSms)) { log.Debug("Notification isn't sent. Notifications disabled."); return; } alreadyNotifyAboutSmallDiskSpace = true; if (healthCheckSettings.SendEmail) { log.Debug("Send email notification"); SendEmail("Onlyoffice:" + HealthCheckResource.SmallDriveSpace + ": " + space, HealthCheckResource.SmallDriveSpace + ": " + space, healthCheckSettings); } else { log.Debug("Email isn't sent. Email notification disabled."); } if (healthCheckSettings.SendSms) { log.Debug("Send SMS notification"); SendSms(HealthCheckResource.SmallDriveSpace + ": " + space, healthCheckSettings); } else { log.Debug("SMS isn't sent. SMS notifications disabled."); } } catch (Exception ex) { log.ErrorFormat("Error on IdleTimeoutDriveSpace. {0} {1} {2}", ex.Message, ex.StackTrace, ex.InnerException != null ? ex.InnerException.Message : string.Empty); } finally { log.Debug("End IdleTimeoutDriveSpace"); } }