Merge branch 'master' into feature/enhanced-discord-webhook-alerts-5535

This commit is contained in:
Frank Elsinga 2026-01-18 13:49:52 +01:00 committed by GitHub
commit b9db2c7d9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 1004 additions and 585 deletions

View File

@ -0,0 +1,11 @@
exports.up = async function (knex) {
await knex.schema.alterTable("monitor", (table) => {
table.string("snmp_v3_username", 255);
});
};
exports.down = async function (knex) {
await knex.schema.alterTable("monitor", (table) => {
table.dropColumn("snmp_v3_username");
});
};

1274
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -207,7 +207,7 @@
"stylelint-config-standard": "~25.0.0",
"terser": "~5.15.0",
"test": "~3.3.0",
"testcontainers": "^10.13.1",
"testcontainers": "^11.5.0",
"typescript": "~4.4.4",
"v-pagination-3": "~0.1.7",
"vite": "~5.4.15",

View File

@ -17,7 +17,22 @@ class SNMPMonitorType extends MonitorType {
timeout: monitor.timeout * 1000,
version: snmp.Version[monitor.snmpVersion],
};
session = snmp.createSession(monitor.hostname, monitor.radiusPassword, sessionOptions);
if (monitor.snmpVersion === "3") {
if (!monitor.snmp_v3_username) {
throw new Error("SNMPv3 username is required");
}
// SNMPv3 currently defaults to noAuthNoPriv.
// Supporting authNoPriv / authPriv requires additional inputs
// (auth/priv protocols, passwords), validation, secure storage,
// and database migrations, which is intentionally left for
// a follow-up PR to keep this change scoped.
sessionOptions.securityLevel = snmp.SecurityLevel.noAuthNoPriv;
sessionOptions.username = monitor.snmp_v3_username;
session = snmp.createV3Session(monitor.hostname, monitor.snmp_v3_username, sessionOptions);
} else {
session = snmp.createSession(monitor.hostname, monitor.radiusPassword, sessionOptions);
}
// Handle errors during session creation
session.on("error", (error) => {

View File

@ -18,7 +18,7 @@ class WeCom extends NotificationProvider {
},
};
config = this.getAxiosConfigWithProxy(config);
let body = this.composeMessage(heartbeatJSON, msg);
let body = this.composeMessage(notification, heartbeatJSON, msg);
await axios.post(
`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${notification.weComBotKey}`,
body,
@ -32,11 +32,12 @@ class WeCom extends NotificationProvider {
/**
* Generate the message to send
* @param {object} notification Notification configuration
* @param {object} heartbeatJSON Heartbeat details (For Up/Down only)
* @param {string} msg General message
* @returns {object} Message
*/
composeMessage(heartbeatJSON, msg) {
composeMessage(notification, heartbeatJSON, msg) {
let title = "UptimeKuma Message";
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
title = "UptimeKuma Monitor Up";
@ -44,11 +45,26 @@ class WeCom extends NotificationProvider {
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
title = "UptimeKuma Monitor Down";
}
let textObj = {
content: title + "\n" + msg,
};
// Handle mentioned_mobile_list if configured
if (notification.weComMentionedMobileList?.trim()) {
let mentionedMobiles = notification.weComMentionedMobileList
.split(",")
.map((mobile) => mobile.trim())
.filter((mobile) => mobile.length > 0);
if (mentionedMobiles.length > 0) {
textObj.mentioned_mobile_list = mentionedMobiles;
}
}
return {
msgtype: "text",
text: {
content: title + "\n" + msg,
},
text: textObj,
};
}
}

View File

@ -35,7 +35,13 @@
:aria-label="selectAll ? $t('deselectAllMonitorsAria') : $t('selectAllMonitorsAria')"
/>
<MonitorListFilter :filterState="filterState" @update-filter="updateFilter" />
<MonitorListFilter
:filterState="filterState"
:allCollapsed="allGroupsCollapsed"
:hasGroups="groupMonitors.length >= 2"
@update-filter="updateFilter"
@toggle-collapse-all="toggleCollapseAll"
/>
</div>
</div>
@ -100,8 +106,8 @@
</div>
<MonitorListItem
v-for="(item, index) in sortedMonitorList"
:key="index"
v-for="item in sortedMonitorList"
:key="`${item.id}-${collapseKey}`"
:monitor="item"
:isSelectMode="selectMode"
:isSelected="isSelected"
@ -154,6 +160,7 @@ export default {
active: null,
tags: null,
},
collapseKey: 0,
};
},
computed: {
@ -229,6 +236,38 @@ export default {
this.searchText !== ""
);
},
/**
* Gets all group monitors at root level that have children
* @returns {Array} Array of group monitors with children
*/
groupMonitors() {
const monitors = Object.values(this.$root.monitorList);
return monitors.filter(
(m) => m.type === "group" && m.parent === null && monitors.some((child) => child.parent === m.id)
);
},
/**
* Determines if all groups are collapsed.
* Note: collapseKey is included to force re-computation when toggleCollapseAll()
* updates localStorage, since Vue cannot detect localStorage changes.
* @returns {boolean} True if all groups are collapsed
*/
allGroupsCollapsed() {
// collapseKey forces this computed to re-evaluate after localStorage updates
if (this.collapseKey < 0 || this.groupMonitors.length === 0) {
return true;
}
const storage = window.localStorage.getItem("monitorCollapsed");
if (storage === null) {
return true; // Default is collapsed
}
const storageObject = JSON.parse(storage);
return this.groupMonitors.every((group) => storageObject[`monitor_${group.id}`] !== false);
},
},
watch: {
searchText() {
@ -303,6 +342,26 @@ export default {
updateFilter(newFilter) {
this.filterState = newFilter;
},
/**
* Toggle collapse state for all group monitors
* @returns {void}
*/
toggleCollapseAll() {
const shouldCollapse = !this.allGroupsCollapsed;
let storageObject = {};
const storage = window.localStorage.getItem("monitorCollapsed");
if (storage !== null) {
storageObject = JSON.parse(storage);
}
this.groupMonitors.forEach((group) => {
storageObject[`monitor_${group.id}`] = shouldCollapse;
});
window.localStorage.setItem("monitorCollapsed", JSON.stringify(storageObject));
this.collapseKey++;
},
/**
* Deselect a monitor
* @param {number} id ID of monitor
@ -731,6 +790,7 @@ export default {
.search-input {
width: 100%;
padding-right: 30px;
transition: none !important;
}
.monitor-item {

View File

@ -137,6 +137,15 @@
</li>
</template>
</MonitorListFilterDropdown>
<button
v-if="hasGroups"
type="button"
class="btn btn-outline-normal btn-collapse-all"
:title="allCollapsed ? $t('Expand All Groups') : $t('Collapse All Groups')"
@click="$emit('toggle-collapse-all')"
>
<font-awesome-icon :icon="allCollapsed ? 'folder' : 'folder-open'" fixed-width />
</button>
</template>
<script>
@ -155,8 +164,16 @@ export default {
type: Object,
required: true,
},
allCollapsed: {
type: Boolean,
default: true,
},
hasGroups: {
type: Boolean,
default: false,
},
},
emits: ["updateFilter"],
emits: ["updateFilter", "toggle-collapse-all"],
data() {
return {
tagsList: [],
@ -322,4 +339,8 @@ export default {
}
}
}
.btn-collapse-all {
transition: none !important;
}
</style>

View File

@ -23,4 +23,16 @@
</a>
</i18n-t>
</div>
<div class="mb-3">
<label for="wecom-mentioned-mobile-list" class="form-label">{{ $t("WeCom Mentioned Mobile List") }}</label>
<input
id="wecom-mentioned-mobile-list"
v-model="$parent.notification.weComMentionedMobileList"
type="text"
class="form-control"
placeholder="13800001111,13900002222,@all"
/>
<p class="form-text">{{ $t("WeCom Mentioned Mobile List Description") }}</p>
</div>
</template>

View File

@ -53,6 +53,8 @@ import {
faInfoCircle,
faClone,
faCertificate,
faFolder,
faFolderOpen,
} from "@fortawesome/free-solid-svg-icons";
library.add(
@ -103,6 +105,8 @@ library.add(
faInfoCircle,
faClone,
faCertificate,
faFolder,
faFolderOpen,
);
export { FontAwesomeIcon };

View File

@ -793,6 +793,8 @@
"Retry": "Retry",
"Topic": "Topic",
"WeCom Bot Key": "WeCom Bot Key",
"WeCom Mentioned Mobile List": "WeCom Mentioned Mobile List",
"WeCom Mentioned Mobile List Description": "Enter phone numbers to mention. Separate multiple numbers with commas. Use {'@'}all to mention everyone.",
"Setup Proxy": "Set Up Proxy",
"Proxy Protocol": "Proxy Protocol",
"Proxy Server": "Proxy Server",
@ -1109,6 +1111,7 @@
"snmpCommunityStringHelptext": "This string functions as a password to authenticate and control access to SNMP-enabled devices. Match it with your SNMP device's configuration.",
"OID (Object Identifier)": "OID (Object Identifier)",
"snmpOIDHelptext": "Enter the OID for the sensor or status you want to monitor. Use network management tools like MIB browsers or SNMP software if you're unsure about the OID.",
"snmpV3Username": "SNMPv3 Username",
"Condition": "Condition",
"SNMP Version": "SNMP Version",
"Please enter a valid OID.": "Please enter a valid OID.",
@ -1365,5 +1368,7 @@
"Expected TLS Alert": "Expected TLS Alert",
"None (Successful Connection)": "None (Successful Connection)",
"expectedTlsAlertDescription": "Select the TLS alert you expect the server to return. Use {code} to verify mTLS endpoints reject connections without client certificates. See {link} for details.",
"TLS Alert Spec": "RFC 8446"
"TLS Alert Spec": "RFC 8446",
"Expand All Groups": "Expand All Groups",
"Collapse All Groups": "Collapse All Groups"
}

View File

@ -1,7 +1,7 @@
<template>
<div class="container-fluid">
<div class="row">
<div v-if="!$root.isMobile" class="col-12 col-md-5 col-xl-4">
<div v-if="!$root.isMobile" class="col-12 col-md-5 col-xl-4 ps-0">
<div>
<router-link to="/add" class="btn btn-primary mb-3">
<font-awesome-icon icon="plus" />

View File

@ -5,7 +5,7 @@
{{ $t("Quick Stats") }}
</h1>
<div class="shadow-box big-padding text-center mb-4">
<div class="shadow-box big-padding text-center mb-3">
<div class="row">
<div class="col">
<h3>{{ $t("Up") }}</h3>

View File

@ -511,8 +511,23 @@
<select id="snmp_version" v-model="monitor.snmpVersion" class="form-select">
<option value="1">SNMPv1</option>
<option value="2c">SNMPv2c</option>
<option value="3">SNMPv3</option>
</select>
</div>
<div v-if="monitor.type === 'snmp' && monitor.snmpVersion === '3'" class="my-3">
<label for="snmp_v3_username" class="form-label">
{{ $t("snmpV3Username") }}
</label>
<input
id="snmp_v3_username"
v-model="monitor.snmpV3Username"
type="text"
class="form-control"
placeholder="SNMPv3 username"
required
/>
</div>
<div v-if="monitor.type === 'smtp'" class="my-3">
<label for="smtp_security" class="form-label">{{ $t("SMTP Security") }}</label>

View File

@ -0,0 +1,128 @@
const { describe, test } = require("node:test");
const assert = require("node:assert/strict");
const { GenericContainer } = require("testcontainers");
const { SNMPMonitorType } = require("../../server/monitor-types/snmp");
const { UP } = require("../../src/util");
const snmp = require("net-snmp");
describe("SNMPMonitorType", () => {
test(
"check() sets heartbeat to UP when SNMP agent responds",
{
skip: !!process.env.CI && (process.platform !== "linux" || process.arch !== "x64"),
},
async () => {
const container = await new GenericContainer("polinux/snmpd").withExposedPorts("161/udp").start();
try {
// Get the mapped UDP port
const hostPort = container.getMappedPort("161/udp");
const hostIp = container.getHost();
// UDP service small wait to ensure snmpd is ready inside container
await new Promise((r) => setTimeout(r, 2000));
const monitor = {
type: "snmp",
hostname: hostIp,
port: hostPort,
snmpVersion: "2c",
radiusPassword: "public",
snmpOid: "1.3.6.1.2.1.1.1.0",
timeout: 5,
maxretries: 1,
jsonPath: "$",
jsonPathOperator: "!=",
expectedValue: "",
};
const snmpMonitor = new SNMPMonitorType();
const heartbeat = {};
await snmpMonitor.check(monitor, heartbeat);
assert.strictEqual(heartbeat.status, UP);
assert.match(heartbeat.msg, /JSON query passes/);
} finally {
await container.stop();
}
}
);
test(
"check() throws when SNMP agent does not respond",
{
skip: !!process.env.CI && (process.platform !== "linux" || process.arch !== "x64"),
},
async () => {
const monitor = {
type: "snmp",
hostname: "127.0.0.1",
port: 65530, // Assuming no SNMP agent is running here
snmpVersion: "2c",
radiusPassword: "public",
snmpOid: "1.3.6.1.2.1.1.1.0",
timeout: 1,
maxretries: 1,
};
const snmpMonitor = new SNMPMonitorType();
const heartbeat = {};
await assert.rejects(() => snmpMonitor.check(monitor, heartbeat), /timeout|RequestTimedOutError/i);
}
);
test("check() uses SNMPv3 noAuthNoPriv session when version is 3", async () => {
const originalCreateV3Session = snmp.createV3Session;
const originalCreateSession = snmp.createSession;
let createV3Called = false;
let createSessionCalled = false;
let receivedOptions = null;
// Stub createV3Session
snmp.createV3Session = function (_host, _username, options) {
createV3Called = true;
receivedOptions = options;
return {
on: () => {},
close: () => {},
// Stop execution after session creation to avoid real network I/O.
get: (_oids, cb) => cb(new Error("stop test here")),
};
};
// Stub createSession
snmp.createSession = function () {
createSessionCalled = true;
return {};
};
const monitor = {
type: "snmp",
hostname: "127.0.0.1",
port: 161,
timeout: 5,
maxretries: 1,
snmpVersion: "3",
snmp_v3_username: "testuser",
snmpOid: "1.3.6.1.2.1.1.1.0",
};
const snmpMonitor = new SNMPMonitorType();
const heartbeat = {};
await assert.rejects(() => snmpMonitor.check(monitor, heartbeat), /stop test here/);
// Assertions
assert.strictEqual(createV3Called, true);
assert.strictEqual(createSessionCalled, false);
assert.strictEqual(receivedOptions.securityLevel, snmp.SecurityLevel.noAuthNoPriv);
// Restore originals
snmp.createV3Session = originalCreateV3Session;
snmp.createSession = originalCreateSession;
});
});