- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 6.9k
 
feat: add Globalping support #6163
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
base: master
Are you sure you want to change the base?
Changes from 16 commits
235491b
              8edd260
              2eabb3b
              f97d2fd
              eb68637
              88c595a
              082235f
              64628d5
              7e75ad8
              d59422f
              361ba48
              d4efaa3
              79989dc
              a5c5449
              cf916a6
              db4d9d8
              d956708
              c7ba733
              afc3d59
              f9f54bb
              9650498
              a377cb6
              4a5fe2a
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| exports.up = function (knex) { | ||
| // Add new columns | ||
| return knex.schema.alterTable("monitor", function (table) { | ||
| table.string("subtype", 255).nullable(); | ||
| table.string("location", 255).nullable(); | ||
| table.string("protocol", 255).nullable(); | ||
| }); | ||
| }; | ||
| 
     | 
||
| exports.down = function (knex) { | ||
| // Drop columns | ||
| return knex.schema.alterTable("monitor", function (table) { | ||
| table.dropColumn("subtype"); | ||
| table.dropColumn("location"); | ||
| table.dropColumn("protocol"); | ||
| }); | ||
| }; | ||
| 
                       There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to be resync with master  | 
            
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 
                       There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "globalping" npm has deprecated @hey-api dependencies package  | 
            
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -8,8 +8,8 @@ const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, MAX_INTERVAL_SECOND, MI | |
| PING_COUNT_MIN, PING_COUNT_MAX, PING_COUNT_DEFAULT, | ||
| PING_PER_REQUEST_TIMEOUT_MIN, PING_PER_REQUEST_TIMEOUT_MAX, PING_PER_REQUEST_TIMEOUT_DEFAULT | ||
| } = require("../../src/util"); | ||
| const { tcping, ping, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, setSetting, httpNtlm, radius, grpcQuery, | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok old setSetting usage  | 
||
| redisPingAsync, kafkaProducerAsync, getOidcTokenClientCredentials, rootCertificatesFingerprints, axiosAbortSignal | ||
| const { tcping, ping, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, httpNtlm, radius, grpcQuery, | ||
| redisPingAsync, kafkaProducerAsync, getOidcTokenClientCredentials, rootCertificatesFingerprints, axiosAbortSignal, encodeBase64, checkCertExpiryNotifications | ||
| } = require("../util-server"); | ||
| const { R } = require("redbean-node"); | ||
| const { BeanModel } = require("redbean-node/dist/bean-model"); | ||
| 
          
            
          
           | 
    @@ -103,11 +103,14 @@ class Monitor extends BeanModel { | |
| method: this.method, | ||
| hostname: this.hostname, | ||
| port: this.port, | ||
| location: this.location, | ||
| protocol: this.protocol, | ||
| maxretries: this.maxretries, | ||
| weight: this.weight, | ||
| active: preloadData.activeStatus.get(this.id), | ||
| forceInactive: preloadData.forceInactive.get(this.id), | ||
| type: this.type, | ||
| subtype: this.subtype, | ||
| timeout: this.timeout, | ||
| interval: this.interval, | ||
| retryInterval: this.retryInterval, | ||
| 
          
            
          
           | 
    @@ -241,17 +244,6 @@ class Monitor extends BeanModel { | |
| }; | ||
| } | ||
| 
     | 
||
| /** | ||
| * Encode user and password to Base64 encoding | ||
| * for HTTP "basic" auth, as per RFC-7617 | ||
| * @param {string|null} user - The username (nullable if not changed by a user) | ||
| * @param {string|null} pass - The password (nullable if not changed by a user) | ||
| * @returns {string} Encoded Base64 string | ||
| */ | ||
| encodeBase64(user, pass) { | ||
| return Buffer.from(`${user || ""}:${pass || ""}`).toString("base64"); | ||
| } | ||
| 
     | 
||
| /** | ||
| * Is the TLS expiry notification enabled? | ||
| * @returns {boolean} Enabled? | ||
| 
          
            
          
           | 
    @@ -349,6 +341,7 @@ class Monitor extends BeanModel { | |
| let previousBeat = null; | ||
| let retries = 0; | ||
| 
     | 
||
| this.rootCertificates = rootCertificates; | ||
| this.prometheus = new Prometheus(this); | ||
| 
     | 
||
| const beat = async () => { | ||
| 
          
            
          
           | 
    @@ -409,7 +402,7 @@ class Monitor extends BeanModel { | |
| let basicAuthHeader = {}; | ||
| if (this.auth_method === "basic") { | ||
| basicAuthHeader = { | ||
| "Authorization": "Basic " + this.encodeBase64(this.basic_auth_user, this.basic_auth_pass), | ||
| "Authorization": "Basic " + encodeBase64(this.basic_auth_user, this.basic_auth_pass), | ||
| }; | ||
| } | ||
| 
     | 
||
| 
          
            
          
           | 
    @@ -861,7 +854,7 @@ class Monitor extends BeanModel { | |
| let startTime = dayjs().valueOf(); | ||
| const monitorType = UptimeKumaServer.monitorTypeList[this.type]; | ||
| await monitorType.check(this, bean, UptimeKumaServer.getInstance()); | ||
| if (!bean.ping) { | ||
| if (bean.ping === undefined || bean.ping === null) { | ||
| bean.ping = dayjs().valueOf() - startTime; | ||
| } | ||
| 
     | 
||
| 
          
            
          
           | 
    @@ -1371,49 +1364,6 @@ class Monitor extends BeanModel { | |
| return notificationList; | ||
| } | ||
| 
     | 
||
| /** | ||
| * checks certificate chain for expiring certificates | ||
| * @param {object} tlsInfoObject Information about certificate | ||
| * @returns {void} | ||
| */ | ||
| async checkCertExpiryNotifications(tlsInfoObject) { | ||
| if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) { | ||
| const notificationList = await Monitor.getNotificationList(this); | ||
| 
     | 
||
| if (! notificationList.length > 0) { | ||
| // fail fast. If no notification is set, all the following checks can be skipped. | ||
| log.debug("monitor", "No notification, no need to send cert notification"); | ||
| return; | ||
| } | ||
| 
     | 
||
| let notifyDays = await setting("tlsExpiryNotifyDays"); | ||
| if (notifyDays == null || !Array.isArray(notifyDays)) { | ||
| // Reset Default | ||
| await setSetting("tlsExpiryNotifyDays", [ 7, 14, 21 ], "general"); | ||
| notifyDays = [ 7, 14, 21 ]; | ||
| } | ||
| 
     | 
||
| if (Array.isArray(notifyDays)) { | ||
| for (const targetDays of notifyDays) { | ||
| let certInfo = tlsInfoObject.certInfo; | ||
| while (certInfo) { | ||
| let subjectCN = certInfo.subject["CN"]; | ||
| if (rootCertificates.has(certInfo.fingerprint256)) { | ||
| log.debug("monitor", `Known root cert: ${certInfo.certType} certificate "${subjectCN}" (${certInfo.daysRemaining} days valid) on ${targetDays} deadline.`); | ||
| break; | ||
| } else if (certInfo.daysRemaining > targetDays) { | ||
| log.debug("monitor", `No need to send cert notification for ${certInfo.certType} certificate "${subjectCN}" (${certInfo.daysRemaining} days valid) on ${targetDays} deadline.`); | ||
| } else { | ||
| log.debug("monitor", `call sendCertNotificationByTargetDays for ${targetDays} deadline on certificate ${subjectCN}.`); | ||
| await this.sendCertNotificationByTargetDays(subjectCN, certInfo.certType, certInfo.daysRemaining, targetDays, notificationList); | ||
| } | ||
| certInfo = certInfo.issuerCertificate; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| 
     | 
||
| /** | ||
| * Send a certificate notification when certificate expires in less | ||
| * than target days | ||
| 
          
            
          
           | 
    @@ -1769,7 +1719,7 @@ class Monitor extends BeanModel { | |
| 
     | 
||
| if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) { | ||
| log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`); | ||
| await this.checkCertExpiryNotifications(tlsInfo); | ||
| await checkCertExpiryNotifications(this, tlsInfo); | ||
| } | ||
| } | ||
| } | ||
| 
          
            
          
           | 
    ||
Uh oh!
There was an error while loading. Please reload this page.