Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Commit

Permalink
#26 allow slack option to enable/disable alerting on degrading checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alhardy committed Jul 5, 2018
1 parent 19d47ba commit e3a7f94
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ public static IHealthBuilder AddSlackAlerts(

return healthReportingBuilder.Builder;
}

public static IHealthBuilder AddSlackAlerts(
this IHealthReportingBuilder healthReportingBuilder,
SlackHealthAlertOptions options)
{
healthReportingBuilder.Using(new SlackIncomingWebHookHealthAlerter(options));

return healthReportingBuilder.Builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public class SlackHealthAlertOptions
public string Username { get; set; }

public string EmojiIcon { get; set; }

public bool AlertOnDegradedChecks { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ public async Task ReportAsync(HealthOptions options, HealthStatus status, Cancel
AddHealthAttachments(status, options.ApplicationName, HealthCheckStatus.Unhealthy, unhealthyCheck, slackMessage);
}

var degradedChecks = status.Results.Where(r => r.Check.Status == HealthCheckStatus.Degraded).ToList();

if (degradedChecks.Any())
if (_slackOptions.AlertOnDegradedChecks)
{
AddHealthAttachments(status, options.ApplicationName, HealthCheckStatus.Degraded, degradedChecks, slackMessage);
var degradedChecks = status.Results.Where(r => r.Check.Status == HealthCheckStatus.Degraded).ToList();

if (degradedChecks.Any())
{
AddHealthAttachments(status, options.ApplicationName, HealthCheckStatus.Degraded, degradedChecks, slackMessage);
}
}

if (slackMessage.Attachments.Any())
Expand Down

0 comments on commit e3a7f94

Please sign in to comment.