Add Telegram bot integration for real-time alert notifications
- Implemented ITelegramNotificationService and TelegramNotificationService for sending alerts via Telegram. - Updated MonitoringSettings to include Telegram configuration options. - Enhanced AlertService to send alerts and resolutions through Telegram. - Added API endpoints for checking Telegram status and sending test alerts. - Updated README and TELEGRAM_SETUP.md with setup instructions and features. - Included example configuration in appsettings.telegram.example.json.
This commit is contained in:
@@ -20,6 +20,7 @@ namespace ResourceMonitorService
|
||||
private readonly IResourceMonitorService _resourceMonitorService;
|
||||
private readonly IGameDetectionService _gameDetectionService;
|
||||
private readonly IAlertService _alertService;
|
||||
private readonly ITelegramNotificationService _telegramService;
|
||||
private readonly ApiSettings _apiSettings;
|
||||
private readonly MonitoringSettings _monitoringSettings;
|
||||
|
||||
@@ -30,6 +31,7 @@ namespace ResourceMonitorService
|
||||
IResourceMonitorService resourceMonitorService,
|
||||
IGameDetectionService gameDetectionService,
|
||||
IAlertService alertService,
|
||||
ITelegramNotificationService telegramService,
|
||||
IOptions<ApiSettings> apiSettings,
|
||||
IOptions<MonitoringSettings> monitoringSettings)
|
||||
{
|
||||
@@ -39,6 +41,7 @@ namespace ResourceMonitorService
|
||||
_resourceMonitorService = resourceMonitorService;
|
||||
_gameDetectionService = gameDetectionService;
|
||||
_alertService = alertService;
|
||||
_telegramService = telegramService;
|
||||
_apiSettings = apiSettings.Value;
|
||||
_monitoringSettings = monitoringSettings.Value;
|
||||
}
|
||||
@@ -148,6 +151,37 @@ namespace ResourceMonitorService
|
||||
app.MapGet($"{basePath}/alerts/enabled", async () =>
|
||||
Results.Ok(new { Enabled = await _alertService.IsAlertingEnabledAsync() }));
|
||||
|
||||
// Telegram endpoints
|
||||
app.MapGet($"{basePath}/telegram/status", async () =>
|
||||
Results.Ok(new {
|
||||
Enabled = await _telegramService.IsEnabledAsync(),
|
||||
Connected = await _telegramService.TestConnectionAsync()
|
||||
}));
|
||||
|
||||
app.MapPost($"{basePath}/telegram/test", async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var testAlert = new Alert
|
||||
{
|
||||
Timestamp = DateTime.Now,
|
||||
Component = "Test",
|
||||
Level = "Warning",
|
||||
Message = "This is a test alert from Resource Monitor Service",
|
||||
CurrentValue = 100,
|
||||
ThresholdValue = 90,
|
||||
IsResolved = false
|
||||
};
|
||||
|
||||
await _telegramService.SendAlertAsync(testAlert);
|
||||
return Results.Ok(new { Message = "Test alert sent successfully" });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Results.Problem($"Failed to send test alert: {ex.Message}");
|
||||
}
|
||||
});
|
||||
|
||||
// Process management endpoints (enhanced)
|
||||
app.MapPost($"{basePath}/process/kill", async (HttpContext context) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user