/vitality-net

Provides component status evaluation to integrate with monitoring services

Primary LanguageC#MIT LicenseMIT

Vitality.NET

Travis NuGet

vitality.net

Description

Vitality.NET provides component status evaluation to integrate with monitoring services.

Licensing

Released under the MIT License. See the LICENSE file for further details.

Installation

In the Package Manager Console execute

Install-Package Vitality

Or update *.csproj to include a dependency on

<ItemGroup>
  <PackageReference Include="Vitality" Version="0.1.0-*" />
</ItemGroup>

Usage

Sample authorization for details:

class Startup {
  public void ConfigureServices(IServiceCollection services) => 
    services.AddVitality(options => options.AuthorizeDetails = ctx => ctx.User.IsInRole("Admin"));
}

Sample integration with Sqlite Database:

class Startup {
  // ...
  
  public void ConfigureServices(IServiceCollection services) => 
    services.AddVitality(options => options.AddDbConnectionEvaluator("SqliteDatabase", () => new SqliteConnection(), "Data Source=:memory:;"));
    
  public void Configure(IApplicationBuilder app, IHostingEnvironment env) =>
    app.UseVitality().UseMvc();
}

Sample output for /vitality results in

{
  "sqliteDatabase": "Up"
}

Test results can be cached by using the appropriate overload:

services.AddVitality(options => options.AddDbConnectionEvaluator("SqliteDatabase", () => new SqliteConnection(), "Data Source=:memory:;"), TimeSpan.FromMinutes(5));

Test an Entity Framework DbContext (include Vitality.EntityFrameworkCore):

// Simply make sure the database connection is correct.
services.AddVitality(options => options.AddDbContextEvaluator<ApplicationDbContext>("ApplicationDbContext"));

// Check something on the context for verification.
services.AddVitality(options => options.AddDbContextEvaluator<ApplicationDbContext>("ApplicationDbContext", ctx => ctx.CriticalTableMustHaveRows.AnyAsync()));

For additional usage see Tests.