@daemonitor/plugins 1.1.12 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -77,6 +77,33 @@ async function tunnelStatus(port) {
|
|
|
77
77
|
return { up: false };
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
+
// Inbound tunnels: on the PBX, each connected SBC (and any tunnelled client) holds
|
|
81
|
+
// an established session whose LOCAL port is the tunnel port (5090). Returns the
|
|
82
|
+
// set of distinct peer IPs — matching a configured SBC's edge IP tells us that SBC
|
|
83
|
+
// is still reaching the PBX, observed entirely from the PBX side.
|
|
84
|
+
async function inboundTunnelPeers(port) {
|
|
85
|
+
try {
|
|
86
|
+
const { stdout } = await pexec("ss", ["-tn", "state", "established"], { timeout: 6000 });
|
|
87
|
+
const suffix = `:${port}`;
|
|
88
|
+
const peers = new Set();
|
|
89
|
+
for (const line of stdout.split("\n")) {
|
|
90
|
+
const cols = line.trim().split(/\s+/);
|
|
91
|
+
if (cols.length < 2)
|
|
92
|
+
continue;
|
|
93
|
+
const local = cols[cols.length - 2];
|
|
94
|
+
const peer = cols[cols.length - 1];
|
|
95
|
+
if (!local || !local.endsWith(suffix))
|
|
96
|
+
continue; // only sessions we LISTEN for on :port
|
|
97
|
+
const ip = peer.replace(/:\d+$/, "").replace(/^\[|\]$/g, "").replace(/^::ffff:/, "");
|
|
98
|
+
if (ip)
|
|
99
|
+
peers.add(ip);
|
|
100
|
+
}
|
|
101
|
+
return [...peers];
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
80
107
|
async function collect3cx(inst) {
|
|
81
108
|
const role = inst.role === "sbc" ? "sbc" : "pbx";
|
|
82
109
|
const name = inst.name || hostname();
|
|
@@ -133,7 +160,19 @@ async function collect3cx(inst) {
|
|
|
133
160
|
const sip = await Promise.all(sipPorts.map(async (port) => ({ port, listening: await portListening(host, port) })));
|
|
134
161
|
const sipOk = sip.every((p) => p.listening);
|
|
135
162
|
const consoleProbe = { port: consolePort, listening: await portListening(host, consolePort) };
|
|
136
|
-
|
|
163
|
+
// Watch branch SBCs from the PBX side, if any are configured.
|
|
164
|
+
let sbcs = undefined;
|
|
165
|
+
let sbcTunnelCount = undefined;
|
|
166
|
+
if (Array.isArray(inst.sbcs) && inst.sbcs.length) {
|
|
167
|
+
const peers = await inboundTunnelPeers(pbxTunnelPort);
|
|
168
|
+
sbcTunnelCount = peers.length;
|
|
169
|
+
sbcs = inst.sbcs.map((s) => ({
|
|
170
|
+
name: s.name,
|
|
171
|
+
peer: s.peer,
|
|
172
|
+
connected: s.peer ? peers.includes(s.peer) : peers.length > 0,
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
return { ...svcCommon, sip, sipOk, console: consoleProbe, ...(sbcs ? { sbcs, sbcTunnelCount } : {}) };
|
|
137
176
|
}
|
|
138
177
|
export function createThreeCXPlugin() {
|
|
139
178
|
let refreshTimer = null;
|
|
@@ -151,6 +190,7 @@ export function createThreeCXPlugin() {
|
|
|
151
190
|
sipPorts: cfg.sipPorts,
|
|
152
191
|
consolePort: cfg.consolePort,
|
|
153
192
|
pbxTunnelPort: cfg.pbxTunnelPort,
|
|
193
|
+
sbcs: cfg.sbcs,
|
|
154
194
|
systemctlBin: cfg.systemctlBin,
|
|
155
195
|
uniqueId: cfg.uniqueId,
|
|
156
196
|
}];
|