Skip to content

Conversation

@SmartDever02
Copy link

Implement notification system that works even when database is unavailable.

Problem:

  • When Uptime Kuma's database (external MariaDB/SQLite) becomes unavailable, UK stops functioning and cannot send notifications about its own failure.
  • Users are not alerted when UK itself is having database connectivity issues.

Solution:

  • Added notification cache system that stores all active notification configs in memory when database is available
  • Implemented database error detection in both monitor.js and server.js error handlers to catch EHOSTUNREACH, ECONNREFUSED, and other DB errors
  • Added sendDatabaseDownNotification() method that uses cached notifications to send alerts when database connection fails
  • Cache automatically refreshes periodically (every 30 minutes) and when notifications are added/updated/deleted
  • Prevents duplicate notifications for the same database down event

Changes:

  • server/notification.js: Added cache system and database down notification
  • server/server.js: Enhanced error handler to detect DB errors and trigger notifications, refresh cache on startup
  • server/model/monitor.js: Added DB error detection in safeBeat error handler
  • server/jobs.js: Added periodic cache refresh job (every 30 minutes)
  • test/backend-test/test-database-down-notification.js: Comprehensive test suite covering cache, notifications, error handling

This ensures users are always notified when UK itself is having database connectivity issues, even if the database is completely unavailable.

Closes #6498

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=102175066

SmartDever02 and others added 2 commits January 6, 2026 03:00
Implement notification system that works even when database is unavailable.

Problem:
- When Uptime Kuma's database (external MariaDB/SQLite) becomes unavailable,
  UK stops functioning and cannot send notifications about its own failure.
- Users are not alerted when UK itself is having database connectivity issues.

Solution:
- Added notification cache system that stores all active notification configs
  in memory when database is available
- Implemented database error detection in both monitor.js and server.js
  error handlers to catch EHOSTUNREACH, ECONNREFUSED, and other DB errors
- Added sendDatabaseDownNotification() method that uses cached notifications
  to send alerts when database connection fails
- Cache automatically refreshes periodically (every 30 minutes) and when
  notifications are added/updated/deleted
- Prevents duplicate notifications for the same database down event

Changes:
- server/notification.js: Added cache system and database down notification
- server/server.js: Enhanced error handler to detect DB errors and trigger
  notifications, refresh cache on startup
- server/model/monitor.js: Added DB error detection in safeBeat error handler
- server/jobs.js: Added periodic cache refresh job (every 30 minutes)
- test/backend-test/test-database-down-notification.js: Comprehensive test
  suite covering cache, notifications, error handling

This ensures users are always notified when UK itself is having database
connectivity issues, even if the database is completely unavailable.
@SmartDever02
Copy link
Author

hi @CommanderStorm , could you review my pr?

@SmartDever02
Copy link
Author

all of the tests passed :) @CommanderStorm

Copy link
Collaborator

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Architecturally, we need to move this to its own file.

Adding new, larger features to the notification.js or monitor.js are not the best of ideas. (the files for this are alreay over 1k lines, which is way too large).

The code is also a bit too spaced out and duplicated and I don't think it is currently quite to the point that it is production ready in terms of "this cannot cause very alarming false positives".
Could you give it another iteration?

@CommanderStorm CommanderStorm added the pr:please address review comments this PR needs a bit more work to be mergable label Jan 6, 2026
Copy link
Owner

@louislam louislam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to think more.

  • Will it send to all notification providers? If yes, I don't think it should.
  • Need GUI to config which notification providers want to receive this.
  • Turn off by default
  • Will it send only one notification during a period, or it keep sending notifications as long as it hit the errors? It may be a problem that it can strike the notification providers (rate limit or sms pricing etc.)

autofix-ci bot and others added 8 commits January 9, 2026 05:11
- Add send_database_down column to notification table (default: false)
- Only notifications with send_database_down enabled receive database down alerts
- Add GUI checkbox in NotificationDialog to configure opt-in setting
- Implement 24-hour cooldown period to prevent notification spam
- Add database error detector to avoid false positives
- Update tests to verify opt-in behavior

Addresses owner feedback:
- Not sending to all providers (opt-in only)
- GUI configuration available
- Turned off by default
- Cooldown prevents spam/rate limiting issues
- Check for missing is_default column and add it if needed
- Handle outdated template database in CI/CD environment
- Ensures test works even if template DB is missing columns
@SmartDever02 SmartDever02 marked this pull request as ready for review January 15, 2026 03:25
@SmartDever02 SmartDever02 requested a review from louislam January 15, 2026 03:25
@github-actions github-actions bot added pr:needs review this PR needs a review by maintainers or other community members and removed pr:please address review comments this PR needs a bit more work to be mergable labels Jan 15, 2026
@CommanderStorm
Copy link
Collaborator

Honestly, I don't think this code or the way it is integrated would be maintainable long term.

I am tempted to just close this feature and its feature request since this really would need some architectural changes to work well.

1 similar comment
@CommanderStorm
Copy link
Collaborator

Honestly, I don't think this code or the way it is integrated would be maintainable long term.

I am tempted to just close this feature and its feature request since this really would need some architectural changes to work well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:needs review this PR needs a review by maintainers or other community members

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to send notifications when UK database is down

3 participants