Skip to content

Latest commit

Β 

History

History
137 lines (100 loc) Β· 3.42 KB

File metadata and controls

137 lines (100 loc) Β· 3.42 KB

πŸš€ QUICK START - 2 Minutes to Running

Option 1: Visual Studio (Easiest)

  1. Open SqlHealthCheck.sln in Visual Studio
  2. Update connection string in SqlCheckDemo/Program.cs (line 13)
  3. Press F5 to run

Option 2: Command Line

# Navigate to the solution folder
cd SqlHealthCheck

# Build everything
dotnet build

# Run with default connection (localhost)
cd SqlCheckDemo
dotnet run

# Or run with your own connection string
dotnet run "Server=YOUR_SERVER;Database=master;Integrated Security=true;TrustServerCertificate=true;"

What You'll See

=== SQL Server Health Check Demo ===

Loaded 12 checks from sql-checks.json

Testing connection...
βœ… Connected successfully

Running checks...

[Backup]
------------------------------------------------------------
βœ… Full Backup Recency
βœ… Transaction Log Backup Recency

[Configuration]
------------------------------------------------------------
βœ… Auto Close Enabled
βœ… Auto Shrink Enabled
❌ TempDB File Count [Info]
   Check failed. Expected: 0, Got: 1. Add more TempDB data files...
βœ… Percentage Growth Settings

[Integrity]
------------------------------------------------------------
βœ… Database Corruption Detected

[Performance]
------------------------------------------------------------
❌ High Index Fragmentation [Warning]
   Check failed. Expected: 0, Got: 1. Consider rebuilding...
βœ… Missing Index Recommendations
βœ… Excessive VLF Count

[Security]
------------------------------------------------------------
βœ… SA Account Enabled
βœ… Weak Password Policies

=== Summary ===
Total Checks: 12
Passed: 10
Failed: 2

Now Customize It!

The first time you run, it creates sql-checks.json in the SqlCheckDemo folder.

Edit that file to:

  • ✏️ Change thresholds (e.g., backup age from 7 to 3 days)
  • βž• Add new checks (see USAGE.md for examples)
  • πŸ”‡ Disable checks you don't care about
  • πŸ“ Update SQL queries for your environment

No recompile needed - just edit the JSON and run again!

File Structure

SqlHealthCheck/
β”œβ”€β”€ SqlCheckLibrary/          # The reusable library
β”‚   β”œβ”€β”€ Models/              # SqlCheck and CheckResult classes
β”‚   └── Services/            # CheckRunner and CheckRepository
β”œβ”€β”€ SqlCheckDemo/            # Console app demo
β”‚   └── Program.cs           # Change connection string here
└── sql-checks.json          # Auto-generated on first run - EDIT THIS!

Integration Examples

In Your Own Code

using SqlCheckLibrary.Services;

var repo = new CheckRepository();
await repo.LoadChecksAsync();

var runner = new CheckRunner("your-connection-string");
var results = await runner.RunChecksAsync(repo.GetEnabledChecks());

// Do whatever you want with results!
foreach (var fail in results.Where(r => !r.Passed))
{
    Console.WriteLine($"Issue: {fail.CheckName}");
    SendAlert(fail); // Your alert logic
}

Multi-Server Monitoring

var servers = new[] { "sql01", "sql02", "sql03" };

foreach (var server in servers)
{
    var connStr = $"Server={server};Database=master;Integrated Security=true;TrustServerCertificate=true;";
    var runner = new CheckRunner(connStr);
    var results = await runner.RunChecksAsync(repo.GetEnabledChecks());
    
    SaveToDatabase(server, results); // Store in monitoring DB
}

Enjoy! πŸŽ‰

That's it. Super simple. All checks are in JSON, easy to modify, zero magic.

Go plant those trees! 🌳