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

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