added option to force ipv4 or ipv6 for http(s) monitor type

This commit is contained in:
Fabian Triebsch 2025-06-04 13:25:43 +02:00 committed by Fabian Triebsch
parent f27811c394
commit 91f34dde79
4 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,13 @@
exports.up = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {
table.boolean("force_ip").defaultTo(null);
});
};
exports.down = function (knex) {
return knex.schema
.alterTable("monitor", function (table) {
table.dropColumn("force_ip");
});
};

View file

@ -160,6 +160,7 @@ class Monitor extends BeanModel {
smtpSecurity: this.smtpSecurity, smtpSecurity: this.smtpSecurity,
rabbitmqNodes: JSON.parse(this.rabbitmqNodes), rabbitmqNodes: JSON.parse(this.rabbitmqNodes),
conditions: JSON.parse(this.conditions), conditions: JSON.parse(this.conditions),
forceIp: this.forceIp,
// ping advanced options // ping advanced options
ping_numeric: this.isPingNumeric(), ping_numeric: this.isPingNumeric(),
@ -426,10 +427,18 @@ class Monitor extends BeanModel {
} }
} }
const agentFamily = this.forceIp ? (this.forceIp === "ipv4" ? 4 : 6) : undefined;
const httpsAgentOptions = { const httpsAgentOptions = {
maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940) maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
rejectUnauthorized: !this.getIgnoreTls(), rejectUnauthorized: !this.getIgnoreTls(),
secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT, secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT,
...(agentFamily ? { family: agentFamily } : {})
};
const httpAgentOptions = {
maxCachedSessions: 0,
...(agentFamily ? { family: agentFamily } : {})
}; };
log.debug("monitor", `[${this.name}] Prepare Options for axios`); log.debug("monitor", `[${this.name}] Prepare Options for axios`);
@ -491,6 +500,7 @@ class Monitor extends BeanModel {
if (proxy && proxy.active) { if (proxy && proxy.active) {
const { httpAgent, httpsAgent } = Proxy.createAgents(proxy, { const { httpAgent, httpsAgent } = Proxy.createAgents(proxy, {
httpsAgentOptions: httpsAgentOptions, httpsAgentOptions: httpsAgentOptions,
httpAgentOptions: httpAgentOptions,
}); });
options.proxy = false; options.proxy = false;
@ -499,6 +509,10 @@ class Monitor extends BeanModel {
} }
} }
if (!options.httpAgent) {
options.httpAgent = new http.Agent(httpAgentOptions);
}
if (!options.httpsAgent) { if (!options.httpsAgent) {
let jar = new CookieJar(); let jar = new CookieJar();
let httpsCookieAgentOptions = { let httpsCookieAgentOptions = {

View file

@ -792,6 +792,7 @@ let needSetup = false;
bean.url = monitor.url; bean.url = monitor.url;
bean.method = monitor.method; bean.method = monitor.method;
bean.body = monitor.body; bean.body = monitor.body;
bean.forceIp = monitor.forceIp;
bean.headers = monitor.headers; bean.headers = monitor.headers;
bean.basic_auth_user = monitor.basic_auth_user; bean.basic_auth_user = monitor.basic_auth_user;
bean.basic_auth_pass = monitor.basic_auth_pass; bean.basic_auth_pass = monitor.basic_auth_pass;

View file

@ -906,6 +906,21 @@
</select> </select>
</div> </div>
<div class="my-3">
<label for="forceIp" class="form-label">{{ $t("Force Ip") }}</label>
<select id="forceIp" v-model="monitor.forceIp" class="form-select">
<option :value="null">
{{ $t("None") }}
</option>
<option value="ipv4">
ipv4
</option>
<option value="ipv6">
ipv6
</option>
</select>
</div>
<!-- Encoding --> <!-- Encoding -->
<div class="my-3"> <div class="my-3">
<label for="httpBodyEncoding" class="form-label">{{ $t("Body Encoding") }}</label> <label for="httpBodyEncoding" class="form-label">{{ $t("Body Encoding") }}</label>
@ -1129,6 +1144,7 @@ const monitorDefaults = {
parent: null, parent: null,
url: "https://", url: "https://",
method: "GET", method: "GET",
forceIp: null,
interval: 60, interval: 60,
retryInterval: 60, retryInterval: 60,
resendInterval: 0, resendInterval: 0,