-
Notifications
You must be signed in to change notification settings - Fork 66
Integration
Integration is an external service configured to work with the Warden. For example, you might want to send an email, message on a Slack or Skype etc. - that's where the integrations may come in handy. Currently available integrations:
Integrations implement the following (marker) interface:
public interface IIntegration
{
}
Integrations are registered and resolved by the integrator:
public interface IIntegrator
{
void Register<T>(T integration) where T : class, IIntegration;
T Resolve<T>() where T : class, IIntegration;
}
You may think of it as a simple IoC container or so. If you would like to provide a custom IIntegrator make use of the available SetIntegratorProvider() while configuring the Warden.
var wardenConfiguration = WardenConfiguration
.Create()
.SetIntegratorProvider(() => new CustomIntegrator())
//Configure watchers, hooks etc.
To register an integration, make a new instance of it and add it to the Warden:
var wardenConfiguration = WardenConfiguration
.Create()
.AddIntegration(new CustomIntegration())
//Configure watchers, hooks etc.
In order to resolve an integration, make use of the overloaded method while configuring the hooks:
var wardenConfiguration = WardenConfiguration
.Create()
.AddIntegration(new CustomIntegration())
.SetGlobalWatcherHooks((hooks, integrations) =>
{
hooks.OnStart(check => GlobalHookOnStart(check))
.OnFailure(result => integrations.Resolve<CustomIntegration>().DoSomething())
})
//Configure watchers, hooks etc..
If you are using the built-in integrations such as the SendGrid you can register and resolve such integration via provided extension methods, like this:
var wardenConfiguration = WardenConfiguration
.Create()
.IntegrateWithSendGrid("api-key", "noreply@system.com", cfg =>
{
cfg.WithDefaultSubject("Monitoring status")
.WithDefaultReceivers("admin@system.com");
})
.SetGlobalWatcherHooks((hooks, integrations) =>
{
hooks.OnStart(check => GlobalHookOnStart(check))
.OnFailure(result => integrations.SendGrid().SendEmailAsync("Monitoring errors have occured."))
})
//Configure watchers, hooks etc..
In order to provide a custom integration implement the mentioned marker interface IIntegration and add a new instance of your integration to the Warden by using the AddIntegration(). You can also create an extension method for both registering and resolving the custom integration, which will fit nicely to the already provided fluent API.