Skip to content

Latest commit

Β 

History

History
317 lines (259 loc) Β· 8.79 KB

File metadata and controls

317 lines (259 loc) Β· 8.79 KB

πŸš€ Version 1.9 - Enterprise Multi-Server + MVVM Architecture

βœ… What's Been Implemented

1. Multi-Server Support

Run health checks across multiple SQL servers simultaneously using parallel processing.

Features:

  • Issue queries to all servers concurrently with Task.WhenAll()
  • Results grouped by check showing passed/failed per server
  • Expandable per-server view
  • Connection throttling prevents overload

Usage:

var servers = new List<ServerConnection>
{
    new ServerConnection { ServerName = "Server1", ConnectionString = conn1 },
    new ServerConnection { ServerName = "Server2", ConnectionString = conn2 },
    new ServerConnection { ServerName = "Server3", ConnectionString = conn3 }
};

var results = await CheckRunner.RunChecksOnMultipleServersAsync(
    servers,
    checks,
    progress: new Progress<(string server, int current, int total)>(p =>
    {
        Console.WriteLine($"[{p.server}] {p.current}/{p.total}");
    }));

// Results grouped by check
foreach (var checkGroup in results.GroupedByCheck)
{
    Console.WriteLine($"{checkGroup.CheckName}: {checkGroup.PassedCount} passed, {checkGroup.FailedCount} failed");
    
    foreach (var serverResult in checkGroup.ServerResults)
    {
        Console.WriteLine($"  - {serverResult.ServerName}: {(serverResult.Passed ? "PASS" : "FAIL")}");
    }
}

2. Enterprise Connection Dialog

Secure connection management with Windows and SQL Server authentication options.

Features:

  • Windows Authentication (Recommended) - Uses AD credentials
  • SQL Server Authentication - For non-AD environments
  • Encryption settings (Encrypt, TrustServerCertificate)
  • Connection test before use
  • Security validation with warnings

Security Best Practices:

  • Windows Auth preferred (Integrated Security=SSPI)
  • Password not stored - re-entered each session
  • Security warnings for insecure settings
  • Connection string sanitization for logging

3. Connection String Builder Service

Enterprise patterns for building secure connection strings.

Usage:

// Windows Authentication (recommended)
var connStr = ConnectionStringBuilder.BuildWithIntegratedSecurity(
    server: "SERVER01",
    database: "master",
    encrypt: true,
    trustServerCertificate: false);

// SQL Server Authentication
var connStr = ConnectionStringBuilder.BuildWithSqlAuth(
    server: "SERVER01",
    username: "admin",
    password: GetPasswordFromSecureStorage(), // Never hardcode!
    database: "master");

// Parse existing connection string
var info = ConnectionStringBuilder.ParseConnectionString(existingConnStr);
Console.WriteLine($"Server: {info.Server}");
Console.WriteLine($"Uses Windows Auth: {info.UseIntegratedSecurity}");

// Validate security
var validation = ConnectionStringBuilder.ValidateSecurity(connStr);
if (!validation.IsSecure)
{
    foreach (var warning in validation.Warnings)
    {
        Console.WriteLine($"⚠️ {warning}");
    }
}

// Safe for logging (masks password)
var sanitized = ConnectionStringBuilder.GetSanitizedForLogging(connStr);

4. Script Manager

Configure and manage embedded diagnostic scripts.

Features:

  • Scan scripts folder to auto-detect SQL files
  • Configure execution parameters
  • Set execution order
  • Enable/disable scripts
  • Configure timeout and CSV export
  • Default parameters for sp_Blitz, sp_BlitzIndex, sp_BlitzFirst

Setup:

  1. Create scripts folder in app directory
  2. Copy diagnostic scripts (sp_Blitz.sql, sp_triage.sql)
  3. Click "Scan Scripts Folder"
  4. Configure parameters
  5. Save configuration

5. Complete Health Check Runner

Execute all configured scripts and export results to CSV.

Features:

  • Runs all enabled scripts in order
  • Exports each result set to CSV
  • Server name and timestamp in filenames
  • Error handling per script
  • Progress reporting

Output Files:

output/
β”œβ”€β”€ SERVER01_sp_Blitz_20260123-143022.csv
β”œβ”€β”€ SERVER01_sp_BlitzIndex_20260123-143045.csv
β”œβ”€β”€ SERVER01_sp_triage_20260123-143112.csv
└── (any errors logged to _ERROR_ files)

6. Bulk Edit Dialog

Edit multiple checks simultaneously.

Features:

  • Select multiple checks (Ctrl+Click)
  • Change Category, Severity, Priority
  • Change Enabled state
  • Change Execution Type
  • Apply to all selected

7. Memory Monitoring

Background monitoring for memory pressure.

Features:

  • Timer checks every 5 minutes
  • Triggers cleanup on high pressure
  • Server GC configuration
  • Proper disposal on window close

8. Progress Window

Visual progress for long operations.

Features:

  • Status text
  • Progress bar
  • Percentage display
  • Thread-safe updates

πŸ”§ Enterprise Architecture Patterns

MVVM Support

Added CommunityToolkit.Mvvm for enterprise patterns:

<!-- In .csproj -->
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" />

Can now use:

  • ObservableProperty attributes
  • RelayCommand/AsyncRelayCommand
  • ObservableObject base class
  • Messenger for loose coupling

Parallel Processing

Multi-server operations use Task.WhenAll for maximum throughput:

var serverTasks = servers.Select(async server =>
{
    using var runner = new CheckRunner(server.ConnectionString);
    return await runner.RunChecksAsync(checks);
});

var allResults = await Task.WhenAll(serverTasks);

Resource Management

Enterprise disposal patterns:

// All runners implement IDisposable
using var runner = new CheckRunner(connectionString);
var results = await runner.RunChecksAsync(checks);
// Automatically disposed

// Background cleanup
ResourceManager.SuggestCleanup();
ResourceManager.AggressiveCleanup();

// Memory monitoring
var pressure = ResourceManager.CheckMemoryPressure();
if (pressure == MemoryPressure.High)
{
    ResourceManager.AggressiveCleanup();
}

Server GC Configuration

Added to project files:

<PropertyGroup>
    <ServerGarbageCollection>true</ServerGarbageCollection>
    <ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
</PropertyGroup>

πŸ“ New Files

SqlCheckLibrary/Services/

  • ConnectionStringBuilder.cs - Enterprise connection patterns
  • CompleteHealthCheckRunner.cs - Script execution + CSV export

SqlMonitorUI/

  • ConnectionDialog.xaml/.cs - Connection configuration
  • BulkEditDialog.xaml/.cs - Bulk edit checks
  • ScriptManagerWindow.xaml/.cs - Script management
  • ProgressWindow.xaml/.cs - Progress display

πŸ”’ Security Checklist

βœ… Windows Authentication preferred - Uses AD credentials
βœ… Passwords not stored - Re-entered each session
βœ… Connection string sanitization - Safe for logging
βœ… Security validation - Warns about insecure settings
βœ… Encryption support - Encrypt=True recommended
βœ… Certificate validation - TrustServerCertificate guidance
βœ… Connection throttling - Prevents connection exhaustion

πŸ“Š Multi-Server Results Model

MultiServerCheckResults
β”œβ”€β”€ ServerResults[]
β”‚   β”œβ”€β”€ ServerName
β”‚   β”œβ”€β”€ ConnectionSuccessful
β”‚   β”œβ”€β”€ Results[]
β”‚   β”‚   β”œβ”€β”€ CheckId
β”‚   β”‚   β”œβ”€β”€ Passed
β”‚   β”‚   └── Message
β”‚   └── ErrorMessage (if failed)
└── GroupedByCheck[]
    β”œβ”€β”€ CheckId
    β”œβ”€β”€ CheckName
    β”œβ”€β”€ PassedCount
    β”œβ”€β”€ FailedCount
    └── ServerResults[]
        β”œβ”€β”€ ServerName
        β”œβ”€β”€ Passed
        └── Message

🎯 Usage Workflow

Single Server

  1. Click "Connect" button
  2. Select Windows or SQL Auth
  3. Enter server name
  4. Test connection
  5. Click "Run Checks"

Multiple Servers (Future UI)

  1. Add servers to list
  2. Configure auth per server
  3. Click "Run All"
  4. View grouped results
  5. Expand per-server details

Complete Health Check

  1. Configure scripts in Script Manager
  2. Click "Full Check" button
  3. Confirm execution
  4. Wait for progress
  5. Review CSV files

Bulk Edit

  1. Open Check Manager
  2. Select multiple checks
  3. Click "Bulk Edit"
  4. Select properties to change
  5. Apply and save

πŸ’‘ Tips

  1. Use Windows Auth - Most secure, uses AD credentials
  2. Test connections - Always test before running checks
  3. Review security warnings - Don't ignore encryption warnings
  4. Monitor memory - Check stats in production
  5. Use batch operations - Bulk edit saves time
  6. Export to CSV - Full Check creates detailed reports

Summary

βœ… Multi-server support - Parallel execution across servers
βœ… Enterprise security - Windows Auth, secure connections
βœ… Connection builder - Enterprise patterns for connection strings
βœ… Script manager - Configure diagnostic scripts
βœ… Bulk editing - Edit multiple checks at once
βœ… Memory monitoring - Background pressure checks
βœ… MVVM toolkit - Enterprise architecture support
βœ… Progress tracking - Visual feedback for operations

All code is implemented and ready for enterprise deployment!