Esempio n. 1
0
        protected override void Run()
        {
            try
            {
                var diagnosticToken = Pool.HealthCheckSettings.GetSecretyInfo(Session, HealthCheckSettings.DIAGNOSTIC_TOKEN_SECRET);
                if (string.IsNullOrEmpty(diagnosticToken))
                {
                    log.InfoFormat("Cannot get the diagnostic result for {0}, because couldn't retrieve the diagnostic token", Pool.Name);
                    Description = Messages.ACTION_GET_HEALTH_CHECK_RESULT_FAILED;
                    return;
                }
                if (!Pool.HealthCheckSettings.HasUpload)
                {
                    log.InfoFormat("Cannot get the diagnostic result for {0}, because the there is no upload completed yet", Pool.Name);
                    Description = Messages.ACTION_GET_HEALTH_CHECK_RESULT_FAILED;
                    return;
                }
                var analysisResult = GetAnalysisResult(diagnosticToken, Pool.HealthCheckSettings.UploadUuid);
                log.Info("Saving analysis result");
                Dictionary <string, string> newConfig = Pool.health_check_config;
                newConfig[HealthCheckSettings.REPORT_ANALYSIS_SEVERITY]        = HealthCheckSettings.DiagnosticAlertSeverityToString(GetMaxSeverity(analysisResult));
                newConfig[HealthCheckSettings.REPORT_ANALYSIS_ISSUES_DETECTED] = analysisResult.Count.ToString();
                newConfig[HealthCheckSettings.REPORT_ANALYSIS_UPLOAD_UUID]     = Pool.HealthCheckSettings.UploadUuid;
                newConfig[HealthCheckSettings.REPORT_ANALYSIS_UPLOAD_TIME]     = Pool.HealthCheckSettings.LastSuccessfulUpload;
                Pool.set_health_check_config(Session, Pool.opaque_ref, newConfig);
            }
            catch (Exception e)
            {
                log.InfoFormat("Exception while getting diagnostic result from {0}. Exception Message: {1} ", diagnosticDomainName, e.Message);
                Description = Messages.ACTION_GET_HEALTH_CHECK_RESULT_FAILED;
                throw;
            }

            Description = Messages.COMPLETED;
        }
Esempio n. 2
0
        public AkkaHealthCheck(HealthCheckSettings settings, ExtendedActorSystem system)
        {
            Settings = settings;

            if (!settings.Misconfigured)
            {
                LivenessProvider  = TryCreateProvider(settings.LivenessProbeProvider, system);
                ReadinessProvider = TryCreateProvider(settings.ReadinessProbeProvider, system);
            }
            else // if we are misconfigured
            {
                LivenessProvider  = new MisconfiguredLivenessProvider(system);
                ReadinessProvider = new MisconfiguredReadinessProvider(system);
            }

            // start the probes
            LivenessProbe  = system.SystemActorOf(LivenessProvider.ProbeProps, "healthcheck-live");
            ReadinessProbe = system.SystemActorOf(ReadinessProvider.ProbeProps, "healthcheck-readiness");

            // Need to set up transports (possibly)
            LivenessTransportActor = StartTransportActor(Settings.LivenessTransportSettings, system, ProbeKind.Liveness,
                                                         LivenessProbe);

            ReadinessTransportActor = StartTransportActor(Settings.ReadinessTransportSettings, system,
                                                          ProbeKind.Readiness, ReadinessProbe);
        }
 public TransferHealthCheckSettingsAction(Pool pool, HealthCheckSettings healthCheckSettings, string username, string password, bool suppressHistory)
     : base(pool.Connection, Messages.ACTION_TRANSFER_HEALTHCHECK_SETTINGS, string.Format(Messages.ACTION_TRANSFER_HEALTHCHECK_SETTINGS, pool.Name), suppressHistory)
 {
     this.pool = pool;
     this.healthCheckSettings = healthCheckSettings;
     this.username = username;
     this.password = password;
 }
 public SaveHealthCheckSettingsAction(Pool pool, HealthCheckSettings healthCheckSettings, string authenticationToken, string userName, string passWord, bool suppressHistory)
     : base(pool.Connection, Messages.ACTION_SAVE_HEALTHCHECK_SETTINGS, string.Format(Messages.ACTION_SAVING_HEALTHCHECK_SETTINGS, pool.Name), suppressHistory)
 {
     this.pool = pool;
     this.healthCheckSettings = healthCheckSettings;
     this.authenticationToken = authenticationToken;
     this.username = healthCheckSettings.Status == HealthCheckStatus.Enabled ? userName : null;
     this.password = healthCheckSettings.Status == HealthCheckStatus.Enabled ? passWord : null;
 }
 public string GetLastUploadDescription(HealthCheckSettings healthCheckSettings)
 {
     if (!string.IsNullOrEmpty(healthCheckSettings.LastSuccessfulUpload))
     {
         DateTime lastSuccessfulUpload;
         if (HealthCheckSettings.TryParseStringToDateTime(healthCheckSettings.LastSuccessfulUpload, out lastSuccessfulUpload))
         {
             return HelpersGUI.DateTimeToString(lastSuccessfulUpload.ToLocalTime(), Messages.DATEFORMAT_DMY_HM, true);
         }
     }
     return string.Empty;
 }
Esempio n. 6
0
        public void Should_load_default_HealthCheck_Settings()
        {
            var settings = new HealthCheckSettings(HealthCheckSettings.DefaultConfig().GetConfig("akka.healthcheck"));

            settings.Misconfigured.Should().BeFalse();
            settings.LivenessProbeProvider.Should().Be(typeof(DefaultLivenessProvider));
            settings.ReadinessProbeProvider.Should().Be(typeof(DefaultReadinessProvider));
            settings.LivenessTransport.Should().Be(ProbeTransport.Custom);
            settings.ReadinessTransport.Should().Be(ProbeTransport.Custom);
            settings.LivenessTransportSettings.Should().BeOfType <CustomTransportSettings>();
            settings.ReadinessTransportSettings.Should().BeOfType <CustomTransportSettings>();
        }
Esempio n. 7
0
        public void SendSMS(string number, string message, HealthCheckSettings healthCheckSettings)
        {
            if (string.IsNullOrWhiteSpace(number)) throw new ArgumentException("number");
            if (string.IsNullOrWhiteSpace(message)) throw new ArgumentException("message");
            if (healthCheckSettings == null) throw new ArgumentNullException("healthCheckSettings");

            log.DebugFormat("SendSMS: number = {0}, message = {1}", number, message);
            if ("log".Equals(ConfigurationManager.AppSettings["core.notify.postman"], StringComparison.InvariantCultureIgnoreCase))
            {
                log.InfoFormat("Send notify sms to phoneNumber: {0}\n Message: {1}", number, message);
                return;
            }

            number = new Regex("[^\\d+]").Replace(number, string.Empty);

            var url = healthCheckSettings.SmsOperatorUrlClickatel;
            var method = PostMethod;

            if (!string.IsNullOrEmpty(SMSUSAregex) &&
                Regex.IsMatch(number, SMSUSAregex))
            {
                url = healthCheckSettings.SmsOperatorUrlClickatelUSA;
            }

            if (!string.IsNullOrEmpty(SMSCISregex) &&
                Regex.IsMatch(number, SMSCISregex))
            {
                url = healthCheckSettings.SmsOperatorUrlSmsc;
                method = GetMethod;
            }

            try
            {
                var request = (HttpWebRequest)WebRequest.Create(url.Replace("{phone}", number).Replace("{text}", HttpUtility.UrlEncode(message)));
                request.Method = method;
                request.ContentType = "application/x-www-form-urlencoded";
                request.Timeout = 1000;

                using (var stream = request.GetResponse().GetResponseStream())
                using (var reader = new StreamReader(stream))
                {
                    var result = reader.ReadToEnd();
                    log.InfoFormat("SMS was sent to {0}, service returned: {1}", number, result);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("SendSMS: Failed to send sms message. {0} {1}",
                    ex.ToString(), ex.InnerException != null ? ex.InnerException.Message : string.Empty);
                return;
            }
        }
Esempio n. 8
0
        public void Should_signal_misconfiguration_when_Readiness_provider_is_invalid()
        {
            var hocon = ConfigurationFactory.ParseString(@"
                akka.healthcheck.readiness.provider = ""Akka.Fake.FakeProvider, Akka.Fake""
            ");

            var settings = new HealthCheckSettings(hocon.WithFallback(HealthCheckSettings.DefaultConfig())
                                                   .GetConfig("akka.healthcheck"));

            settings.Misconfigured.Should().BeTrue();
            settings.LivenessProbeProvider.Should().Be(typeof(DefaultLivenessProvider));
            settings.ReadinessProbeProvider.Should().Be(typeof(DefaultReadinessProvider));
        }
 public HealthCheckSettingsDialog(Pool pool, bool enrollNow)
 {
     this.pool = pool;
     healthCheckSettings = pool.HealthCheckSettings;
     if (enrollNow)
         healthCheckSettings.Status = HealthCheckStatus.Enabled;
     authenticationToken = healthCheckSettings.GetExistingSecretyInfo(pool.Connection, HealthCheckSettings.UPLOAD_TOKEN_SECRET);
     xsUserName = healthCheckSettings.GetSecretyInfo(pool.Connection, HealthCheckSettings.UPLOAD_CREDENTIAL_USER_SECRET);
     xsPassword = healthCheckSettings.GetSecretyInfo(pool.Connection, HealthCheckSettings.UPLOAD_CREDENTIAL_PASSWORD_SECRET);
     InitializeComponent();
     PopulateControls();
     InitializeControls();
     UpdateButtons();
 }
Esempio n. 10
0
        public void Should_load_non_default_Log_Settings()
        {
            var hocon = ConfigurationFactory.ParseString(@"
                akka.healthcheck{         
                                 log-config-on-start = off
                                 log-info = off
            }");

            var settings = new HealthCheckSettings(hocon.WithFallback(HealthCheckSettings.DefaultConfig())
                                                   .GetConfig("akka.healthcheck"));

            settings.LogConfigOnStart.Should().BeFalse();
            settings.LogInfoEvents.Should().BeFalse();
        }
        public AkkaHealthCheck(HealthCheckSettings settings, ExtendedActorSystem system)
        {
            Settings = settings;

            if (settings.LogConfigOnStart)
            {
                system.Log.Info("Liveness Prove Provider: {0}", Settings.LivenessProbeProvider);
                system.Log.Info("Liveness Transport Type: {0}", Settings.LivenessTransport.ToString());
                system.Log.Info(Settings.LivenessTransportSettings.StartupMessage);
                system.Log.Info("Readiness Prove Provider: {0}", Settings.ReadinessProbeProvider);
                system.Log.Info("Readines Transport Type: {0}", Settings.ReadinessTransport.ToString());
                system.Log.Info(Settings.ReadinessTransportSettings.StartupMessage);
            }

            if (!settings.Misconfigured)
            {
                if (settings.LogConfigOnStart)
                {
                    system.Log.Info("Settings Correctly Configured");
                }
                LivenessProvider  = TryCreateProvider(settings.LivenessProbeProvider, system);
                ReadinessProvider = TryCreateProvider(settings.ReadinessProbeProvider, system);
            }
            else // if we are misconfigured
            {
                if (settings.LogConfigOnStart)
                {
                    system.Log.Info("Settings Misconfigured");
                }
                LivenessProvider  = new MisconfiguredLivenessProvider(system);
                ReadinessProvider = new MisconfiguredReadinessProvider(system);
            }

            // start the probes
            LivenessProbe  = system.SystemActorOf(LivenessProvider.ProbeProps, "healthcheck-live");
            ReadinessProbe = system.SystemActorOf(ReadinessProvider.ProbeProps, "healthcheck-readiness");

            // Need to set up transports (possibly)
            LivenessTransportActor = StartTransportActor(Settings.LivenessTransportSettings, system, ProbeKind.Liveness,
                                                         LivenessProbe, Settings.LogInfoEvents);

            ReadinessTransportActor = StartTransportActor(Settings.ReadinessTransportSettings, system,
                                                          ProbeKind.Readiness, ReadinessProbe, Settings.LogInfoEvents);
        }
Esempio n. 12
0
        private void SaveAndClose()
        {
            if (ChangesMade())
            {
                var newHealthCheckSettings = new HealthCheckSettings(pool.health_check_config);

                newHealthCheckSettings.Status         = enrollmentCheckBox.Checked ? HealthCheckStatus.Enabled : HealthCheckStatus.Disabled;
                newHealthCheckSettings.IntervalInDays = (int)(frequencyNumericBox.Value * 7);
                newHealthCheckSettings.DayOfWeek      = (DayOfWeek)dayOfWeekComboBox.SelectedValue;
                newHealthCheckSettings.TimeOfDay      = (int)timeOfDayComboBox.SelectedValue;
                newHealthCheckSettings.RetryInterval  = HealthCheckSettings.DEFAULT_RETRY_INTERVAL;

                new SaveHealthCheckSettingsAction(pool, newHealthCheckSettings, authenticationToken, diagnosticToken, textboxXSUserName.Text.Trim(), textboxXSPassword.Text, false).RunAsync();
                new TransferHealthCheckSettingsAction(pool, newHealthCheckSettings, textboxXSUserName.Text.Trim(), textboxXSPassword.Text, true).RunAsync();
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 13
0
        public void Should_load_non_default_Transport_values()
        {
            var hocon = ConfigurationFactory.ParseString(@"
                akka.healthcheck.readiness.transport = file
                akka.healthcheck.liveness.transport = tcp
            ");

            var settings = new HealthCheckSettings(hocon.WithFallback(HealthCheckSettings.DefaultConfig())
                                                   .GetConfig("akka.healthcheck"));

            settings.Misconfigured.Should().BeFalse();
            settings.LivenessProbeProvider.Should().Be(typeof(DefaultLivenessProvider));
            settings.ReadinessProbeProvider.Should().Be(typeof(DefaultReadinessProvider));
            settings.LivenessTransport.Should().Be(ProbeTransport.TcpSocket);
            settings.ReadinessTransport.Should().Be(ProbeTransport.File);
            settings.LivenessTransportSettings.Should().BeOfType <SocketTransportSettings>();
            settings.LivenessTransportSettings.As <SocketTransportSettings>().Port.Should().Be(11000);
            settings.ReadinessTransportSettings.Should().BeOfType <FileTransportSettings>();
            settings.ReadinessTransportSettings.As <FileTransportSettings>().FilePath.Should().Be("readiness.txt");
        }
Esempio n. 14
0
        private void okButton_Click(object sender, EventArgs e)
        {
            okButton.Enabled = false;
            if (enrollmentCheckBox.Checked && newAuthenticationRadioButton.Checked 
                && !m_ctrlError.PerformCheck(CheckUploadAuthentication))
            {
                okButton.Enabled = true;
                return;
            }

            if (ChangesMade())
            {
                var newHealthCheckSettings = new HealthCheckSettings(pool.health_check_config);

                newHealthCheckSettings.Status = enrollmentCheckBox.Checked ? HealthCheckStatus.Enabled : HealthCheckStatus.Disabled;
                newHealthCheckSettings.IntervalInDays = (int)(frequencyNumericBox.Value * 7);
                newHealthCheckSettings.DayOfWeek = (DayOfWeek)dayOfWeekComboBox.SelectedValue;
                newHealthCheckSettings.TimeOfDay = (int)timeOfDayComboBox.SelectedValue;
                newHealthCheckSettings. RetryInterval = HealthCheckSettings.DEFAULT_RETRY_INTERVAL;
                
                new SaveHealthCheckSettingsAction(pool, newHealthCheckSettings, authenticationToken, diagnosticToken, textboxXSUserName.Text.Trim(), textboxXSPassword.Text, false).RunAsync();
                new TransferHealthCheckSettingsAction(pool, newHealthCheckSettings, textboxXSUserName.Text.Trim(), textboxXSPassword.Text, true).RunAsync();
            }
            okButton.Enabled = true;
            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 15
0
        public void UpdateAnalysisResult(HealthCheckSettings healthCheckSettings)
        {
            issuesLabel.Text = healthCheckSettings.StatusDescription;
            ReportAnalysisLinkLabel.Visible = healthCheckSettings.HasAnalysisResult;

            if (healthCheckSettings.HasAnalysisResult)
                switch (healthCheckSettings.ReportAnalysisSeverity)
                {
                    case DiagnosticAlertSeverity.Error:
                        issuesLabel.ForeColor = Color.Red;
                        break;
                    case DiagnosticAlertSeverity.Warning:
                        issuesLabel.ForeColor = Color.OrangeRed;
                        break;
                    default:
                        issuesLabel.ForeColor = 
                            healthCheckSettings.ReportAnalysisIssuesDetected > 0 ? SystemColors.ControlText : Color.Green;
                        break;
                }
            else
            {
                issuesLabel.ForeColor = SystemColors.ControlText;
            }

            refreshLinkLabel.Visible = healthCheckSettings.HasUpload && !healthCheckSettings.HasAnalysisResult;

            if (healthCheckSettings.HasOldAnalysisResult)
            {
                previousUploadPanel.Visible = healthCheckSettings.HasOldAnalysisResult;

                DateTime previousUpload;
                if (HealthCheckSettings.TryParseStringToDateTime(healthCheckSettings.ReportAnalysisUploadTime,
                    out previousUpload))
                {
                    previousUploadDateLabel.Text = HelpersGUI.DateTimeToString(previousUpload.ToLocalTime(),
                        Messages.DATEFORMAT_DMY_HM, true);
                }
            }
            else
            {
                previousUploadPanel.Visible = false;
            }
        }
Esempio n. 16
0
 public void UpdateUploadRequestDescription(HealthCheckSettings healthCheckSettings)
 {
     {
         if (!healthCheckSettings.CanRequestNewUpload)
         {
                 uploadRequestLinkLabel.Text = string.Format(Messages.HEALTHCHECK_ON_DEMAND_REQUESTED_AT,
                                                             HelpersGUI.DateTimeToString(healthCheckSettings.NewUploadRequestTime.ToLocalTime(), 
                                                                 Messages.DATEFORMAT_HM, true));
             uploadRequestLinkLabel.LinkArea = new LinkArea(0, 0);
             return;
         }
         uploadRequestLinkLabel.Text = Messages.HEALTHCHECK_ON_DEMAND_REQUEST;
         uploadRequestLinkLabel.LinkArea = new LinkArea(0, uploadRequestLinkLabel.Text.Length);
     }
 }
Esempio n. 17
0
 public string GetScheduleDescription(HealthCheckSettings healthCheckSettings)
 {
     {
         var time = new DateTime(1900, 1, 1, healthCheckSettings.TimeOfDay, 0, 0);
         return healthCheckSettings.Status == HealthCheckStatus.Enabled
             ? string.Format(Messages.HEALTHCHECK_SCHEDULE_DESCRIPTION, healthCheckSettings.IntervalInWeeks,
                             healthCheckSettings.DayOfWeek, HelpersGUI.DateTimeToString(time, Messages.DATEFORMAT_HM, true))
             : string.Empty;
     }
 }
Esempio n. 18
0
 private Image GetSeverityImage(HealthCheckSettings healthCheckSettings)
 {
     if (healthCheckSettings.ReportAnalysisIssuesDetected == 0)
         return Properties.Resources._000_Tick_h32bit_16;
     switch (healthCheckSettings.ReportAnalysisSeverity)
     {
         case DiagnosticAlertSeverity.Error:
             return Properties.Resources._000_error_h32bit_16;
         case DiagnosticAlertSeverity.Warning:
             return Properties.Resources._000_Alert2_h32bit_16;
         default:
             return Properties.Resources._000_Info3_h32bit_16;
     }
 }
Esempio n. 19
0
        private void okButton_Click(object sender, EventArgs e)
        {
            okButton.Enabled = false;
            if (enrollmentCheckBox.Checked && newAuthenticationRadioButton.Checked
                && !m_ctrlError.PerformCheck(CheckUploadAuthentication))
            {
                okButton.Enabled = true;
                return;
            }

            if (ChangesMade())
            {
                var newHealthCheckSettings = new HealthCheckSettings(
                    enrollmentCheckBox.Checked ? HealthCheckStatus.Enabled : HealthCheckStatus.Disabled,
                    (int)(frequencyNumericBox.Value * 7),
                    (DayOfWeek)dayOfWeekComboBox.SelectedValue,
                    (int)timeOfDayComboBox.SelectedValue,
                    HealthCheckSettings.DefaultRetryInterval);

                new SaveHealthCheckSettingsAction(pool, newHealthCheckSettings, authenticationToken, textboxXSUserName.Text, textboxXSPassword.Text, false).RunAsync();
                new TransferHealthCheckSettingsAction(pool, newHealthCheckSettings, textboxXSUserName.Text, textboxXSPassword.Text, true).RunAsync();
            }
            okButton.Enabled = true;
            DialogResult = DialogResult.OK;
            Close();
        }