Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resend Notification if Down X times consequently #1212

Merged
merged 26 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1ac904d
Introduce resend interval if down
OidaTiftla Jan 23, 2022
b69a8b8
Fix formatting
OidaTiftla Jan 23, 2022
65fc71e
Revert version change
OidaTiftla Jan 23, 2022
11e9eee
Change seconds to minutes
OidaTiftla Jan 23, 2022
f931e70
Add database patch
OidaTiftla Jan 24, 2022
8c4ab9d
Simplify
OidaTiftla Jan 24, 2022
30ce53f
Fix min value of resend interval
OidaTiftla Jan 24, 2022
f390a8c
Fix missing DB patch and use DATETIME as column format
OidaTiftla Jan 24, 2022
855b12f
Add text for resend disabled
OidaTiftla Jan 24, 2022
d446a57
Add german translation
OidaTiftla Jan 24, 2022
91366ff
Merge branch 'master' into introduce-resend-interval
OidaTiftla Mar 27, 2022
d8013f3
Update version after merging new master branch
OidaTiftla Mar 27, 2022
b7e2489
Merge branch 'master' into introduce-resend-interval
OidaTiftla Apr 21, 2022
60f8ab7
Use new logging mechanism
OidaTiftla Apr 21, 2022
19933bb
Improve backwards compatibility
OidaTiftla Apr 21, 2022
d6b591a
Make comment more readable
OidaTiftla Apr 21, 2022
052fde5
Fix casing of text label
OidaTiftla Apr 21, 2022
c7ec9a0
Add translation for text label
OidaTiftla Apr 21, 2022
7ed8ae9
Fix trailing space warning
OidaTiftla Apr 21, 2022
8e99cbf
Merge branch 'master' into introduce-resend-interval
OidaTiftla May 4, 2022
98ee9ca
Add variable for currentTime
OidaTiftla May 5, 2022
9305020
Merge database changes into single patch file
OidaTiftla May 5, 2022
869a040
Merge branch 'master' into introduce-resend-interval
OidaTiftla Jun 15, 2022
ac27e6e
Rename feature to: Resend Notification if Down X times consequently
OidaTiftla Jun 15, 2022
d0d1e0d
Merge remote-tracking branch 'origin/master' into introduce-resend-in…
louislam Aug 5, 2022
de6e1e7
Merge remote-tracking branch 'origin/master' into introduce-resend-in…
louislam Aug 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions db/patch-monitor-add-resend-interval.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
BEGIN TRANSACTION;

ALTER TABLE monitor
ADD resend_interval INTEGER default 0 not null;

ALTER TABLE heartbeat
ADD last_notified_time DATETIME default null;

COMMIT;
1 change: 1 addition & 0 deletions server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Database {
"patch-monitor-expiry-notification.sql": true,
"patch-status-page-footer-css.sql": true,
"patch-added-mqtt-monitor.sql": true,
"patch-monitor-add-resend-interval.sql": true,
};

/**
Expand Down
19 changes: 19 additions & 0 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Monitor extends BeanModel {
type: this.type,
interval: this.interval,
retryInterval: this.retryInterval,
resendInterval: this.resendInterval,
keyword: this.keyword,
expiryNotification: this.isEnabledExpiryNotification(),
ignoreTls: this.getIgnoreTls(),
Expand Down Expand Up @@ -193,6 +194,7 @@ class Monitor extends BeanModel {
bean.monitor_id = this.id;
bean.time = R.isoDateTime(dayjs.utc());
bean.status = DOWN;
bean.lastNotifiedTime = previousBeat?.lastNotifiedTime;

if (this.isUpsideDown()) {
bean.status = flipStatus(bean.status);
Expand Down Expand Up @@ -475,12 +477,29 @@ class Monitor extends BeanModel {
log.debug("monitor", `[${this.name}] sendNotification`);
await Monitor.sendNotification(isFirstBeat, this, bean);

// Set last notified time to now
bean.lastNotifiedTime = R.isoDateTime(dayjs.utc());

// Clear Status Page Cache
log.debug("monitor", `[${this.name}] apicache clear`);
apicache.clear();

} else {
bean.important = false;

if (bean.status === DOWN && this.resendInterval > 0) {
// divide by 1000 to convert from milliseconds to seconds and divide by 60 to convert from seconds to minutes
let timeSinceLastNotified = (dayjs.utc().valueOf() - (bean.lastNotifiedTime == null ? 0 : dayjs.utc(bean.lastNotifiedTime).valueOf())) / 1000 / 60;
if (timeSinceLastNotified >= this.resendInterval) {
// Send notification again, because we are still DOWN
const currentTime = R.isoDateTime(dayjs.utc());
log.debug("monitor", `[${this.name}] sendNotification again: lastNotifiedTime: ${bean.lastNotifiedTime} | current time: ${currentTime}`);
await Monitor.sendNotification(isFirstBeat, this, bean);

// Set last notified time to now
bean.lastNotifiedTime = currentTime;
}
}
}

if (bean.status === UP) {
Expand Down
2 changes: 2 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ try {
bean.basic_auth_pass = monitor.basic_auth_pass;
bean.interval = monitor.interval;
bean.retryInterval = monitor.retryInterval;
bean.resendInterval = monitor.resendInterval;
bean.hostname = monitor.hostname;
bean.maxretries = monitor.maxretries;
bean.port = monitor.port;
Expand Down Expand Up @@ -1251,6 +1252,7 @@ try {
basic_auth_pass: monitorListData[i].basic_auth_pass,
interval: monitorListData[i].interval,
retryInterval: retryInterval,
resendInterval: monitorListData[i].resendInterval || 0,
hostname: monitorListData[i].hostname,
maxretries: monitorListData[i].maxretries,
port: monitorListData[i].port,
Expand Down
3 changes: 3 additions & 0 deletions src/languages/de-DE.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ export default {
Pink: "Pink",
"Search...": "Suchen...",
"Heartbeat Retry Interval": "Überprüfungsintervall",
"Notification resend interval if down": "Benachrichtigung erneut versenden wenn Inaktiv",
retryCheckEverySecond: "Alle {0} Sekunden neu versuchen",
resendEveryMinute: "Erneut versenden alle {0} Minuten",
resendDisabled: "Erneut versenden deaktiviert",
"Import Backup": "Backup importieren",
"Export Backup": "Backup exportieren",
"Avg. Ping": "Durchschn. Ping",
Expand Down
3 changes: 3 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export default {
languageName: "English",
checkEverySecond: "Check every {0} seconds",
retryCheckEverySecond: "Retry every {0} seconds",
resendEveryMinute: "Resend every {0} minutes",
resendDisabled: "Resend disabled",
retriesDescription: "Maximum retries before the service is marked as down and a notification is sent",
ignoreTLSError: "Ignore TLS/SSL error for HTTPS websites",
upsideDownModeDescription: "Flip the status upside down. If the service is reachable, it is DOWN.",
Expand Down Expand Up @@ -72,6 +74,7 @@ export default {
"Heartbeat Interval": "Heartbeat Interval",
Retries: "Retries",
"Heartbeat Retry Interval": "Heartbeat Retry Interval",
"Notification resend interval if down": "Notification resend interval if down",
Advanced: "Advanced",
"Upside Down Mode": "Upside Down Mode",
"Max. Redirects": "Max. Redirects",
Expand Down
10 changes: 10 additions & 0 deletions src/pages/EditMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@
<input id="retry-interval" v-model="monitor.retryInterval" type="number" class="form-control" required min="20" step="1">
</div>

<div class="my-3">
<label for="resend-interval" class="form-label">
{{ $t("Notification resend interval if down") }}
<span v-if="monitor.resendInterval > 0">({{ $t("resendEveryMinute", [ monitor.resendInterval ]) }})</span>
<span v-else>({{ $t("resendDisabled") }})</span>
</label>
<input id="resend-interval" v-model="monitor.resendInterval" type="number" class="form-control" required min="0" step="1">
</div>

<h2 v-if="monitor.type !== 'push'" class="mt-5 mb-2">{{ $t("Advanced") }}</h2>

<div v-if="monitor.type === 'http' || monitor.type === 'keyword' " class="my-3 form-check">
Expand Down Expand Up @@ -514,6 +523,7 @@ export default {
method: "GET",
interval: 60,
retryInterval: this.interval,
resendInterval: 0,
maxretries: 0,
notificationIDList: {},
ignoreTls: false,
Expand Down