MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / fetchServiceMonitor

Function fetchServiceMonitor

nezha/nezha.ts:239–271  ·  view source on GitHub ↗
(
  config: NeZhaConfig,
  serverId: number
)

Source from the content-addressed store, hash-verified

237 try {
238 let secret = config.secret;
239 if (config.configPath) {
240 const fileSecret = readSecretFromConfig(config.configPath);
241 if (fileSecret) secret = fileSecret;
242 }
243 const token = generateJWT(secret);
244 const apiUrl = config.url.replace(/\/$/, "") + `/api/v1/service/${serverId}`;
245 const response = await axios.get<ServiceMonitorData>(apiUrl, {
246 timeout: 10000,
247 headers: {
248 Cookie: `nz-jwt=${token}`,
249 "User-Agent": "TeleBox-NeZha-Plugin/1.0",
250 },
251 });
252 if (response.data.success && response.data.data) {
253 for (const item of response.data.data) {
254 if (item.monitor_name && item.avg_delay && item.avg_delay.length > 0) {
255 const latestDelay = item.avg_delay[item.avg_delay.length - 1];
256 result.set(item.monitor_name, latestDelay);
257 }
258 }
259 }
260 } catch (error: any) {
261 console.error(`[NeZha Debug] Service monitor API error for server ${serverId}:`, error.message || error);
262 }
263 return result;
264}
265
266async function fetchServiceMonitorFull(
267 config: NeZhaConfig,
268 serverId: number
269): Promise<ServiceMonitorItem[]> {
270 try {
271 let secret = config.secret;
272 if (config.configPath) {
273 const fileSecret = readSecretFromConfig(config.configPath);
274 if (fileSecret) secret = fileSecret;

Callers 1

nezhaFunction · 0.85

Calls 4

readSecretFromConfigFunction · 0.85
generateJWTFunction · 0.85
errorMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected