Skip to content

Commit f282422

Browse files
fabtrieIonys320CommanderStorm
authored
added option to force ipv4 or ipv6 for http(s) monitor type (#5880)
Co-authored-by: Ionys <9364594+Ionys320@users.noreply.github.com> Co-authored-by: Frank Elsinga <frank@elsinga.de>
1 parent 53e83e7 commit f282422

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports.up = function (knex) {
2+
return knex.schema
3+
.alterTable("monitor", function (table) {
4+
table.boolean("ip_family").defaultTo(null);
5+
});
6+
};
7+
8+
exports.down = function (knex) {
9+
return knex.schema
10+
.alterTable("monitor", function (table) {
11+
table.dropColumn("ip_family");
12+
});
13+
};

server/model/monitor.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class Monitor extends BeanModel {
160160
smtpSecurity: this.smtpSecurity,
161161
rabbitmqNodes: JSON.parse(this.rabbitmqNodes),
162162
conditions: JSON.parse(this.conditions),
163+
ipFamily: this.ipFamily,
163164

164165
// ping advanced options
165166
ping_numeric: this.isPingNumeric(),
@@ -426,10 +427,26 @@ class Monitor extends BeanModel {
426427
}
427428
}
428429

430+
let agentFamily = undefined;
431+
if (this.ipFamily === "ipv4") {
432+
agentFamily = 4;
433+
}
434+
if (this.ipFamily === "ipv6") {
435+
agentFamily = 6;
436+
}
437+
429438
const httpsAgentOptions = {
430439
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
431440
rejectUnauthorized: !this.getIgnoreTls(),
432441
secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT,
442+
autoSelectFamily: true,
443+
...(agentFamily ? { family: agentFamily } : {})
444+
};
445+
446+
const httpAgentOptions = {
447+
maxCachedSessions: 0,
448+
autoSelectFamily: true,
449+
...(agentFamily ? { family: agentFamily } : {})
433450
};
434451

435452
log.debug("monitor", `[${this.name}] Prepare Options for axios`);
@@ -491,6 +508,7 @@ class Monitor extends BeanModel {
491508
if (proxy && proxy.active) {
492509
const { httpAgent, httpsAgent } = Proxy.createAgents(proxy, {
493510
httpsAgentOptions: httpsAgentOptions,
511+
httpAgentOptions: httpAgentOptions,
494512
});
495513

496514
options.proxy = false;
@@ -499,6 +517,10 @@ class Monitor extends BeanModel {
499517
}
500518
}
501519

520+
if (!options.httpAgent) {
521+
options.httpAgent = new http.Agent(httpAgentOptions);
522+
}
523+
502524
if (!options.httpsAgent) {
503525
let jar = new CookieJar();
504526
let httpsCookieAgentOptions = {

server/server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ let needSetup = false;
792792
bean.url = monitor.url;
793793
bean.method = monitor.method;
794794
bean.body = monitor.body;
795+
bean.ipFamily = monitor.ipFamily;
795796
bean.headers = monitor.headers;
796797
bean.basic_auth_user = monitor.basic_auth_user;
797798
bean.basic_auth_pass = monitor.basic_auth_pass;

src/lang/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,9 @@
11161116
"Sender name": "Sender name",
11171117
"smsplanetNeedToApproveName": "Needs to be approved in the client panel",
11181118
"Disable URL in Notification": "Disable URL in Notification",
1119+
"Ip Family": "IP Family",
1120+
"ipFamilyDescriptionAutoSelect": "Uses the {happyEyeballs} for determining the IP family.",
1121+
"Happy Eyeballs algorithm": "Happy Eyeballs algorithm",
11191122
"Add Another Tag": "Add Another Tag",
11201123
"Staged Tags for Batch Add": "Staged Tags for Batch Add",
11211124
"Clear Form": "Clear Form",

src/pages/EditMonitor.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,20 @@
745745
{{ $t("acceptedStatusCodesDescription") }}
746746
</div>
747747
</div>
748+
749+
<div class="my-3">
750+
<label for="ipFamily" class="form-label">{{ $t("Ip Family") }}</label>
751+
<select id="ipFamily" v-model="monitor.ipFamily" class="form-select">
752+
<option :value="null">{{ $t("auto-select") }}</option>
753+
<option value="ipv4">IPv4</option>
754+
<option value="ipv6">IPv6</option>
755+
</select>
756+
<i18n-t v-if="monitor.ipFamily == null" keypath="ipFamilyDescriptionAutoSelect" tag="div" class="form-text">
757+
<template #happyEyeballs>
758+
<a href="https://en.wikipedia.org/wiki/Happy_Eyeballs" target="_blank">{{ $t("Happy Eyeballs algorithm") }}</a>
759+
</template>
760+
</i18n-t>
761+
</div>
748762
</template>
749763

750764
<!-- Parent Monitor -->
@@ -1129,6 +1143,7 @@ const monitorDefaults = {
11291143
parent: null,
11301144
url: "https://",
11311145
method: "GET",
1146+
ipFamily: null,
11321147
interval: 60,
11331148
retryInterval: 60,
11341149
resendInterval: 0,

0 commit comments

Comments
 (0)