private async Task ReportManagedCertificateStatus(ManagedCertificate managedCertificate)
        {
            if (CoreAppSettings.Current.EnableStatusReporting)
            {
                if (_pluginManager != null && _pluginManager.DashboardClient != null)
                {
                    var reportedCert = Newtonsoft.Json.JsonConvert.DeserializeObject <ManagedCertificate>(Newtonsoft.Json.JsonConvert.SerializeObject(managedCertificate));

                    // remove anything we don't want to report to the dashboard

                    reportedCert.RequestConfig.CustomCSR        = null;
                    reportedCert.RequestConfig.CustomPrivateKey = null;

                    var report = new Models.Shared.RenewalStatusReport
                    {
                        InstanceId          = CoreAppSettings.Current.InstanceId,
                        MachineName         = Environment.MachineName,
                        PrimaryContactEmail = (await GetAccountDetailsForManagedItem(managedCertificate))?.Email,
                        ManagedSite         = reportedCert,
                        AppVersion          = Util.GetAppVersion().ToString()
                    };
                    try
                    {
                        await _pluginManager.DashboardClient.ReportRenewalStatusAsync(report);
                    }
                    catch (Exception)
                    {
                        // failed to report status
                        LogMessage(managedCertificate.Id, "Failed to send renewal status report.",
                                   LogItemType.GeneralWarning);
                    }
                }
            }
        }
 private async Task ReportManagedCertificateStatus(ManagedCertificate managedCertificate)
 {
     if (CoreAppSettings.Current.EnableStatusReporting)
     {
         if (_pluginManager != null && _pluginManager.DashboardClient != null)
         {
             var report = new Models.Shared.RenewalStatusReport
             {
                 InstanceId          = CoreAppSettings.Current.InstanceId,
                 MachineName         = Environment.MachineName,
                 PrimaryContactEmail = (await GetAccountDetailsForManagedItem(managedCertificate))?.Email,
                 ManagedSite         = managedCertificate,
                 AppVersion          = Util.GetAppVersion().ToString()
             };
             try
             {
                 await _pluginManager.DashboardClient.ReportRenewalStatusAsync(report);
             }
             catch (Exception)
             {
                 // failed to report status
                 LogMessage(managedCertificate.Id, "Failed to send renewal status report.",
                            LogItemType.GeneralWarning);
             }
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Perform a subset of diagnostics, report failures if status reporting is enabled.
        /// </summary>
        /// <returns></returns>
        public async Task PerformScheduledDiagnostics()
        {
            try
            {
                _serviceLog.Information("Performing system diagnostics.");

                var diagnosticResults = await PerformServiceDiagnostics();

                if (diagnosticResults.Any(d => d.IsSuccess == false))
                {
                    var reportingEmail = (await GetAccountDetailsForManagedItem(null))?.Email;

                    foreach (var d in diagnosticResults.Where(di => di.IsSuccess == false && di.Result != null))
                    {
                        _serviceLog.Warning("Diagnostic Check Failed: " + d.Message);

                        // report diagnostic failures (if enabled)
                        if (reportingEmail != null && CoreAppSettings.Current.EnableStatusReporting && _pluginManager.DashboardClient != null)
                        {
                            try
                            {
                                await _pluginManager.DashboardClient.ReportUserActionRequiredAsync(new Models.Shared.ItemActionRequired
                                {
                                    InstanceId        = null,
                                    ManagedItemId     = null,
                                    ItemTitle         = "Diagnostic Check Failed",
                                    ActionType        = "diagnostic:" + d.Result.ToString(),
                                    InstanceTitle     = Environment.MachineName,
                                    Message           = d.Message,
                                    NotificationEmail = reportingEmail,
                                    AppVersion        = Util.GetAppVersion().ToString() + ";" + Environment.OSVersion.ToString()
                                });
                            }
                            catch (Exception)
                            {
                                _serviceLog.Warning("Failed to send diagnostic status report to API.");
                            }
                        }
                    }
                }
                else
                {
                    _serviceLog.Information("Diagnostics - OK.");
                }
            }
            catch (Exception ex)
            {
                _serviceLog.Error(ex, "Diagnostics Error");
            }
        }