Compare commits

...

7 commits

Author SHA1 Message Date
Peace
a6f4c99843
Merge 94af1d98d7 into 6899603eb7 2024-11-09 15:30:21 +00:00
Abhigyan Mohanta
6899603eb7
fix #5314 Email Address Friendly Name Error (#5318)
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Merge Conflict Labeler / Labeling (push) Has been cancelled
validate / json-yaml-validate (push) Has been cancelled
validate / validate (push) Has been cancelled
Auto Test / armv7-simple-test (18, ARMv7) (push) Has been cancelled
Auto Test / armv7-simple-test (20, ARMv7) (push) Has been cancelled
Auto Test / check-linters (push) Has been cancelled
Auto Test / e2e-test (push) Has been cancelled
Auto Test / auto-test (18, ARM64) (push) Has been cancelled
Auto Test / auto-test (18, macos-latest) (push) Has been cancelled
Auto Test / auto-test (18, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (18, windows-latest) (push) Has been cancelled
Auto Test / auto-test (20, ARM64) (push) Has been cancelled
Auto Test / auto-test (20, macos-latest) (push) Has been cancelled
Auto Test / auto-test (20, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (20, windows-latest) (push) Has been cancelled
2024-11-09 23:30:08 +08:00
Peace
94af1d98d7
feat: opt-out option to show path instead of name for notifications 2024-10-17 19:46:32 +02:00
Peace
16a41d53c1
Merge branch 'master' into feature/show-group-status 2024-10-14 23:08:57 +02:00
Peace
a3376069d0
fix: remove test logs 2024-10-12 23:39:35 +02:00
Peace
90b9173cfb
style: fix formatting 2024-10-12 23:27:34 +02:00
Peace
50d6ea36a4
feat: show child status on group error 2024-10-12 23:24:56 +02:00
6 changed files with 75 additions and 9 deletions

View file

@ -0,0 +1,12 @@
exports.up = function (knex) {
return knex.schema
.alterTable("notification", function (table) {
table.boolean("use_path_as_name").notNullable().defaultTo(true);
});
};
exports.down = function (knex) {
return knex.schema.alterTable("notification", function (table) {
table.dropColumn("use_path_as_name");
});
};

View file

@ -26,7 +26,15 @@ async function sendNotificationList(socket) {
for (let bean of list) {
let notificationObject = bean.export();
notificationObject.isDefault = (notificationObject.isDefault === 1);
notificationObject.usePathAsName = (notificationObject.usePathAsName === 1);
notificationObject.active = (notificationObject.active === 1);
const configObject = JSON.parse(notificationObject.config);
if ( !("usePathAsName" in configObject)) {
configObject.usePathAsName = notificationObject.usePathAsName;
notificationObject.config = JSON.stringify(configObject);
}
result.push(notificationObject);
}

View file

@ -385,7 +385,8 @@ class Monitor extends BeanModel {
if (children.length > 0) {
bean.status = UP;
bean.msg = "All children up and running";
bean.msg = "";
let errorChildNames = [];
for (const child of children) {
if (!child.active) {
// Ignore inactive childs
@ -402,10 +403,22 @@ class Monitor extends BeanModel {
} else if (bean.status === PENDING && lastBeat.status === DOWN) {
bean.status = lastBeat.status;
}
if (lastBeat && (lastBeat.status === PENDING || lastBeat.status === DOWN)) {
const childMonitor = await Monitor.getMonitor(lastBeat.monitor_id);
if (errorChildNames.length > 0) {
bean.msg += "\r\n";
}
bean.msg += "- " + childMonitor.name + ":\r\n" + lastBeat.msg.trim().replace(/^/gm, " ");
errorChildNames.push(childMonitor.name);
}
}
if (bean.status !== UP) {
bean.msg = "Child inaccessible";
if (bean.status === UP) {
bean.msg = "All children up and running";
} else if (bean.status === PENDING || bean.status === DOWN) {
bean.msg = "Some Children are having problems (" + errorChildNames.join(", ") + ")\r\n" + bean.msg;
}
} else {
// Set status pending if group is empty
@ -1326,8 +1339,10 @@ class Monitor extends BeanModel {
for (let notification of notificationList) {
try {
const heartbeatJSON = bean.toJSON();
const monitorData = [{ id: monitor.id,
active: monitor.active
const monitorData = [{
id: monitor.id,
name: monitor.name,
active: monitor.active,
}];
const preloadData = await Monitor.preparePreloadData(monitorData);
// Prevent if the msg is undefined, notifications such as Discord cannot send out.
@ -1606,6 +1621,20 @@ class Monitor extends BeanModel {
};
}
/**
* Gets Monitor with specific ID
* @param {number} monitorID ID of monitor to get
* @returns {Promise<LooseObject<any>>} Children
*/
static async getMonitor(monitorID) {
return await R.getRow(`
SELECT * FROM monitor
WHERE id = ?
`, [
monitorID,
]);
}
/**
* Gets Parent of the monitor
* @param {number} monitorID ID of monitor to get

View file

@ -178,6 +178,9 @@ class Notification {
* @throws Error with fail msg
*/
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
if (notification.usePathAsName && monitorJSON) {
monitorJSON["name"] = monitorJSON["pathName"];
}
if (this.providerList[notification.type]) {
return this.providerList[notification.type].send(notification, msg, monitorJSON, heartbeatJSON);
} else {
@ -213,6 +216,8 @@ class Notification {
bean.user_id = userID;
bean.config = JSON.stringify(notification);
bean.is_default = notification.isDefault || false;
bean.use_path_as_name = notification.usePathAsName;
await R.store(bean);
if (notification.applyExisting) {

View file

@ -41,6 +41,16 @@
<br>
<div class="form-check form-switch">
<input v-model="notification.usePathAsName" class="form-check-input" type="checkbox">
<label class="form-check-label">Use Monitor Path as Name</label>
</div>
<div class="form-text">
If your monitor is inside a group, the name will show the full path of the monitor. For example "Group A / Monitor 1".
</div>
<br>
<div class="form-check form-switch">
<input v-model="notification.applyExisting" class="form-check-input" type="checkbox">
<label class="form-check-label">{{ $t("Apply on all existing monitors") }}</label>
@ -95,6 +105,7 @@ export default {
/** @type { null | keyof NotificationFormList } */
type: null,
isDefault: false,
usePathAsName: false,
// Do not set default value here, please scroll to show()
}
};
@ -264,6 +275,7 @@ export default {
name: "",
type: "telegram",
isDefault: false,
usePathAsName: true,
};
}

View file

@ -5,20 +5,20 @@
</div>
<div class="mb-3">
<label for="sendgrid-from-email" class="form-label">{{ $t("From Email") }}</label>
<input id="sendgrid-from-email" v-model="$parent.notification.sendgridFromEmail" type="email" class="form-control" required>
<input id="sendgrid-from-email" v-model="$parent.notification.sendgridFromEmail" type="text" class="form-control" required>
</div>
<div class="mb-3">
<label for="sendgrid-to-email" class="form-label">{{ $t("To Email") }}</label>
<input id="sendgrid-to-email" v-model="$parent.notification.sendgridToEmail" type="email" class="form-control" required>
<input id="sendgrid-to-email" v-model="$parent.notification.sendgridToEmail" type="text" class="form-control" required>
</div>
<div class="mb-3">
<label for="sendgrid-cc-email" class="form-label">{{ $t("smtpCC") }}</label>
<input id="sendgrid-cc-email" v-model="$parent.notification.sendgridCcEmail" type="email" class="form-control">
<input id="sendgrid-cc-email" v-model="$parent.notification.sendgridCcEmail" type="text" class="form-control">
<div class="form-text">{{ $t("Separate multiple email addresses with commas") }}</div>
</div>
<div class="mb-3">
<label for="sendgrid-bcc-email" class="form-label">{{ $t("smtpBCC") }}</label>
<input id="sendgrid-bcc-email" v-model="$parent.notification.sendgridBccEmail" type="email" class="form-control">
<input id="sendgrid-bcc-email" v-model="$parent.notification.sendgridBccEmail" type="text" class="form-control">
<small class="form-text text-muted">{{ $t("Separate multiple email addresses with commas") }}</small>
</div>
<div class="mb-3">