feat: fix API Key authentication and payload alignment
- Update openclaw.plugin.json: replace challengeUuid with apiKey (optional) - Fix tsconfig: use CommonJS module to avoid import.meta.url issues - Fix plugin/index.ts: remove ESM-specific code, use __dirname - Fix telemetry.mjs: - Add loadavg to os imports, remove require() call - Replace challengeUuid with apiKey in config - Update endpoint to heartbeat-v2 - Add X-API-Key header when apiKey is configured - Fix payload field names: agents, load_avg (array), uptime_seconds - Change missing apiKey from error to warning
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
/**
|
||||
* HarborForge Monitor Plugin for OpenClaw
|
||||
*
|
||||
*
|
||||
* Manages sidecar lifecycle and provides monitor-related tools.
|
||||
*/
|
||||
import { spawn } from 'child_process';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
import { join } from 'path';
|
||||
import { existsSync } from 'fs';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
interface PluginConfig {
|
||||
enabled?: boolean;
|
||||
backendUrl?: string;
|
||||
identifier?: string;
|
||||
challengeUuid?: string;
|
||||
apiKey?: string;
|
||||
reportIntervalSec?: number;
|
||||
httpFallbackIntervalSec?: number;
|
||||
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
||||
@@ -35,7 +31,7 @@ interface PluginAPI {
|
||||
}
|
||||
|
||||
export default function register(api: PluginAPI, config: PluginConfig) {
|
||||
const logger = api.logger || {
|
||||
const logger = api.logger || {
|
||||
info: (...args: any[]) => console.log('[HF-Monitor]', ...args),
|
||||
error: (...args: any[]) => console.error('[HF-Monitor]', ...args),
|
||||
debug: (...args: any[]) => console.debug('[HF-Monitor]', ...args),
|
||||
@@ -47,14 +43,13 @@ export default function register(api: PluginAPI, config: PluginConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!config.challengeUuid) {
|
||||
logger.error('Missing required config: challengeUuid');
|
||||
logger.error('Please register server in HarborForge Monitor first');
|
||||
return;
|
||||
if (!config.apiKey) {
|
||||
logger.warn('Missing config: apiKey');
|
||||
logger.warn('API authentication will fail. Generate apiKey from HarborForge Monitor admin.');
|
||||
}
|
||||
|
||||
const serverPath = join(__dirname, '..', 'server', 'telemetry.mjs');
|
||||
|
||||
|
||||
if (!existsSync(serverPath)) {
|
||||
logger.error('Telemetry server not found:', serverPath);
|
||||
return;
|
||||
@@ -69,12 +64,12 @@ export default function register(api: PluginAPI, config: PluginConfig) {
|
||||
}
|
||||
|
||||
logger.info('Starting HarborForge Monitor telemetry server...');
|
||||
|
||||
|
||||
const env = {
|
||||
...process.env,
|
||||
HF_MONITOR_BACKEND_URL: config.backendUrl || 'https://monitor.hangman-lab.top',
|
||||
HF_MONITOR_IDENTIFIER: config.identifier || '',
|
||||
HF_MONITOR_CHALLENGE_UUID: config.challengeUuid,
|
||||
HF_MONITOR_API_KEY: config.apiKey || '',
|
||||
HF_MONITOR_REPORT_INTERVAL: String(config.reportIntervalSec || 30),
|
||||
HF_MONITOR_HTTP_FALLBACK_INTERVAL: String(config.httpFallbackIntervalSec || 60),
|
||||
HF_MONITOR_LOG_LEVEL: config.logLevel || 'info',
|
||||
@@ -117,7 +112,7 @@ export default function register(api: PluginAPI, config: PluginConfig) {
|
||||
|
||||
logger.info('Stopping HarborForge Monitor telemetry server...');
|
||||
sidecar.kill('SIGTERM');
|
||||
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
if (sidecar && !sidecar.killed) {
|
||||
logger.warn('Telemetry server did not exit gracefully, forcing kill');
|
||||
|
||||
Reference in New Issue
Block a user