Skip to content

Commit bad679e

Browse files
radulucutCommanderStormautofix-ci[bot]
authored
feat: add Globalping support (#6163)
Co-authored-by: Frank Elsinga <frank@elsinga.de> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 66c8bac commit bad679e

File tree

14 files changed

+2070
-80
lines changed

14 files changed

+2070
-80
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
exports.up = function (knex) {
2+
// Add new columns
3+
return knex.schema.alterTable("monitor", function (table) {
4+
table.string("subtype", 10).nullable();
5+
table.string("location", 255).nullable();
6+
table.string("protocol", 20).nullable();
7+
});
8+
};
9+
10+
exports.down = function (knex) {
11+
// Drop columns
12+
return knex.schema.alterTable("monitor", function (table) {
13+
table.dropColumn("subtype");
14+
table.dropColumn("location");
15+
table.dropColumn("protocol");
16+
});
17+
};

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"express-static-gzip": "~2.1.7",
9797
"feed": "^4.2.2",
9898
"form-data": "~4.0.0",
99+
"globalping": "^0.2.0",
99100
"gamedig": "^5.0.1",
100101
"html-escaper": "^3.0.3",
101102
"http-cookie-agent": "~5.0.4",

server/model/monitor.js

Lines changed: 10 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ const {
3333
checkStatusCode,
3434
getTotalClientInRoom,
3535
setting,
36-
setSetting,
3736
httpNtlm,
3837
radius,
3938
kafkaProducerAsync,
4039
getOidcTokenClientCredentials,
4140
rootCertificatesFingerprints,
4241
axiosAbortSignal,
4342
checkCertificateHostname,
43+
encodeBase64,
44+
checkCertExpiryNotifications,
4445
} = require("../util-server");
4546
const { R } = require("redbean-node");
4647
const { BeanModel } = require("redbean-node/dist/bean-model");
@@ -141,11 +142,14 @@ class Monitor extends BeanModel {
141142
method: this.method,
142143
hostname: this.hostname,
143144
port: this.port,
145+
location: this.location,
146+
protocol: this.protocol,
144147
maxretries: this.maxretries,
145148
weight: this.weight,
146149
active: preloadData.activeStatus.get(this.id),
147150
forceInactive: preloadData.forceInactive.get(this.id),
148151
type: this.type,
152+
subtype: this.subtype,
149153
timeout: this.timeout,
150154
interval: this.interval,
151155
retryInterval: this.retryInterval,
@@ -289,17 +293,6 @@ class Monitor extends BeanModel {
289293
};
290294
}
291295

292-
/**
293-
* Encode user and password to Base64 encoding
294-
* for HTTP "basic" auth, as per RFC-7617
295-
* @param {string|null} user - The username (nullable if not changed by a user)
296-
* @param {string|null} pass - The password (nullable if not changed by a user)
297-
* @returns {string} Encoded Base64 string
298-
*/
299-
encodeBase64(user, pass) {
300-
return Buffer.from(`${user || ""}:${pass || ""}`).toString("base64");
301-
}
302-
303296
/**
304297
* Is the TLS expiry notification enabled?
305298
* @returns {boolean} Enabled?
@@ -421,6 +414,8 @@ class Monitor extends BeanModel {
421414
let previousBeat = null;
422415
let retries = 0;
423416

417+
this.rootCertificates = rootCertificates;
418+
424419
try {
425420
this.prometheus = new Prometheus(this, await this.getTags());
426421
} catch (e) {
@@ -482,7 +477,7 @@ class Monitor extends BeanModel {
482477
let basicAuthHeader = {};
483478
if (this.auth_method === "basic") {
484479
basicAuthHeader = {
485-
Authorization: "Basic " + this.encodeBase64(this.basic_auth_user, this.basic_auth_pass),
480+
Authorization: "Basic " + encodeBase64(this.basic_auth_user, this.basic_auth_pass),
486481
};
487482
}
488483

@@ -922,7 +917,7 @@ class Monitor extends BeanModel {
922917
);
923918
}
924919

925-
if (!bean.ping) {
920+
if (bean.ping === undefined || bean.ping === null) {
926921
bean.ping = dayjs().valueOf() - startTime;
927922
}
928923
} else if (this.type === "kafka-producer") {
@@ -1572,64 +1567,6 @@ class Monitor extends BeanModel {
15721567
return notificationList;
15731568
}
15741569

1575-
/**
1576-
* checks certificate chain for expiring certificates
1577-
* @param {object} tlsInfoObject Information about certificate
1578-
* @returns {Promise<void>}
1579-
*/
1580-
async checkCertExpiryNotifications(tlsInfoObject) {
1581-
if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) {
1582-
const notificationList = await Monitor.getNotificationList(this);
1583-
1584-
if (!notificationList.length > 0) {
1585-
// fail fast. If no notification is set, all the following checks can be skipped.
1586-
log.debug("monitor", "No notification, no need to send cert notification");
1587-
return;
1588-
}
1589-
1590-
let notifyDays = await setting("tlsExpiryNotifyDays");
1591-
if (notifyDays == null || !Array.isArray(notifyDays)) {
1592-
// Reset Default
1593-
await setSetting("tlsExpiryNotifyDays", [7, 14, 21], "general");
1594-
notifyDays = [7, 14, 21];
1595-
}
1596-
1597-
if (Array.isArray(notifyDays)) {
1598-
for (const targetDays of notifyDays) {
1599-
let certInfo = tlsInfoObject.certInfo;
1600-
while (certInfo) {
1601-
let subjectCN = certInfo.subject["CN"];
1602-
if (rootCertificates.has(certInfo.fingerprint256)) {
1603-
log.debug(
1604-
"monitor",
1605-
`Known root cert: ${certInfo.certType} certificate "${subjectCN}" (${certInfo.daysRemaining} days valid) on ${targetDays} deadline.`
1606-
);
1607-
break;
1608-
} else if (certInfo.daysRemaining > targetDays) {
1609-
log.debug(
1610-
"monitor",
1611-
`No need to send cert notification for ${certInfo.certType} certificate "${subjectCN}" (${certInfo.daysRemaining} days valid) on ${targetDays} deadline.`
1612-
);
1613-
} else {
1614-
log.debug(
1615-
"monitor",
1616-
`call sendCertNotificationByTargetDays for ${targetDays} deadline on certificate ${subjectCN}.`
1617-
);
1618-
await this.sendCertNotificationByTargetDays(
1619-
subjectCN,
1620-
certInfo.certType,
1621-
certInfo.daysRemaining,
1622-
targetDays,
1623-
notificationList
1624-
);
1625-
}
1626-
certInfo = certInfo.issuerCertificate;
1627-
}
1628-
}
1629-
}
1630-
}
1631-
}
1632-
16331570
/**
16341571
* Send a certificate notification when certificate expires in less
16351572
* than target days
@@ -2164,7 +2101,7 @@ class Monitor extends BeanModel {
21642101

21652102
if (!this.getIgnoreTls() && this.isEnabledExpiryNotification()) {
21662103
log.debug("monitor", `[${this.name}] call checkCertExpiryNotifications`);
2167-
await this.checkCertExpiryNotifications(tlsInfo);
2104+
await checkCertExpiryNotifications(this, tlsInfo);
21682105
}
21692106
}
21702107
}

0 commit comments

Comments
 (0)