From e049a0c98efbfdec0de3e127787d56fdbd71bbba Mon Sep 17 00:00:00 2001 From: Computroniks Date: Sat, 29 Jan 2022 18:38:21 +0000 Subject: [PATCH] Added #1206. Friendly name is no longer required When adding or updating a monitor, if a friendly name is not specified, the URL or hostname will be used instead. Note: the hostname has priority over the URL so if both are set (possible in instances where monitor type has been changed), the friendly name will be set to the hostname. Signed-off-by: Computroniks --- src/pages/EditMonitor.vue | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 4b6a920c8..4deef120b 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -38,7 +38,7 @@
- +
@@ -317,6 +317,7 @@ export default { }, acceptedStatusCodeOptions: [], dnsresolvetypeOptions: [], + friendlyNameRequiredOptions: [], // Source: https://digitalfortress.tech/tips/top-15-commonly-used-regex/ ipRegexPattern: "((^\\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\\s*$)|(^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$))", @@ -413,12 +414,17 @@ export default { "TXT", ]; + let friendlyNameRequiredOptions = [ + "push", + ]; + for (let i = 100; i <= 999; i++) { acceptedStatusCodeOptions.push(i.toString()); } this.acceptedStatusCodeOptions = acceptedStatusCodeOptions; this.dnsresolvetypeOptions = dnsresolvetypeOptions; + this.friendlyNameRequiredOptions = friendlyNameRequiredOptions; }, methods: { init() { @@ -450,7 +456,10 @@ export default { this.$root.getSocket().emit("getMonitor", this.$route.params.id, (res) => { if (res.ok) { this.monitor = res.monitor; - + // Handling for when friendly name isn't set + if (this.monitor.name === this.monitor.url || this.monitor.name === this.monitor.hostname) { + this.monitor.name = ""; + } // Handling for monitors that are created before 1.7.0 if (this.monitor.retryInterval === 0) { this.monitor.retryInterval = this.monitor.interval; @@ -486,6 +495,16 @@ export default { async submit() { this.processing = true; + // Check if friendly name has been supplied. If not, use URL + // or hostname + if (this.monitor.name === "") { + if (this.monitor.hostname === null || this.monitor.hostname === "") { + this.monitor.name = this.monitor.url; + } else { + this.monitor.name = this.monitor.hostname; + } + } + if (!this.isInputValid()) { this.processing = false; return; @@ -532,6 +551,19 @@ export default { addedNotification(id) { this.monitor.notificationIDList[id] = true; }, + + /** + * Is the friendly name required for the selected option. + * Returns true if it is else null + * @returns {null|true} + */ + friendlyNameRequired() { + if (this.friendlyNameRequiredOptions.includes(this.monitor.type)) { + return true; + } else { + return null; + } + } }, };