Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

feat: unify agent installation UI and scripts

[email protected]92f8426ee755
diff --git a/frontend-modern/src/components/Settings/DockerAgents.tsx b/frontend-modern/src/components/Settings/DockerAgents.tsx
deleted file mode 100644
index e92d784abd..0000000000
--- a/frontend-modern/src/components/Settings/DockerAgents.tsx
+++ /dev/null
@@ -1,1580 +0,0 @@
-import { Component, createSignal, Show, For, onMount, createEffect, createMemo } from 'solid-js';
-import { useWebSocket } from '@/App';
-import { Card } from '@/components/shared/Card';
-import { formatRelativeTime, formatAbsoluteTime } from '@/utils/format';
-import { MonitoringAPI } from '@/api/monitoring';
-import { SecurityAPI } from '@/api/security';
-import { notificationStore } from '@/stores/notifications';
-import type { SecurityStatus } from '@/types/config';
-import type { DockerHost } from '@/types/api';
-import type { APITokenRecord } from '@/api/security';
-import { DOCKER_REPORT_SCOPE } from '@/constants/apiScopes';
-import { resolveHostRuntime } from '@/components/Docker/runtimeDisplay';
-import { copyToClipboard } from '@/utils/clipboard';
-import { getPulseBaseUrl } from '@/utils/url';
-import { logger } from '@/utils/logger';
-
-
-export const DockerAgents: Component = () => {
- const { state } = useWebSocket();
-
- let hasLoggedSecurityStatusError = false;
-
- const [showHidden, setShowHidden] = createSignal(false);
-
- const allDockerHosts = () => state.dockerHosts || [];
-
- const dockerHosts = createMemo(() => {
- const all = allDockerHosts();
- const includeHidden = showHidden();
- let filtered = includeHidden ? all : all.filter(host => !host.hidden);
-
- if (!includeHidden) {
- filtered = filtered.filter(host => {
- if (!host.pendingUninstall) {
- return true;
- }
- const status = host.command?.status;
- return status === 'failed' || status === 'expired';
- });
- }
-
- return filtered;
- });
-
- const hiddenCount = () => allDockerHosts().filter(host => host.hidden).length;
-
- const pendingHosts = createMemo(() =>
- allDockerHosts().filter(host => {
- if (host.pendingUninstall) return true;
- const status = host.command?.status;
- return status === 'queued' || status === 'dispatched' || status === 'acknowledged' || status === 'completed';
- }),
- );
-
- const removedHosts = () => state.removedDockerHosts ?? [];
- const hasRemovedHosts = () => removedHosts().length > 0;
-
- const [removingHostId, setRemovingHostId] = createSignal<string | null>(null);
- const [showRemoveModal, setShowRemoveModal] = createSignal(false);
- const [hostToRemoveId, setHostToRemoveId] = createSignal<string | null>(null);
- const [uninstallCommandCopied, setUninstallCommandCopied] = createSignal(false);
- const [removeActionLoading, setRemoveActionLoading] = createSignal<
- 'queue' | 'force' | 'hide' | 'awaitingCommand' | null
- >(null);
- const [showAdvancedOptions, setShowAdvancedOptions] = createSignal(false);
- const [securityStatus, setSecurityStatus] = createSignal<SecurityStatus | null>(null);
- const [isGeneratingToken, setIsGeneratingToken] = createSignal(false);
- const [currentToken, setCurrentToken] = createSignal<string | null>(null);
- const [latestRecord, setLatestRecord] = createSignal<APITokenRecord | null>(null);
- const [tokenName, setTokenName] = createSignal('');
- const [commandQueuedTime, setCommandQueuedTime] = createSignal<Date | null>(null);
- const [elapsedSeconds, setElapsedSeconds] = createSignal(0);
- const [editingHostId, setEditingHostId] = createSignal<string | null>(null);
- const [editingDisplayName, setEditingDisplayName] = createSignal('');
- const [savingDisplayName, setSavingDisplayName] = createSignal(false);
-
- const pulseUrl = () => getPulseBaseUrl();
-
- const TOKEN_PLACEHOLDER = '<api-token>';
-
- const hostToRemove = createMemo(() => {
- const id = hostToRemoveId();
- if (!id) return null;
- return (state.dockerHosts || []).find(host => host.id === id) ?? null;
- });
-
- const getDisplayName = (host: DockerHost | { id: string; displayName?: string | null; hostname?: string | null; customDisplayName?: string | null }) => {
- if ('customDisplayName' in host && host.customDisplayName) {
- return host.customDisplayName;
- }
- return host.displayName || host.hostname || host.id;
- };
-
- const describeRuntime = (host: DockerHost) => {
- const runtimeInfo = resolveHostRuntime(host);
- const version = host.runtimeVersion || host.dockerVersion || '';
- return version ? `${runtimeInfo.label} ${version}` : runtimeInfo.label;
- };
-
- const modalDisplayName = () => {
- const host = hostToRemove();
- return host ? getDisplayName(host) : '';
- };
-
- const modalHostname = () => {
- const host = hostToRemove();
- return host?.hostname || host?.id || '';
- };
-
- const modalHostStatus = () => {
- const host = hostToRemove();
- return host?.status || 'unknown';
- };
-
- const modalHostIsOnline = () => modalHostStatus().toLowerCase() === 'online';
- const modalHostHidden = () => Boolean(hostToRemove()?.hidden);
- const modalCommand = createMemo(() => hostToRemove()?.command ?? null);
- const modalCommandStatus = createMemo(() => modalCommand()?.status ?? null);
- const modalCommandInProgress = createMemo(() => {
- const status = modalCommandStatus();
- return status === 'queued' || status === 'dispatched' || status === 'acknowledged';
- });
- const modalCommandFailed = createMemo(() => modalCommandStatus() === 'failed');
- const modalCommandCompleted = createMemo(() => modalCommandStatus() === 'completed');
- const modalCommandProgress = createMemo(() => {
- const cmd = modalCommand();
- if (!cmd) return [];
-
- const statusOrder: Record<string, number> = {
- queued: 0,
- dispatched: 1,
- acknowledged: 2,
- completed: 3,
- failed: 4,
- expired: 5,
- };
- const currentIndex = statusOrder[cmd.status] ?? 0;
- const steps = [
- { key: 'queued', label: 'Stop command queued' },
- { key: 'dispatched', label: 'Instruction delivered to the agent' },
- { key: 'acknowledged', label: 'Agent acknowledged the stop request' },
- { key: 'completed', label: 'Agent disabled the service and removed autostart' },
- ];
-
- return steps.map((step) => {
- const stepIndex = statusOrder[step.key] ?? 0;
- return {
- label: step.label,
- done: currentIndex > stepIndex,
- active: currentIndex === stepIndex,
- };
- });
- });
-
- const modalCommandTimedOut = createMemo(() => {
- return modalCommandInProgress() && elapsedSeconds() > 120; // 2 minutes
- });
-
- const modalLastHeartbeat = createMemo(() => {
- const host = hostToRemove();
- return host?.lastSeen ? formatRelativeTime(host.lastSeen) : null;
- });
-
- const modalHostPendingUninstall = createMemo(() => Boolean(hostToRemove()?.pendingUninstall));
- const modalHasCommand = createMemo(() => Boolean(modalCommand()));
- const [hasShownCommandCompletion, setHasShownCommandCompletion] = createSignal(false);
-
- const formatElapsedTime = (seconds: number) => {
- if (seconds < 60) {
- return `${seconds}s`;
- }
- const mins = Math.floor(seconds / 60);
- const secs = seconds % 60;
- return `${mins}m ${secs}s`;
- };
-
- type RemovalStatusTone = 'info' | 'success' | 'danger';
-
- const removalBadgeClassMap: Record<RemovalStatusTone, string> = {
- info: 'inline-flex items-center gap-1 rounded-full bg-blue-100 px-2 py-0.5 text-[11px] font-semibold uppercase tracking-wide text-blue-700 dark:bg-blue-900/40 dark:text-blue-200',
- success:
- 'inline-flex items-center gap-1 rounded-full bg-emerald-100 px-2 py-0.5 text-[11px] font-semibold uppercase tracking-wide text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200',
- danger:
- 'inline-flex items-center gap-1 rounded-full bg-red-100 px-2 py-0.5 text-[11px] font-semibold uppercase tracking-wide text-red-600 dark:bg-red-900/40 dark:text-red-200',
- };
-
- const removalTextClassMap: Record<RemovalStatusTone, string> = {
- info: 'text-blue-700 dark:text-blue-300',
- success: 'text-emerald-700 dark:text-emerald-300',
- danger: 'text-red-600 dark:text-red-300',
- };
-
- const getRemovalStatusInfo = (host: DockerHost): { label: string; tone: RemovalStatusTone } | null => {
- const status = host.command?.status ?? null;
-
- switch (status) {
- case 'failed':
- return {
- label: host.command?.failureReason || 'Pulse could not stop the agent automatically.',
- tone: 'danger',
- };
- case 'expired':
- return {
- label: 'Stop command expired before the agent responded.',
- tone: 'danger',
- };
- case 'completed':
- return {
- label: 'Agent stopped. Pulse will hide this host after the next missed heartbeat.',
- tone: 'success',
- };
- case 'acknowledged':
- return { label: 'Agent acknowledged the stop command—waiting for shutdown.', tone: 'info' };
- case 'dispatched':
- return { label: 'Instruction delivered to the agent.', tone: 'info' };
- case 'queued':
- return { label: 'Stop command queued; waiting to reach the agent.', tone: 'info' };
- default:
- if (host.pendingUninstall) {
- return { label: 'Marked for uninstall; waiting for agent confirmation.', tone: 'info' };
- }
- return null;
- }
- };
-
- createEffect(() => {
- if (!showRemoveModal()) return;
- const id = hostToRemoveId();
- const host = hostToRemove();
- if (id && !host) {
- closeRemoveModal();
- }
- });
-
- createEffect(() => {
- if (!showRemoveModal()) {
- return;
- }
- if (removeActionLoading() === 'awaitingCommand') {
- if (modalHasCommand() || modalHostPendingUninstall() || modalCommandFailed()) {
- setRemoveActionLoading(null);
- }
- }
- });
-
- // Track elapsed time for command execution
- createEffect(() => {
- const cmd = modalCommand();
- if (!cmd) {
- setCommandQueuedTime(null);
- setElapsedSeconds(0);
- return;
- }
-
- // Set queued time when command first appears
- if (cmd.createdAt && !commandQueuedTime()) {
- setCommandQueuedTime(new Date(cmd.createdAt));
- }
-
- // Update elapsed time every second while command is in progress
- if (modalCommandInProgress()) {
- const interval = setInterval(() => {
- const queuedTime = commandQueuedTime();
- if (queuedTime) {
- const now = new Date();
- const elapsed = Math.floor((now.getTime() - queuedTime.getTime()) / 1000);
- setElapsedSeconds(elapsed);
- }
- }, 1000);
-
- return () => clearInterval(interval);
- }
- });
-
- createEffect(() => {
- if (!showRemoveModal()) {
- return;
- }
- if (modalCommandCompleted() && !hasShownCommandCompletion()) {
- setHasShownCommandCompletion(true);
- notificationStore.success('Agent stopped. Pulse will hide this host after the next heartbeat.', 5000);
- if (typeof window !== 'undefined') {
- window.setTimeout(() => {
- closeRemoveModal();
- }, 1200);
- } else {
- closeRemoveModal();
- }
- }
- });
-
- onMount(() => {
- if (typeof window === 'undefined') {
- return;
- }
-
- const fetchSecurityStatus = async () => {
- try {
- const response = await fetch('/api/security/status', { credentials: 'include' });
- if (response.ok) {
- const data = (await response.json()) as SecurityStatus;
- setSecurityStatus(data);
- }
- } catch (err) {
- if (!hasLoggedSecurityStatusError) {
- hasLoggedSecurityStatusError = true;
- logger.error('Failed to load security status', err);
- }
- }
- };
- fetchSecurityStatus();
- });
-
- const showInstallCommand = () => !requiresToken() || Boolean(currentToken());
-
- const handleGenerateToken = async () => {
- if (isGeneratingToken()) return;
- setIsGeneratingToken(true);
- try {
- const name = tokenName().trim() || `Container host ${new Date().toISOString().slice(0, 10)}`;
- const { token, record } = await SecurityAPI.createToken(name, [DOCKER_REPORT_SCOPE]);
-
- setCurrentToken(token);
- setLatestRecord(record);
- setTokenName('');
- notificationStore.success('Token generated and inserted into the command below.', 4000);
- } catch (err) {
- logger.error('Failed to generate API token', err);
- const errorMsg = err instanceof Error ? err.message : 'Unknown error';
- notificationStore.error(`Failed to generate API token: ${errorMsg}`, 8000);
- } finally {
- setIsGeneratingToken(false);
- }
- };
-
- const requiresToken = () => {
- const status = securityStatus();
- if (status) {
- return status.requiresAuth || status.apiTokenConfigured;
- }
- return true;
- };
-
- // Always return command template with placeholder; the UI replaces it with the selected token.
- const getInstallCommandTemplate = () => {
- const url = pulseUrl();
- const tokenValue = requiresToken() ? TOKEN_PLACEHOLDER : 'disabled';
- const tokenSegment = `--token '${tokenValue}'`;
- return `curl -fsSL '${url}/install.sh' | bash -s -- --url '${url}' ${tokenSegment} --enable-docker`;
- };
-
- const getUninstallCommand = () => {
- const url = pulseUrl();
- return `curl -fsSL '${url}/install.sh' | bash -s -- --uninstall`;
- };
-
- const getSystemdService = () => {
- const token = requiresToken() ? TOKEN_PLACEHOLDER : 'disabled';
- return `[Unit]
-Description=Pulse Unified Agent
-After=network-online.target docker.service
-Wants=network-online.target
-
-[Service]
-Type=simple
-ExecStart=/usr/local/bin/pulse-agent --url ${pulseUrl()} --token ${token} --interval 30s --enable-docker
-Restart=always
-RestartSec=5s
-User=root
-
-[Install]
-WantedBy=multi-user.target`;
- };
-
- const getAllowReenrollCommand = (hostId: string) => {
- const url = pulseUrl();
- return `curl -X POST -H "X-API-Token: <token-with-docker:manage>" ${url}/api/agents/docker/hosts/${hostId}/allow-reenroll`;
- };
-
- const handleAllowReenroll = async (hostId: string, label: string) => {
- try {
- await MonitoringAPI.allowDockerHostReenroll(hostId);
- notificationStore.success(`Allowed ${label} to report again`, 4000);
- } catch (error) {
- logger.error('Failed to allow host re-enroll', error);
- const message =
- error instanceof Error
- ? error.message
- : 'Failed to clear the removal block. Confirm your account has docker:manage access.';
- notificationStore.error(message, 8000);
- }
- };
-
- const handleCopyAllowCommand = async (hostId: string, label: string) => {
- const command = getAllowReenrollCommand(hostId);
- const copied = await copyToClipboard(command);
- if (copied) {
- notificationStore.success(`Command copied for ${label}`, 3500);
- } else {
- notificationStore.error('Copy failed. You can still manually copy the snippet.', 4000);
- }
- };
-
- const isRemovingHost = (hostId: string) => removingHostId() === hostId;
-
- const openRemoveModal = (host: DockerHost) => {
- setHostToRemoveId(host.id);
- setUninstallCommandCopied(false);
- setRemoveActionLoading(null);
- setShowAdvancedOptions(false);
- setShowRemoveModal(true);
- setHasShownCommandCompletion(false);
- };
-
- const closeRemoveModal = () => {
- setShowRemoveModal(false);
- setHostToRemoveId(null);
- setUninstallCommandCopied(false);
- setRemoveActionLoading(null);
- setShowAdvancedOptions(false);
- setHasShownCommandCompletion(false);
- };
-
- const handleQueueStopCommand = async () => {
- const host = hostToRemove();
- if (!host || removeActionLoading()) return;
-
- const displayName = getDisplayName(host);
- setRemovingHostId(host.id);
- setRemoveActionLoading('queue');
-
- try {
- await MonitoringAPI.deleteDockerHost(host.id);
- notificationStore.success(`Stop command sent to ${displayName}`, 3500);
- setRemoveActionLoading('awaitingCommand');
- } catch (error) {
- logger.error('Failed to queue host stop command', error);
- const message = error instanceof Error ? error.message : 'Failed to send stop command';
- notificationStore.error(message, 8000);
- setRemoveActionLoading(null);
- } finally {
- setRemovingHostId(null);
- }
- };
-
- const handleHideHostFromModal = async () => {
- const host = hostToRemove();
- if (!host || (removeActionLoading() && removeActionLoading() !== 'awaitingCommand')) return;
-
- const displayName = getDisplayName(host);
- setRemovingHostId(host.id);
- setRemoveActionLoading('hide');
-
- try {
- await MonitoringAPI.deleteDockerHost(host.id, { hide: true });
- notificationStore.success(`Hidden host ${displayName}`, 3500);
- closeRemoveModal();
- } catch (error) {
- logger.error('Failed to hide host', error);
- const message = error instanceof Error ? error.message : 'Failed to hide host';
- notificationStore.error(message, 8000);
- } finally {
- setRemovingHostId(null);
- setRemoveActionLoading(null);
- }
- };
-
- const handleRemoveHostNow = async () => {
- const host = hostToRemove();
- if (!host || (removeActionLoading() && removeActionLoading() !== 'awaitingCommand')) return;
-
- const displayName = getDisplayName(host);
- setRemovingHostId(host.id);
- setRemoveActionLoading('force');
-
- try {
- await MonitoringAPI.deleteDockerHost(host.id, { force: true });
- notificationStore.success(`Removed host ${displayName}`, 3500);
- closeRemoveModal();
- } catch (error) {
- logger.error('Failed to remove host', error);
- const message = error instanceof Error ? error.message : 'Failed to remove host';
- notificationStore.error(message, 8000);
- } finally {
- setRemovingHostId(null);
- setRemoveActionLoading(null);
- }
- };
-
- const handleCleanupOfflineHost = async (hostId: string, displayName: string) => {
- if (isRemovingHost(hostId)) return;
-
- setRemovingHostId(hostId);
-
- try {
- await MonitoringAPI.deleteDockerHost(hostId, { force: true });
- notificationStore.success(`Removed host ${displayName}`, 3500);
- if (hostToRemoveId() === hostId) {
- closeRemoveModal();
- }
- } catch (error) {
- logger.error('Failed to remove host', error);
- const message = error instanceof Error ? error.message : 'Failed to remove host';
- notificationStore.error(message, 8000);
- } finally {
- setRemovingHostId(null);
- }
- };
-
- const handleUnhideHost = async (hostId: string, displayName: string) => {
- if (isRemovingHost(hostId)) return;
-
- setRemovingHostId(hostId);
-
- try {
- await MonitoringAPI.unhideDockerHost(hostId);
- notificationStore.success(`Unhidden host ${displayName}`, 3500);
- } catch (error) {
- logger.error('Failed to unhide host', error);
- const message = error instanceof Error ? error.message : 'Failed to unhide host';
- notificationStore.error(message, 8000);
- } finally {
- setRemovingHostId(null);
- }
- };
-
- const startEditingDisplayName = (host: DockerHost) => {
- setEditingHostId(host.id);
- setEditingDisplayName(host.customDisplayName || '');
- };
-
- const cancelEditingDisplayName = () => {
- setEditingHostId(null);
- setEditingDisplayName('');
- };
-
- const saveDisplayName = async (hostId: string, originalName: string) => {
- const newName = editingDisplayName().trim();
-
- setSavingDisplayName(true);
- try {
- await MonitoringAPI.setDockerHostDisplayName(hostId, newName);
- notificationStore.success(`Updated display name for ${originalName}`, 3500);
- setEditingHostId(null);
- setEditingDisplayName('');
- } catch (error) {
- logger.error('Failed to update display name', error);
- const message = error instanceof Error ? error.message : 'Failed to update display name';
- notificationStore.error(message, 8000);
- } finally {
- setSavingDisplayName(false);
- }
- };
-
- return (
- <div class="space-y-6">
- <Show when={hasRemovedHosts()}>
- <Card
- padding="lg"
- class="space-y-4 border border-amber-300 bg-amber-50 text-amber-900 shadow-sm dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-100"
- >
- <div class="space-y-1">
- <h3 class="text-sm font-semibold">Recently removed container hosts</h3>
- <p class="text-sm text-amber-800 dark:text-amber-200">
- Pulse is currently blocking these hosts because they were explicitly removed. Allow them to re-enroll or
- copy the command below and run it with a token that includes the <code>docker:manage</code> scope.
- </p>
- </div>
-
- <div class="space-y-3">
- <For each={removedHosts()}>
- {(entry) => {
- const label = entry.displayName || entry.hostname || entry.id;
- return (
- <div class="rounded-lg border border-amber-200 bg-white/80 p-4 shadow-sm dark:border-amber-500/40 dark:bg-amber-950/20">
- <div class="flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
- <div>
- <p class="text-sm font-semibold text-gray-900 dark:text-gray-100">{label}</p>
- <p class="text-xs text-gray-500 dark:text-gray-400">Host ID: {entry.id}</p>
- </div>
- <div class="text-xs text-gray-500 dark:text-gray-400">
- Removed {formatRelativeTime(entry.removedAt)}
- </div>
- </div>
-
- <div class="mt-3 flex flex-wrap gap-2">
- <button
- type="button"
- onClick={() => handleAllowReenroll(entry.id, label)}
- class="inline-flex items-center justify-center gap-2 rounded-md bg-emerald-600 px-3 py-1.5 text-xs font-medium text-white transition hover:bg-emerald-700 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-1 dark:focus:ring-offset-gray-900"
- >
- Allow re-enroll
- </button>
- <button
- type="button"
- onClick={() => handleCopyAllowCommand(entry.id, label)}
- class="inline-flex items-center justify-center gap-2 rounded-md border border-emerald-600/50 px-3 py-1.5 text-xs font-medium text-emerald-700 transition hover:bg-emerald-50 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-1 dark:border-emerald-400/60 dark:text-emerald-200 dark:hover:bg-emerald-500/20 dark:focus:ring-offset-gray-900"
- >
- Copy curl command
- </button>
- </div>
- </div>
- );
- }}
- </For>
- <p class="text-xs text-amber-800 dark:text-amber-200">
- If you removed a host intentionally, you can simply ignore it—entries expire automatically after 24 hours.
- </p>
- </div>
- </Card>
- </Show>
-
- <Card padding="lg" class="space-y-5">
- <div class="space-y-2">
- <h3 class="text-base font-semibold text-gray-900 dark:text-gray-100">Enroll a container runtime</h3>
- <p class="text-sm text-gray-600 dark:text-gray-400">
- Run the command below on any host running Docker or Podman. The installer will automatically detect your container runtime.
- </p>
- </div>
-
- <div class="space-y-5">
- <Show when={requiresToken()}>
- <div class="space-y-3">
- <div class="space-y-1">
- <p class="text-sm font-semibold text-gray-900 dark:text-gray-100">Generate API token</p>
- <p class="text-sm text-gray-600 dark:text-gray-400">
- Create a fresh token scoped to <code>{DOCKER_REPORT_SCOPE}</code>
- </p>
- </div>
-
- <div class="flex gap-2">
- <input
- type="text"
- value={tokenName()}
- onInput={(e) => setTokenName(e.currentTarget.value)}
- onKeyDown={(e) => {
- if (e.key === 'Enter' && !isGeneratingToken()) {
- handleGenerateToken();
- }
- }}
- placeholder="Token name (optional)"
- class="flex-1 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-100 dark:focus:border-blue-400 dark:focus:ring-blue-900/60"
- />
- <button
- type="button"
- onClick={handleGenerateToken}
- disabled={isGeneratingToken()}
- class="inline-flex items-center justify-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-60"
- >
- {isGeneratingToken() ? 'Generating…' : currentToken() ? 'Generate another' : 'Generate token'}
- </button>
- </div>
-
- <Show when={latestRecord()}>
- <div class="flex items-center gap-2 rounded-lg border border-blue-200 bg-blue-50 px-4 py-2 text-xs text-blue-800 dark:border-blue-800 dark:bg-blue-900/20 dark:text-blue-200">
- <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
- <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
- </svg>
- <span>
- Token <strong>{latestRecord()?.name}</strong> created and inserted into the command below.
- </span>
- </div>
- </Show>
- </div>
- </Show>
-
- <Show when={showInstallCommand()}>
- <div class="space-y-3">
- <div class="flex items-center justify-between">
- <label class="text-sm font-semibold text-gray-900 dark:text-gray-100">Install command</label>
- <button
- type="button"
- onClick={async () => {
- const command = getInstallCommandTemplate().replace(TOKEN_PLACEHOLDER, currentToken() || TOKEN_PLACEHOLDER);
- const success = await copyToClipboard(command);
- if (typeof window !== 'undefined' && window.showToast) {
- window.showToast(success ? 'success' : 'error', success ? 'Copied!' : 'Failed to copy');
- }
- }}
- class="px-3 py-1.5 text-xs font-medium rounded-lg transition-colors bg-blue-600 text-white hover:bg-blue-700"
- >
- Copy command
- </button>
- </div>
- <pre class="overflow-x-auto rounded-md bg-gray-900/90 p-3 text-xs text-gray-100">
- <code>{getInstallCommandTemplate().replace(TOKEN_PLACEHOLDER, currentToken() || TOKEN_PLACEHOLDER)}</code>
- </pre>
- <p class="text-xs text-gray-500 dark:text-gray-400">
- The unified installer downloads the agent, detects your container runtime, configures a systemd service, and starts reporting automatically.
- </p>
- </div>
- </Show>
-
- <Show when={requiresToken() && !currentToken()}>
- <p class="text-xs text-gray-500 dark:text-gray-400">
- Generate a token to see the install command.
- </p>
- </Show>
- </div>
-
- <details class="rounded-lg border border-gray-200 bg-gray-50 px-4 py-3 text-sm text-gray-700 dark:border-gray-700 dark:bg-gray-800/50 dark:text-gray-300">
- <summary class="cursor-pointer text-sm font-medium text-gray-900 dark:text-gray-100">
- Advanced options (uninstall & manual install)
- </summary>
- <div class="mt-3 space-y-4">
- <div>
- <p class="text-xs uppercase tracking-wide text-gray-500 dark:text-gray-400">Uninstall</p>
- <div class="mt-2 flex items-center gap-2">
- <code class="flex-1 break-all rounded bg-gray-900 px-3 py-2 font-mono text-xs text-red-400 dark:bg-gray-950">
- {getUninstallCommand()}
- </code>
- <button
- type="button"
- onClick={async () => {
- const success = await copyToClipboard(getUninstallCommand());
- if (typeof window !== 'undefined' && window.showToast) {
- window.showToast(success ? 'success' : 'error', success ? 'Copied to clipboard' : 'Failed to copy to clipboard');
- }
- }}
- class="rounded-lg bg-red-50 px-3 py-1.5 text-xs font-medium text-red-700 transition-colors hover:bg-red-100 dark:bg-red-900/30 dark:text-red-300 dark:hover:bg-red-900/50"
- >
- Copy
- </button>
- </div>
- <p class="mt-2 text-xs text-gray-500 dark:text-gray-400">
- Stops the agent, removes the binary, the systemd unit, and related files.
- </p>
- </div>
-
- <div>
- <p class="text-xs uppercase tracking-wide text-gray-500 dark:text-gray-400">Manual installation</p>
- <div class="mt-2 space-y-3 rounded-lg border border-gray-200 bg-white p-3 text-xs dark:border-gray-700 dark:bg-gray-900">
- <p class="font-medium text-gray-900 dark:text-gray-100">1. Build the binary</p>
- <div class="rounded bg-gray-900 p-3 font-mono text-xs text-gray-100 dark:bg-gray-950">
- <code>
- cd /opt/pulse
- <br />
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pulse-agent ./cmd/pulse-agent
- </code>
- </div>
- <p class="text-xs text-gray-500 dark:text-gray-400">
- Building with <code class="font-mono text-[11px]">CGO_ENABLED=0</code> keeps the binary fully static so it runs on hosts with older glibc (e.g. Debian 11).
- </p>
- <p class="font-medium text-gray-900 dark:text-gray-100">2. Copy to host</p>
- <div class="rounded bg-gray-900 p-3 font-mono text-xs text-gray-100 dark:bg-gray-950">
- <code>
- scp pulse-agent user@docker-host:/usr/local/bin/
- <br />
- ssh user@docker-host chmod +x /usr/local/bin/pulse-agent
- </code>
- </div>
- <p class="font-medium text-gray-900 dark:text-gray-100">3. Systemd template</p>
- <div class="relative">
- <button
- type="button"
- onClick={async () => {
- const success = await copyToClipboard(getSystemdService());
- if (typeof window !== 'undefined' && window.showToast) {
- window.showToast(success ? 'success' : 'error', success ? 'Copied to clipboard' : 'Failed to copy to clipboard');
- }
- }}
- class="absolute right-2 top-2 rounded-lg bg-gray-700 px-3 py-1.5 text-xs font-medium text-gray-200 transition-colors hover:bg-gray-600"
- >
- Copy
- </button>
- <div class="rounded bg-gray-900 p-3 font-mono text-xs text-gray-100 dark:bg-gray-950">
- <pre>{getSystemdService()}</pre>
- </div>
- </div>
- <p class="font-medium text-gray-900 dark:text-gray-100">4. Enable & start</p>
- <div class="rounded bg-gray-900 p-3 font-mono text-xs text-gray-100 dark:bg-gray-950">
- <code>
- systemctl daemon-reload
- <br />
- systemctl enable --now pulse-agent
- </code>
- </div>
- </div>
- </div>
- </div>
- </details>
- </Card>
-
- {/* Remove Container Host Modal */}
- <Show when={showRemoveModal()}>
- <div class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
- <div class="w-full max-w-2xl rounded-lg bg-white p-6 shadow-xl dark:bg-gray-800">
- <div class="space-y-2">
- <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100">
- Remove container host "{modalDisplayName()}"
- </h3>
- <p class="text-sm text-gray-600 dark:text-gray-400">
- Pulse guides you through uninstalling the agent and safely cleaning up the host entry.
- </p>
- </div>
-
- <div class="mt-4 space-y-4">
- <div class="rounded-lg border border-blue-200 bg-blue-50 p-4 space-y-3 dark:border-blue-800 dark:bg-blue-900/20">
- <div class="flex items-start gap-3">
- <svg class="w-5 h-5 text-blue-600 dark:text-blue-400 mt-0.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
- </svg>
- <div class="flex-1 space-y-2">
- <h4 class="text-sm font-semibold text-blue-900 dark:text-blue-100">Step 1 · Pulse stops the agent</h4>
- <p class="text-sm text-blue-800 dark:text-blue-200">
- Pulse will queue a stop command with this host. The agent shuts down its system service (or Unraid autostart hook if present), confirms back to Pulse, and the row disappears as soon as that acknowledgement arrives—or after the next missed heartbeat.
- </p>
- <Show when={modalCommand()}>
- <div class="rounded border border-blue-200 bg-white px-3 py-2 text-xs text-blue-800 dark:border-blue-700 dark:bg-blue-800/20 dark:text-blue-200">
- <div class="flex items-center justify-between gap-3">
- <span class="font-semibold uppercase tracking-wide text-[11px] text-blue-600 dark:text-blue-300">Command status</span>
- <span class="rounded-full bg-blue-100 px-2 py-0.5 text-[11px] font-medium uppercase text-blue-700 dark:bg-blue-900/40 dark:text-blue-300">
- {modalCommandStatus()}
- </span>
- </div>
- <Show when={modalCommand()?.message}>
- <p class="mt-2 leading-snug">{modalCommand()?.message}</p>
- </Show>
- <Show when={modalCommandFailed()}>
- <p class="mt-2 font-medium text-red-600 dark:text-red-300">
- {modalCommand()?.failureReason || 'Pulse could not stop the agent automatically.'}
- </p>
- </Show>
- </div>
- </Show>
- <button
- type="button"
- onClick={handleQueueStopCommand}
- disabled={
- removeActionLoading() !== null ||
- modalCommandInProgress() ||
- modalCommandStatus() === 'completed' ||
- (modalHostPendingUninstall() && !modalHasCommand())
- }
- class={`inline-flex items-center justify-center rounded px-4 py-2 text-sm font-medium text-white transition-colors ${modalCommandStatus() === 'completed'
- ? 'bg-emerald-600 dark:bg-emerald-500'
- : 'bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-400'
- } disabled:cursor-not-allowed disabled:opacity-60`}
- >
- {(() => {
- if (removeActionLoading() === 'queue') return 'Sending…';
- if (removeActionLoading() === 'awaitingCommand') return 'Waiting for agent…';
- if (modalCommandInProgress()) return 'Waiting for agent…';
- if (modalCommandStatus() === 'completed') return 'Agent stopped';
- if (!modalHasCommand() && modalHostPendingUninstall()) return 'Waiting for host…';
- if (modalCommandFailed()) return 'Retry stop command';
- return 'Stop agent now';
- })()}
- </button>
- <Show
- when={
- removeActionLoading() === 'awaitingCommand' &&
- !modalHasCommand() &&
- !modalHostPendingUninstall()
- }
- >
- <div class="rounded border border-blue-200 bg-white p-3 dark:border-blue-700 dark:bg-blue-800/20">
- <div class="flex items-start gap-2 text-xs text-blue-700 dark:text-blue-200">
- <svg class="mt-0.5 h-4 w-4 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
- </svg>
- <div>
- <p class="font-semibold">Stop command sent.</p>
- <p class="mt-1 leading-snug">
- Pulse is waiting for <span class="font-medium">{modalHostname()}</span> to pick up the shutdown instruction. This usually finishes within 30-60 seconds.
- </p>
- </div>
- </div>
- </div>
- </Show>
- <Show
- when={
- modalCommandInProgress() ||
- modalCommandCompleted() ||
- (!modalHasCommand() && modalHostPendingUninstall())
- }
- >
- <div class="space-y-3">
- <Show when={modalHasCommand()}>
- <div class="rounded border border-blue-200 bg-white p-3 dark:border-blue-700 dark:bg-blue-800/20">
- <div class="mb-2 flex items-center justify-between">
- <span class="text-xs font-semibold uppercase tracking-wide text-blue-700 dark:text-blue-300">Progress</span>
- <Show
- when={!modalCommandCompleted()}
- fallback={<span class="text-xs font-semibold text-emerald-600 dark:text-emerald-300">Completed</span>}
- >
- <span class="text-xs text-blue-600 dark:text-blue-400">{formatElapsedTime(elapsedSeconds())} elapsed</span>
- </Show>
- </div>
- <ul class="space-y-1.5">
- <For each={modalCommandProgress()}>
- {(step) => (
- <li
- class={`${step.done || step.active ? 'text-blue-700 dark:text-blue-200' : 'text-gray-500 dark:text-gray-400'} flex items-center gap-2 text-xs`}
- >
- <span
- class={`relative h-2 w-2 flex-shrink-0 rounded-full ${step.done
- ? 'bg-blue-500'
- : step.active
- ? 'bg-blue-400 animate-pulse'
- : 'bg-gray-300 dark:bg-gray-600'
- } ${modalCommandCompleted() && step.done ? 'after:absolute after:-inset-1 after:rounded-full after:border after:border-emerald-400/40 after:animate-pulse' : ''}`}
- />
- {step.label}
- </li>
- )}
- </For>
- </ul>
- </div>
- </Show>
-
- <Show when={!modalHasCommand() && modalHostPendingUninstall()}>
- <div class="rounded border border-blue-200 bg-white p-3 text-xs text-blue-700 dark:border-blue-700 dark:bg-blue-800/20 dark:text-blue-200">
- <p class="font-semibold">Agent already stopped.</p>
- <p class="mt-1 leading-snug">
- Pulse is waiting for <span class="font-medium">{modalHostname()}</span> to miss its next heartbeat so the host can be removed automatically. No further action is required—this usually finishes within 60 seconds.
- </p>
- <Show when={modalLastHeartbeat()}>
- <p class="mt-2 text-[11px]">
- Last heartbeat: {modalLastHeartbeat()}. Pulse will clear the entry after the next missed report.
- </p>
- </Show>
- </div>
- </Show>
-
- <Show when={modalHasCommand() && !modalCommandCompleted()}>
- <div class="flex items-start gap-2 text-xs text-blue-700 dark:text-blue-300">
- <svg class="w-4 h-4 mt-0.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
- </svg>
- <div>
- <p>
- <Show when={!modalCommandTimedOut()} fallback="This is taking longer than expected.">
- This usually takes 30-60 seconds.
- </Show>
- <Show when={modalLastHeartbeat()}>
- {' '}Last heartbeat: {modalLastHeartbeat()}.
- </Show>
- </p>
- </div>
- </div>
- </Show>
-
- <Show when={modalHasCommand() && modalCommandTimedOut() && !modalCommandCompleted()}>
- <div class="rounded border border-yellow-200 bg-yellow-50 p-3 dark:border-yellow-700 dark:bg-yellow-900/20">
- <div class="flex items-start gap-2">
- <svg class="w-4 h-4 mt-0.5 flex-shrink-0 text-yellow-600 dark:text-yellow-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
- </svg>
- <div class="flex-1 text-xs">
- <p class="font-semibold text-yellow-900 dark:text-yellow-100">Command taking longer than expected</p>
- <p class="mt-1 text-yellow-800 dark:text-yellow-200">
- The agent may be offline or experiencing issues. Consider using "Force remove now" below to skip the agent stop and remove the host immediately.
- </p>
- </div>
- </div>
- </div>
- </Show>
- </div>
- </Show>
- <Show when={modalCommandCompleted()}>
- <div class="rounded border border-emerald-200 bg-white p-3 text-xs text-emerald-800 dark:border-emerald-700 dark:bg-emerald-900/20 dark:text-emerald-100">
- <p class="font-medium">
- Agent confirmed the stop. Pulse has already cleaned up everything it controls:
- </p>
- <ul class="mt-2 space-y-1 leading-snug">
- <li>• Terminated the running <code class="font-mono text-[11px]">pulse-agent</code> process</li>
- <li>• Disabled future auto-start (stops the systemd unit or removes the Unraid autostart script if one exists)</li>
- <li>• Cleared the host from the dashboard so new reports won’t appear unexpectedly</li>
- </ul>
- <p class="mt-2">
- The binary remains at <code class="font-mono text-[11px]">/usr/local/bin/pulse-agent</code> for quick reinstalls. Use the uninstall command below if you prefer to remove it too.
- </p>
- </div>
- </Show>
- <Show when={modalCommandFailed() && modalCommand()?.failureReason}>
- <p class="text-xs text-red-600 dark:text-red-300">
- {modalCommand()?.failureReason}
- </p>
- </Show>
- <Show when={modalCommand()}>
- <details class="rounded border border-blue-200 bg-white p-3 text-xs text-gray-700 dark:border-blue-800 dark:bg-blue-900/20 dark:text-blue-200">
- <summary class="flex cursor-pointer items-center justify-between gap-2">
- <span class="font-semibold uppercase tracking-wide text-[11px] text-blue-700 dark:text-blue-300">Behind the scenes</span>
- <code class="rounded bg-blue-100 px-2 py-0.5 font-mono text-[11px] text-blue-700 dark:bg-blue-900/40 dark:text-blue-300">
- {modalCommand()?.id}
- </code>
- </summary>
- <div class="mt-2 space-y-2">
- <ul class="space-y-1">
- <For each={modalCommandProgress()}>
- {(step) => (
- <li
- class={`${step.done || step.active ? 'text-blue-700 dark:text-blue-200' : 'text-gray-500 dark:text-gray-400'} flex items-center gap-2`}
- >
- <span
- class={`relative h-2 w-2 rounded-full ${step.done
- ? 'bg-blue-500'
- : step.active
- ? 'bg-blue-400 animate-pulse'
- : 'bg-gray-300 dark:bg-gray-600'
- } ${modalCommandCompleted() && step.done ? 'after:absolute after:-inset-1 after:rounded-full after:border after:border-emerald-400/40 after:animate-pulse' : ''}`}
- />
- {step.label}
- </li>
- )}
- </For>
- </ul>
- <p class="leading-snug">
- Pulse responds to the agent's <code class="font-mono text-[11px]">/api/agents/docker/report</code> call with a stop command. The agent disables its service, removes
- <code class="font-mono text-[11px]">/boot/config/go.d/pulse-agent.sh</code>, and posts back to
- <code class="font-mono text-[11px]">/api/agents/docker/commands/&lt;id&gt;/ack</code> so Pulse knows it can remove the row.
- </p>
- </div>
- </details>
- </Show>
- </div>
- </div>
- </div>
-
- {/* Force remove option when command times out */}
- <Show when={modalCommandTimedOut()}>
- <div class="rounded-lg border border-orange-200 bg-orange-50 p-4 dark:border-orange-800 dark:bg-orange-900/20">
- <div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
- <div class="flex items-start gap-3">
- <svg class="w-5 h-5 text-orange-600 dark:text-orange-400 mt-0.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
- </svg>
- <div>
- <h4 class="text-sm font-semibold text-orange-900 dark:text-orange-100">Skip waiting and remove now</h4>
- <p class="text-sm text-orange-800 dark:text-orange-200">
- Still waiting after {formatElapsedTime(elapsedSeconds())}. Remove the host entry immediately without waiting for the agent.
- </p>
- </div>
- </div>
- <button
- type="button"
- onClick={handleRemoveHostNow}
- disabled={removeActionLoading() !== null && removeActionLoading() !== 'awaitingCommand'}
- class="self-start rounded bg-orange-600 px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-orange-700 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-orange-500 dark:hover:bg-orange-400 whitespace-nowrap"
- >
- {removeActionLoading() === 'force' ? 'Removing…' : 'Force remove now'}
- </button>
- </div>
- </div>
- </Show>
-
- <Show when={!modalHostIsOnline()}>
- <div class="rounded-lg border border-emerald-200 bg-emerald-50 p-4 dark:border-emerald-800 dark:bg-emerald-900/20">
- <div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
- <div>
- <h4 class="text-sm font-semibold text-emerald-900 dark:text-emerald-100">Host is offline</h4>
- <p class="text-sm text-emerald-800 dark:text-emerald-200">
- Tower stopped reporting. Remove it now to finish the cleanup.
- </p>
- </div>
- <button
- type="button"
- onClick={handleRemoveHostNow}
- disabled={removeActionLoading() !== null && removeActionLoading() !== 'awaitingCommand'}
- class="self-start rounded bg-emerald-600 px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-emerald-700 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-emerald-500 dark:hover:bg-emerald-400"
- >
- {removeActionLoading() === 'force' ? 'Removing…' : 'Remove host'}
- </button>
- </div>
- </div>
- </Show>
-
- <div class="rounded-lg border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-900">
- <button
- type="button"
- onClick={() => setShowAdvancedOptions((prev) => !prev)}
- class="flex w-full items-center justify-between text-sm font-semibold text-gray-900 transition-colors hover:text-blue-600 dark:text-gray-100 dark:hover:text-blue-300"
- >
- <span>Need something else?</span>
- <svg class={`h-4 w-4 transition-transform ${showAdvancedOptions() ? 'rotate-180' : ''}`} fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
- </svg>
- </button>
- <Show when={showAdvancedOptions()}>
- <div class="mt-3 space-y-3 text-sm">
- <div class="flex flex-col gap-2 rounded border border-gray-200 p-3 dark:border-gray-700">
- <div>
- <p class="font-semibold text-gray-900 dark:text-gray-100">Manual uninstall command</p>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Prefer to remove everything manually? Run this full uninstall on <code class="font-mono text-[11px]">{modalHostname()}</code>. It removes the service, startup script, log, and binary.
- </p>
- </div>
- <div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3">
- <code class="flex-1 rounded bg-gray-900 px-3 py-2 font-mono text-xs text-gray-100 dark:bg-gray-950 overflow-x-auto">
- {getUninstallCommand()}
- </code>
- <button
- type="button"
- onClick={async () => {
- const success = await copyToClipboard(getUninstallCommand());
- if (success) {
- setUninstallCommandCopied(true);
- }
- if (typeof window !== 'undefined' && window.showToast) {
- window.showToast(success ? 'success' : 'error', success ? 'Copied!' : 'Failed to copy');
- }
- }}
- class="self-start rounded-lg bg-gray-800 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-gray-700"
- >
- Copy command
- </button>
- </div>
- <Show when={uninstallCommandCopied()}>
- <p class="text-[11px] font-medium text-gray-600 dark:text-gray-300">Command copied to clipboard.</p>
- </Show>
- <p class="text-[11px] text-gray-500 dark:text-gray-400">
- This command stops the agent, removes the systemd service (or Unraid autostart hook), deletes <code class="font-mono text-[11px]">/var/log/pulse-agent.log</code>, and uninstalls the binary. Pulse will notice the host is gone after the next heartbeat (≈2 minutes) and clean up the row automatically.
- </p>
- </div>
- <div class="flex flex-col gap-2 rounded border border-gray-200 p-3 dark:border-gray-700">
- <div>
- <p class="font-semibold text-gray-900 dark:text-gray-100">Force remove immediately</p>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Skips the stop command and removes the entry right away. Any new report from this host will be rejected until you reinstall.
- </p>
- </div>
- <button
- type="button"
- onClick={handleRemoveHostNow}
- disabled={removeActionLoading() !== null && removeActionLoading() !== 'awaitingCommand'}
- class="self-start rounded bg-red-600 px-3 py-1.5 text-xs font-semibold text-white transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-red-500 dark:hover:bg-red-400"
- >
- {removeActionLoading() === 'force' ? 'Removing…' : 'Force remove now'}
- </button>
- </div>
- <div class="flex flex-col gap-2 rounded border border-gray-200 p-3 dark:border-gray-700">
- <div>
- <p class="font-semibold text-gray-900 dark:text-gray-100">Hide the host instead</p>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Remove it from the default view without uninstalling the agent. It will reappear if the agent reports again.
- </p>
- <Show when={modalHostHidden()}>
- <p class="mt-1 text-xs text-blue-700 dark:text-blue-300">Already hidden.</p>
- </Show>
- </div>
- <button
- type="button"
- onClick={handleHideHostFromModal}
- disabled={(removeActionLoading() !== null && removeActionLoading() !== 'awaitingCommand') || modalHostHidden()}
- class="self-start rounded bg-gray-200 px-3 py-1.5 text-xs font-medium text-gray-800 transition-colors hover:bg-gray-300 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600"
- >
- {removeActionLoading() === 'hide' ? 'Hiding...' : modalHostHidden() ? 'Already hidden' : 'Hide host'}
- </button>
- </div>
- </div>
- </Show>
- </div>
- </div>
-
- <div class="mt-6 flex justify-end">
- <button
- type="button"
- onClick={closeRemoveModal}
- class="rounded-lg px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700"
- >
- Close
- </button>
- </div>
- </div>
- </div>
- </Show>
-
- {/* Active container hosts */}
- <Card>
- <div class="space-y-4">
- {/* Pending hosts banner */}
- <Show when={pendingHosts().length > 0}>
- <div class="rounded-lg border border-yellow-200 bg-yellow-50 px-4 py-3 dark:border-yellow-700 dark:bg-yellow-900/30">
- <div class="flex items-start gap-3">
- <svg class="w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
- </svg>
- <div class="flex-1 space-y-3">
- <div>
- <h4 class="text-sm font-semibold text-yellow-900 dark:text-yellow-100">
- Stopping {pendingHosts().length} host{pendingHosts().length !== 1 ? 's' : ''}
- </h4>
- <p class="mt-1 text-sm text-yellow-800 dark:text-yellow-200">
- Pulse has the stop command in flight. You can keep working—these hosts will disappear automatically once the agent shuts down or misses its next heartbeat.
- </p>
- </div>
-
- <div class="space-y-2">
- <For each={pendingHosts()}>
- {(host) => {
- const label = getDisplayName(host);
- const statusInfo = getRemovalStatusInfo(host) ?? {
- label: 'Marked for uninstall; waiting for agent confirmation.',
- tone: 'info' as RemovalStatusTone,
- };
- const status = host.command?.status ?? (host.pendingUninstall ? 'pending' : 'unknown');
- const isOnline = host.status?.toLowerCase() === 'online';
- const lastSeenLabel = host.lastSeen ? formatRelativeTime(host.lastSeen) : 'Awaiting first report';
- const badgeText =
- status === 'completed'
- ? 'Agent stopped'
- : status === 'acknowledged'
- ? 'Acknowledged'
- : status === 'dispatched'
- ? 'Dispatched'
- : status === 'queued'
- ? 'Queued'
- : 'Pending';
-
- return (
- <div class="rounded-lg border border-yellow-200 bg-white/80 p-3 shadow-sm dark:border-yellow-700/40 dark:bg-yellow-900/20">
- <div class="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
- <div>
- <p class="text-sm font-semibold text-gray-900 dark:text-gray-100">{label}</p>
- <p class="text-xs text-gray-500 dark:text-gray-400">{host.hostname || host.id}</p>
- <span class={removalBadgeClassMap[statusInfo.tone]}>{badgeText}</span>
- </div>
- <div class="text-[11px] text-gray-500 dark:text-gray-400 sm:text-right">
- Last seen {lastSeenLabel}
- </div>
- </div>
- <p class={`mt-2 text-xs ${removalTextClassMap[statusInfo.tone]}`}>{statusInfo.label}</p>
- <div class="mt-3 flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3">
- <button
- type="button"
- class="inline-flex items-center justify-center gap-2 rounded bg-blue-600 px-3 py-1.5 text-xs font-semibold text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-blue-500 dark:hover:bg-blue-400"
- onClick={() => openRemoveModal(host)}
- >
- View progress
- </button>
- <Show when={!isOnline || status === 'failed' || status === 'expired'}>
- <button
- type="button"
- class="inline-flex items-center justify-center gap-2 rounded border border-blue-500/40 px-3 py-1.5 text-xs font-medium text-blue-700 transition-colors hover:bg-blue-50 dark:border-blue-400/40 dark:text-blue-200 dark:hover:bg-blue-500/20"
- onClick={() => handleCleanupOfflineHost(host.id, label)}
- disabled={isRemovingHost(host.id)}
- >
- {isRemovingHost(host.id) ? 'Cleaning up…' : 'Force remove now'}
- </button>
- </Show>
- </div>
- </div>
- );
- }}
- </For>
- </div>
- </div>
- </div>
- </div>
- </Show>
-
- <div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
- <div>
- <h3 class="text-base font-semibold text-gray-900 dark:text-gray-100">
- Reporting container hosts ({dockerHosts().length})
- </h3>
- <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
- Use this list to enroll or retire agents. For live health and troubleshooting, open the container monitoring view.
- </p>
- </div>
- <div class="flex flex-wrap items-center justify-end gap-2">
- <a
- href="/containers"
- class="inline-flex items-center gap-2 rounded-lg border border-blue-200 bg-blue-50 px-3 py-1.5 text-xs font-semibold text-blue-700 transition-colors hover:bg-blue-100 dark:border-blue-600/60 dark:bg-blue-900/30 dark:text-blue-200 dark:hover:bg-blue-900/50"
- >
- <svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
- <path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" />
- </svg>
- Open container monitoring
- </a>
- <Show when={hiddenCount() > 0}>
- <button
- type="button"
- onClick={() => setShowHidden(!showHidden())}
- class="px-3 py-1.5 text-xs font-medium rounded transition-colors bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600"
- >
- {showHidden() ? 'Hide' : 'Show'} hidden ({hiddenCount()})
- </button>
- </Show>
- </div>
- </div>
-
- <Show
- when={dockerHosts().length > 0}
- fallback={
- <div class="text-center py-8">
- <div class="text-gray-400 dark:text-gray-500 mb-2">
- <svg class="w-12 h-12 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"
- />
- </svg>
- </div>
- <p class="text-sm text-gray-600 dark:text-gray-400">
- No container agents are currently reporting.
- </p>
- <p class="text-xs text-gray-500 dark:text-gray-500 mt-1">
- Click "Show deployment instructions" above to get started.
- </p>
- </div>
- }
- >
- <div class="overflow-x-auto">
- <table class="w-full text-sm">
- <thead>
- <tr class="border-b border-gray-200 dark:border-gray-700">
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Host</th>
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Status</th>
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Agent &amp; runtime</th>
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Last Seen</th>
- <th class="text-right py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Actions</th>
- </tr>
- </thead>
- <tbody class="divide-y divide-gray-200 dark:divide-gray-700">
- <For each={dockerHosts()}>
- {(host) => {
- const isOnline = host.status?.toLowerCase() === 'online';
- const displayName = getDisplayName(host);
- const commandStatus = host.command?.status ?? null;
- const removalStatusInfo = getRemovalStatusInfo(host);
- const runtimeInfo = resolveHostRuntime(host);
- const commandInProgress =
- commandStatus === 'queued' ||
- commandStatus === 'dispatched' ||
- commandStatus === 'acknowledged';
- const commandFailed = commandStatus === 'failed';
- const commandCompleted = commandStatus === 'completed';
- const offlineActionLabel =
- commandFailed || commandStatus === 'expired'
- ? 'Force remove host'
- : removalStatusInfo?.tone === 'success'
- ? 'Remove host'
- : host.pendingUninstall
- ? 'Skip wait and remove now'
- : 'Remove offline host';
- const tokenRevoked = typeof host.tokenRevokedAt === 'number';
- const tokenRevokedRelative = tokenRevoked ? formatRelativeTime(host.tokenRevokedAt!) : '';
-
- return (
- <tr class={`${isOnline ? 'bg-white dark:bg-gray-900' : 'bg-gray-50 dark:bg-gray-800/50 opacity-60'}`}>
- <td class="py-3 px-4 align-top">
- <Show
- when={editingHostId() === host.id}
- fallback={
- <div class="flex items-center gap-2">
- <div class="flex-1">
- <div class="font-medium text-gray-900 dark:text-gray-100">{displayName}</div>
- <Show when={host.customDisplayName && host.customDisplayName !== host.displayName}>
- <div class="text-xs text-gray-400 dark:text-gray-500">
- Original: {host.displayName || host.hostname}
- </div>
- </Show>
- </div>
- <button
- type="button"
- class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"
- onClick={() => startEditingDisplayName(host)}
- title="Edit display name"
- >
- <svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
- </svg>
- </button>
- </div>
- }
- >
- <div class="flex items-center gap-2">
- <input
- type="text"
- class="flex-1 px-2 py-1 text-sm border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100"
- value={editingDisplayName()}
- onInput={(e) => setEditingDisplayName(e.currentTarget.value)}
- onKeyDown={(e) => {
- if (e.key === 'Enter') {
- saveDisplayName(host.id, displayName);
- } else if (e.key === 'Escape') {
- cancelEditingDisplayName();
- }
- }}
- placeholder="Custom display name"
- disabled={savingDisplayName()}
- />
- <button
- type="button"
- class="text-green-600 hover:text-green-700 disabled:opacity-50"
- onClick={() => saveDisplayName(host.id, displayName)}
- disabled={savingDisplayName()}
- title="Save"
- >
- <svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
- </svg>
- </button>
- <button
- type="button"
- class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 disabled:opacity-50"
- onClick={cancelEditingDisplayName}
- disabled={savingDisplayName()}
- title="Cancel"
- >
- <svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
- </svg>
- </button>
- </div>
- </Show>
- <div class="text-xs text-gray-500 dark:text-gray-400">{host.hostname}</div>
- <div class="mt-1 text-[10px] uppercase tracking-wide">
- <span
- class={`inline-flex items-center rounded-full px-2 py-0.5 font-semibold ${runtimeInfo.badgeClass}`}
- title={runtimeInfo.raw || runtimeInfo.label}
- >
- {runtimeInfo.label}
- </span>
- </div>
- <Show when={host.os || host.architecture}>
- <div class="mt-1 text-xs text-gray-400 dark:text-gray-500">
- {host.os}
- <Show when={host.os && host.architecture}>
- <span class="mx-1">•</span>
- </Show>
- {host.architecture}
- </div>
- </Show>
- <Show when={host.hidden}>
- <span class="mt-2 inline-flex items-center rounded-full bg-gray-200 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-gray-700 dark:bg-gray-700 dark:text-gray-200">
- Hidden
- </span>
- </Show>
- <Show when={tokenRevoked}>
- <div class="mt-2 text-xs text-amber-600 dark:text-amber-300">
- Token revoked {tokenRevokedRelative}
- </div>
- </Show>
- </td>
- <td class="py-3 px-4 align-top">
- <div class="flex flex-wrap items-center gap-2">
- <span
- class={`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${isOnline
- ? 'bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300'
- : 'bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300'
- }`}
- >
- {host.status || 'unknown'}
- </span>
- <Show when={commandInProgress}>
- <span class="inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-yellow-100 text-yellow-700 dark:bg-yellow-900/40 dark:text-yellow-300">
- <svg class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
- </svg>
- Stopping
- </span>
- </Show>
- <Show when={commandFailed}>
- <span class="inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300">
- <svg class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 5.636l-12.728 12.728M5.636 5.636l12.728 12.728" />
- </svg>
- Failed
- </span>
- </Show>
- <Show when={commandCompleted}>
- <span class="inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-300">
- <svg class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
- </svg>
- Stopped
- </span>
- </Show>
- </div>
- <Show when={removalStatusInfo}>
- {(info) => {
- const details = info();
- return (
- <div class={`mt-2 text-xs ${removalTextClassMap[details.tone]}`}>
- {details.label}
- </div>
- );
- }}
- </Show>
- </td>
- <td class="py-3 px-4 align-top">
- <div class="text-sm font-medium text-gray-900 dark:text-gray-100">
- {describeRuntime(host)}
- </div>
- <div class="text-xs text-gray-500 dark:text-gray-400">
- Agent {host.agentVersion ? `v${host.agentVersion}` : 'not reporting'}
- <Show when={host.intervalSeconds}>
- <span> (every {host.intervalSeconds}s)</span>
- </Show>
- </div>
- </td>
- <td class="py-3 px-4 align-top">
- <div class="text-gray-900 dark:text-gray-100">
- {host.lastSeen ? formatRelativeTime(host.lastSeen) : '—'}
- </div>
- <div class="text-xs text-gray-500 dark:text-gray-400">
- {host.lastSeen ? formatAbsoluteTime(host.lastSeen) : 'Awaiting first report'}
- </div>
- </td>
- <td class="py-3 px-4 text-right align-top">
- <Show
- when={host.hidden}
- fallback={
- <>
- <Show when={commandInProgress || commandCompleted}>
- <button
- type="button"
- class="text-xs font-semibold text-blue-600 disabled:cursor-not-allowed disabled:opacity-50"
- disabled
- >
- {commandCompleted ? 'Cleaning up…' : 'Stopping…'}
- </button>
- </Show>
- <Show
- when={commandFailed}
- fallback={
- <Show
- when={!isOnline}
- fallback={
- <button
- type="button"
- class="text-xs font-semibold text-red-600 hover:text-red-700 disabled:cursor-not-allowed disabled:opacity-50"
- onClick={() => openRemoveModal(host)}
- disabled={isRemovingHost(host.id)}
- >
- {isRemovingHost(host.id) ? 'Working…' : 'Remove'}
- </button>
- }
- >
- <button
- type="button"
- class="text-xs font-semibold text-blue-600 hover:text-blue-700 disabled:cursor-not-allowed disabled:opacity-50"
- onClick={() => handleCleanupOfflineHost(host.id, displayName)}
- disabled={isRemovingHost(host.id)}
- >
- {isRemovingHost(host.id) ? 'Cleaning up…' : offlineActionLabel}
- </button>
- </Show>
- }
- >
- <button
- type="button"
- class="text-xs font-semibold text-red-600 hover:text-red-700 disabled:cursor-not-allowed disabled:opacity-50"
- onClick={() => handleCleanupOfflineHost(host.id, displayName)}
- disabled={isRemovingHost(host.id)}
- >
- {isRemovingHost(host.id) ? 'Removing…' : 'Force remove'}
- </button>
- </Show>
- </>
- }
- >
- <button
- type="button"
- class="text-xs font-semibold text-blue-600 hover:text-blue-700 disabled:cursor-not-allowed disabled:opacity-50"
- onClick={() => handleUnhideHost(host.id, displayName)}
- disabled={isRemovingHost(host.id)}
- >
- {isRemovingHost(host.id) ? 'Unhiding…' : 'Unhide'}
- </button>
- </Show>
- </td>
- </tr>
- );
- }}
- </For>
- </tbody>
- </table>
- </div>
- </Show>
- </div>
- </Card>
- </div>
- );
-};
diff --git a/frontend-modern/src/components/Settings/HostAgents.tsx b/frontend-modern/src/components/Settings/HostAgents.tsx
deleted file mode 100644
index ce0ea222f3..0000000000
--- a/frontend-modern/src/components/Settings/HostAgents.tsx
+++ /dev/null
@@ -1,1283 +0,0 @@
-import { type Component, For, Show, createEffect, createMemo, createSignal, onCleanup, onMount } from 'solid-js';
-import type { JSX } from 'solid-js';
-import { useWebSocket } from '@/App';
-import type { Host, HostLookupResponse } from '@/types/api';
-import { Card } from '@/components/shared/Card';
-import { formatBytes, formatRelativeTime, formatUptime, formatAbsoluteTime } from '@/utils/format';
-import { copyToClipboard } from '@/utils/clipboard';
-import { getPulseBaseUrl } from '@/utils/url';
-import { notificationStore } from '@/stores/notifications';
-import { HOST_AGENT_SCOPE } from '@/constants/apiScopes';
-import type { SecurityStatus } from '@/types/config';
-import type { APITokenRecord } from '@/api/security';
-import { SecurityAPI } from '@/api/security';
-import { MonitoringAPI } from '@/api/monitoring';
-import { logger } from '@/utils/logger';
-
-const TOKEN_PLACEHOLDER = '<api-token>';
-const pulseUrl = () => getPulseBaseUrl();
-
-const buildDefaultTokenName = () => {
- const now = new Date();
- const iso = now.toISOString().slice(0, 16); // YYYY-MM-DDTHH:MM
- const stamp = iso.replace('T', ' ').replace(/:/g, '-');
- return `Host agent ${stamp}`;
-};
-
-type HostAgentPlatform = 'linux' | 'macos' | 'windows';
-
-const commandsByPlatform: Record<
- HostAgentPlatform,
- {
- title: string;
- description: string;
- snippets: { label: string; command: string; note?: string | JSX.Element }[];
- }
-> = {
- linux: {
- title: 'Install on Linux',
- description:
- 'The unified installer downloads the agent binary and configures it as a systemd service.',
- snippets: [
- {
- label: 'Install with systemd',
- command: `curl -fsSL ${pulseUrl()}/install.sh | bash -s -- --url ${pulseUrl()} --token ${TOKEN_PLACEHOLDER} --interval 30s`,
- note: (
- <span>
- Automatically installs to <code>/usr/local/bin/pulse-agent</code> and creates <code>/etc/systemd/system/pulse-agent.service</code>.
- </span>
- ),
- },
- ],
- },
- macos: {
- title: 'Install on macOS',
- description:
- 'The unified installer downloads the universal binary and sets up a launchd service for background monitoring.',
- snippets: [
- {
- label: 'Install with launchd',
- command: `curl -fsSL ${pulseUrl()}/install.sh | bash -s -- --url ${pulseUrl()} --token ${TOKEN_PLACEHOLDER} --interval 30s`,
- note: (
- <span>
- Creates <code>/Library/LaunchDaemons/com.pulse.agent.plist</code> and starts the agent automatically.
- </span>
- ),
- },
- ],
- },
- windows: {
- title: 'Install on Windows',
- description:
- 'Run the PowerShell script to install and configure the unified agent as a Windows service with automatic startup.',
- snippets: [
- {
- label: 'Install as Windows Service (PowerShell)',
- command: `irm ${pulseUrl()}/install.ps1 | iex`,
- note: (
- <span>
- Run in PowerShell as Administrator. The script will prompt for the Pulse URL and API token, download the agent binary, and install it as a Windows service with automatic startup.
- </span>
- ),
- },
- {
- label: 'Install with parameters (PowerShell)',
- command: `$env:PULSE_URL="${pulseUrl()}"; $env:PULSE_TOKEN="${TOKEN_PLACEHOLDER}"; irm ${pulseUrl()}/install.ps1 | iex`,
- note: (
- <span>
- Non-interactive installation. Set environment variables before running to skip prompts.
- </span>
- ),
- },
- ],
- },
-};
-
-const computeHostStaleness = (host: Host) => {
- const intervalSeconds = host.intervalSeconds && host.intervalSeconds > 0 ? host.intervalSeconds : 30;
- const staleThresholdMs = Math.max(intervalSeconds * 1000 * 3, 60_000);
- const lastSeenValue =
- typeof host.lastSeen === 'number'
- ? host.lastSeen
- : Number.isFinite(Number(host.lastSeen))
- ? Number(host.lastSeen)
- : NaN;
- const lastSeenMs = Number.isFinite(lastSeenValue) ? lastSeenValue : null;
- const isStale = lastSeenMs === null ? true : Date.now() - lastSeenMs >= staleThresholdMs;
-
- return {
- isStale,
- lastSeenMs,
- staleThresholdMs,
- };
-};
-
-export const HostAgents: Component = () => {
- const { state } = useWebSocket();
-
- let hasLoggedSecurityStatusError = false;
-
- const [securityStatus, setSecurityStatus] = createSignal<SecurityStatus | null>(null);
- const [latestRecord, setLatestRecord] = createSignal<APITokenRecord | null>(null);
- const [tokenName, setTokenName] = createSignal('');
- const [confirmedNoToken, setConfirmedNoToken] = createSignal(false);
- const [currentToken, setCurrentToken] = createSignal<string | null>(null);
- const [isGeneratingToken, setIsGeneratingToken] = createSignal(false);
- const [lookupValue, setLookupValue] = createSignal('');
- const [lookupResult, setLookupResult] = createSignal<HostLookupResponse | null>(null);
- const [lookupError, setLookupError] = createSignal<string | null>(null);
- const [lookupLoading, setLookupLoading] = createSignal(false);
- const [highlightedHostId, setHighlightedHostId] = createSignal<string | null>(null);
- let highlightTimer: ReturnType<typeof setTimeout> | null = null;
- const [showRemoveModal, setShowRemoveModal] = createSignal(false);
- const [hostToRemoveId, setHostToRemoveId] = createSignal<string | null>(null);
- const [removeActionLoading, setRemoveActionLoading] = createSignal<'remove' | null>(null);
- const [uninstallCommandCopied, setUninstallCommandCopied] = createSignal(false);
- const [uninstallCommandCopiedAt, setUninstallCommandCopiedAt] = createSignal<number | null>(null);
- const [hostRemovalCountdownSeconds, setHostRemovalCountdownSeconds] = createSignal<number | null>(null);
- const [uninstallConfirmed, setUninstallConfirmed] = createSignal(false);
-
- createEffect(() => {
- if (requiresToken()) {
- setConfirmedNoToken(false);
- } else {
- setCurrentToken(null);
- setLatestRecord(null);
- }
- });
-
-
- const allHosts = createMemo(() => {
- const list = state.hosts ?? [];
- return [...list].sort((a, b) => (a.hostname || '').localeCompare(b.hostname || ''));
- });
-
- const hostTokenUsage = createMemo(() => {
- type UsageHost = { id: string; label: string };
- const usage = new Map<string, { count: number; hosts: UsageHost[] }>();
- for (const host of allHosts()) {
- const tokenId = host.tokenId;
- if (!tokenId) continue;
- const label = host.displayName?.trim() || host.hostname || host.id;
- const prev = usage.get(tokenId);
- if (prev) {
- usage.set(tokenId, { count: prev.count + 1, hosts: [...prev.hosts, { id: host.id, label }] });
- } else {
- usage.set(tokenId, { count: 1, hosts: [{ id: host.id, label }] });
- }
- }
- return usage;
- });
-
- const reusedTokens = createMemo(() => {
- const entries: { tokenId: string; hosts: { id: string; label: string }[] }[] = [];
- hostTokenUsage().forEach((value, tokenId) => {
- if (value.count > 1) {
- entries.push({ tokenId, hosts: value.hosts });
- }
- });
- return entries;
- });
-
- const renderTags = (host: Host) => {
- const tags = host.tags ?? [];
- if (!tags.length) return '—';
- return tags.join(', ');
- };
-
- const commandSections = createMemo(() =>
- Object.entries(commandsByPlatform).map(([platform, meta]) => ({
- platform: platform as HostAgentPlatform,
- ...meta,
- })),
- );
-
- const connectedFromStatus = (status: string | undefined | null) => {
- if (!status) return false;
- const value = status.toLowerCase();
- return value === 'online' || value === 'running' || value === 'healthy';
- };
-
- const hostToRemove = createMemo(() => {
- const id = hostToRemoveId();
- if (!id) return null;
- return allHosts().find((host) => host.id === id) ?? null;
- });
-
- const hostRemovalDisplayName = () => {
- const host = hostToRemove();
- return host ? host.displayName || host.hostname || host.id : '';
- };
-
- const hostRemovalPlatform = createMemo(() => hostToRemove()?.platform?.toLowerCase() || '');
- const hostRemovalStatus = createMemo(() => {
- const host = hostToRemove();
- return (host?.status || 'unknown').toLowerCase();
- });
-
- const hostRemovalStatusLabel = () => hostToRemove()?.status || 'unknown';
-
- const hostRemovalIsOnline = createMemo(() => {
- const status = hostRemovalStatus();
- return status === 'online' || status === 'running' || status === 'healthy';
- });
-
- const hostRemovalStaleness = createMemo(() => {
- const host = hostToRemove();
- if (!host) {
- return { isStale: false, lastSeenMs: null as number | null, staleThresholdMs: 90_000 };
- }
- return computeHostStaleness(host);
- });
-
- const hostRemovalIsStale = createMemo(() => hostRemovalStaleness().isStale);
-
- const hostRemovalLastSeen = createMemo(() => {
- const { lastSeenMs } = hostRemovalStaleness();
- if (!lastSeenMs) return null;
- return {
- relative: formatRelativeTime(lastSeenMs),
- absolute: formatAbsoluteTime(lastSeenMs),
- };
- });
-
- const hostRemovalStaleThresholdSeconds = createMemo(() => {
- const threshold = hostRemovalStaleness().staleThresholdMs;
- return Math.max(Math.round(threshold / 1000), 0);
- });
-
- const hostRemovalUninstallCommand = createMemo(() => getHostUninstallCommand(hostToRemove()));
-
- const hostRemovalUninstallNote = () => {
- const platform = hostRemovalPlatform();
- if (platform === 'macos' || platform === 'darwin' || platform === 'mac') {
- return 'Unloads the launch agent, removes the plist, deletes the binary, and clears the local log.';
- }
- if (platform === 'windows' || platform === 'win32' || platform === 'windows_nt') {
- return 'Stops the Windows service, removes it, and deletes the installed binary and log. Run from an elevated PowerShell window.';
- }
- return 'Stops the agent, removes the systemd unit, deletes the binary, and reloads systemd.';
- };
-
- const formatCountdown = (seconds: number | null) => {
- if (seconds === null || seconds < 0) return null;
- if (seconds === 0) return 'any moment now';
- const mins = Math.floor(seconds / 60);
- const secs = seconds % 60;
- if (mins <= 0) {
- return `${secs}s`;
- }
- if (secs === 0) {
- return `${mins}m`;
- }
- return `${mins}m ${secs}s`;
- };
-
- const countdownLabel = createMemo(() => formatCountdown(hostRemovalCountdownSeconds()));
-
- const canRemoveHost = createMemo(() => uninstallCommandCopied() && uninstallConfirmed());
-
- const openRemoveModal = (host: Host) => {
- setHostToRemoveId(host.id);
- setShowRemoveModal(true);
- setRemoveActionLoading(null);
- setUninstallCommandCopied(false);
- setUninstallCommandCopiedAt(null);
- setHostRemovalCountdownSeconds(null);
- setUninstallConfirmed(false);
- };
-
- const closeRemoveModal = () => {
- setShowRemoveModal(false);
- setHostToRemoveId(null);
- setRemoveActionLoading(null);
- setUninstallCommandCopied(false);
- setUninstallCommandCopiedAt(null);
- setHostRemovalCountdownSeconds(null);
- setUninstallConfirmed(false);
- };
-
- const performHostRemoval = async () => {
- const host = hostToRemove();
- if (!host || removeActionLoading()) return;
-
- setRemoveActionLoading('remove');
- const displayName = host.displayName || host.hostname || host.id;
-
- try {
- await MonitoringAPI.deleteHostAgent(host.id);
- notificationStore.success(`Host "${displayName}" removed`, 4000);
- closeRemoveModal();
- } catch (error) {
- logger.error('Failed to remove host agent', error);
- const message = error instanceof Error ? error.message : 'Failed to remove host. Please try again.';
- notificationStore.error(message, 6000);
- } finally {
- setRemoveActionLoading(null);
- }
- };
-
- const handleRemoveHost = () => {
- void performHostRemoval();
- };
-
- createEffect(() => {
- const current = lookupResult();
- if (!current) return;
-
- const targetId = current.host.id;
- const targetHostname = current.host.hostname;
- const hosts = allHosts();
- const match = hosts.find((host) => host.id === targetId || host.hostname === targetHostname);
- if (!match) return;
-
- if (highlightTimer) {
- clearTimeout(highlightTimer);
- highlightTimer = null;
- }
-
- setHighlightedHostId(match.id);
- highlightTimer = setTimeout(() => {
- setHighlightedHostId(null);
- highlightTimer = null;
- }, 10_000);
-
- const updated = {
- success: true,
- host: {
- id: match.id,
- hostname: match.hostname,
- displayName: match.displayName,
- status: match.status,
- connected: connectedFromStatus(match.status),
- lastSeen: match.lastSeen ?? Date.now(),
- agentVersion: match.agentVersion ?? current.host.agentVersion,
- },
- } satisfies HostLookupResponse;
-
- const currentHost = current.host;
- if (
- currentHost.status === updated.host.status &&
- currentHost.connected === updated.host.connected &&
- currentHost.lastSeen === updated.host.lastSeen &&
- currentHost.agentVersion === updated.host.agentVersion &&
- (currentHost.displayName || '') === (updated.host.displayName || '') &&
- currentHost.hostname === updated.host.hostname
- ) {
- return;
- }
-
- setLookupResult(updated);
- setLookupError(null);
- });
-
- createEffect(() => {
- if (!showRemoveModal()) return;
- const id = hostToRemoveId();
- const host = hostToRemove();
- if (id && !host) {
- closeRemoveModal();
- }
- });
-
- createEffect(() => {
- if (!showRemoveModal()) {
- setHostRemovalCountdownSeconds(null);
- return;
- }
-
- const updateCountdown = () => {
- const host = hostToRemove();
- if (!host) {
- setHostRemovalCountdownSeconds(null);
- return;
- }
-
- const { lastSeenMs, staleThresholdMs } = computeHostStaleness(host);
- if (!lastSeenMs) {
- setHostRemovalCountdownSeconds(null);
- return;
- }
-
- const elapsed = Date.now() - lastSeenMs;
- const remaining = staleThresholdMs - elapsed;
- setHostRemovalCountdownSeconds(remaining > 0 ? Math.ceil(remaining / 1000) : 0);
- };
-
- updateCountdown();
- const interval = setInterval(updateCountdown, 1000);
-
- return () => {
- clearInterval(interval);
- setHostRemovalCountdownSeconds(null);
- };
- });
-
- onMount(() => {
- if (typeof window === 'undefined') {
- return;
- }
-
- const fetchSecurityStatus = async () => {
- try {
- const response = await fetch('/api/security/status', { credentials: 'include' });
- if (response.ok) {
- const data = (await response.json()) as SecurityStatus;
- setSecurityStatus(data);
- }
- } catch (err) {
- if (!hasLoggedSecurityStatusError) {
- hasLoggedSecurityStatusError = true;
- logger.error('Failed to load security status', err);
- }
- }
- };
- fetchSecurityStatus();
- });
-
-
- const requiresToken = () => {
- const status = securityStatus();
- if (status) {
- return status.requiresAuth || status.apiTokenConfigured;
- }
- return true;
- };
-
- onCleanup(() => {
- if (highlightTimer) {
- clearTimeout(highlightTimer);
- highlightTimer = null;
- }
- });
-
- const hasToken = () => Boolean(currentToken());
- const commandsUnlocked = () => (requiresToken() ? hasToken() : hasToken() || confirmedNoToken());
-
- const acknowledgeNoToken = () => {
- if (requiresToken()) {
- notificationStore.info('Generate or select a token before continuing.', 4000);
- return;
- }
- setCurrentToken(null);
- setLatestRecord(null);
- setConfirmedNoToken(true);
- notificationStore.success('Confirmed install commands without an API token.', 3500);
- };
-
- const handleGenerateToken = async () => {
- if (isGeneratingToken()) return;
-
- setIsGeneratingToken(true);
- try {
- const desiredName = tokenName().trim() || buildDefaultTokenName();
- const { token, record } = await SecurityAPI.createToken(desiredName, [HOST_AGENT_SCOPE]);
-
- setCurrentToken(token);
- setLatestRecord(record);
- setTokenName('');
- setConfirmedNoToken(false);
- notificationStore.success('Token generated and inserted into the command below.', 4000);
- } catch (err) {
- logger.error('Failed to generate host agent token', err);
- notificationStore.error('Failed to generate host agent token. Confirm you are signed in as an administrator.', 6000);
- } finally {
- setIsGeneratingToken(false);
- }
- };
-
- const resolvedToken = () => {
- if (requiresToken()) {
- return currentToken() || TOKEN_PLACEHOLDER;
- }
- return currentToken() || 'disabled';
- };
-
- const handleLookup = async () => {
- const query = lookupValue().trim();
- setLookupError(null);
-
- if (!query) {
- setLookupResult(null);
- setLookupError('Enter a hostname or host ID to check.');
- return;
- }
-
- setLookupLoading(true);
- try {
- const result = await MonitoringAPI.lookupHost({ id: query, hostname: query });
- if (!result) {
- setLookupResult(null);
- setLookupError(`No host has reported with "${query}" yet. Try again in a few seconds.`);
- } else {
- setLookupResult(result);
- setLookupError(null);
- }
- } catch (err) {
- const message = err instanceof Error ? err.message : 'Host lookup failed.';
- setLookupResult(null);
- setLookupError(message);
- } finally {
- setLookupLoading(false);
- }
- };
-
- const getSystemdServiceUnit = () => `[Unit]
-Description=Pulse Host Agent
-After=network-online.target
-Wants=network-online.target
-
-[Service]
-Type=simple
-ExecStart=/usr/local/bin/pulse-host-agent --url ${pulseUrl()} --token ${resolvedToken()} --interval 30s
-Restart=always
-RestartSec=5s
-User=root
-
-[Install]
-WantedBy=multi-user.target`;
-
- function getManualUninstallCommand(): string {
- return `sudo systemctl stop pulse-agent && \\
-sudo systemctl disable pulse-agent && \\
-sudo rm -f /etc/systemd/system/pulse-agent.service && \\
-sudo rm -f /usr/local/bin/pulse-agent && \\
-sudo systemctl daemon-reload`;
- }
-
- function getHostUninstallCommand(host: Host | null): string {
- const platform = host?.platform?.toLowerCase();
- if (platform === 'macos' || platform === 'darwin' || platform === 'mac') {
- return `launchctl unload /Library/LaunchDaemons/com.pulse.agent.plist >/dev/null 2>&1 || true && \\
-rm -f /Library/LaunchDaemons/com.pulse.agent.plist && \\
-sudo rm -f /usr/local/bin/pulse-agent && \\
-rm -f /var/log/pulse-agent.log`;
- }
- if (platform === 'windows' || platform === 'win32' || platform === 'windows_nt') {
- return `Stop-Service -Name PulseAgent -ErrorAction SilentlyContinue; \\
-sc.exe delete PulseAgent; \\
-Remove-Item 'C:\\\\Program Files\\\\Pulse\\\\pulse-agent.exe' -Force -ErrorAction SilentlyContinue; \\
-Remove-Item '$env:ProgramData\\\\Pulse\\\\pulse-agent.log' -Force -ErrorAction SilentlyContinue`;
- }
- return getManualUninstallCommand();
- }
-
- return (
- <div class="space-y-6">
- <Card padding="lg" class="space-y-5">
- <div class="space-y-1">
- <h3 class="text-base font-semibold text-gray-900 dark:text-gray-100">Add a host agent</h3>
- <p class="text-sm text-gray-600 dark:text-gray-400">
- Generate a token once, then run the matching command on Linux, macOS, or Windows to register new hosts.
- </p>
- </div>
-
- <div class="space-y-5">
- <Show when={requiresToken()}>
- <div class="space-y-3">
- <div class="space-y-1">
- <p class="text-sm font-semibold text-gray-900 dark:text-gray-100">Generate API token</p>
- <p class="text-sm text-gray-600 dark:text-gray-400">
- Create a fresh token scoped to <code>{HOST_AGENT_SCOPE}</code>.
- </p>
- </div>
-
- <div class="flex gap-2">
- <input
- type="text"
- value={tokenName()}
- onInput={(event) => setTokenName(event.currentTarget.value)}
- onKeyDown={(event) => {
- if (event.key === 'Enter' && !isGeneratingToken()) {
- handleGenerateToken();
- }
- }}
- placeholder="Token name (optional)"
- class="flex-1 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-100 dark:focus:border-blue-400 dark:focus:ring-blue-900/60"
- />
- <button
- type="button"
- onClick={handleGenerateToken}
- disabled={isGeneratingToken()}
- class="inline-flex items-center justify-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-60"
- >
- {isGeneratingToken() ? 'Generating…' : hasToken() ? 'Generate another' : 'Generate token'}
- </button>
- </div>
-
- <Show when={latestRecord()}>
- <div class="flex items-center gap-2 rounded-lg border border-blue-200 bg-blue-50 px-4 py-2 text-xs text-blue-800 dark:border-blue-800 dark:bg-blue-900/20 dark:text-blue-200">
- <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
- <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
- </svg>
- <span>
- Token <strong>{latestRecord()?.name}</strong> created ({latestRecord()?.prefix}…{latestRecord()?.suffix}). Commands below now include this credential.
- </span>
- </div>
- </Show>
-
- </div>
- </Show>
-
- <Show when={!requiresToken()}>
- <div class="space-y-3">
- <div class="rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800 dark:border-amber-700 dark:bg-amber-900/30 dark:text-amber-200">
- Tokens are optional on this Pulse instance. Confirm to generate commands without embedding a token.
- </div>
- <button
- type="button"
- onClick={acknowledgeNoToken}
- disabled={confirmedNoToken()}
- class={`inline-flex items-center justify-center rounded-md px-4 py-2 text-sm font-medium transition-colors ${confirmedNoToken()
- ? 'bg-green-600 text-white cursor-default'
- : 'bg-gray-900 text-white hover:bg-black dark:bg-gray-100 dark:text-gray-900 dark:hover:bg-white'
- }`}
- >
- {confirmedNoToken() ? 'No token confirmed' : 'Confirm without token'}
- </button>
- </div>
- </Show>
-
- <Show when={commandsUnlocked()}>
- <div class="space-y-3">
- <h4 class="text-sm font-semibold text-gray-900 dark:text-gray-100">Installation commands</h4>
- <p class="text-xs text-gray-500 dark:text-gray-400">
- Copy the command for the platform you are deploying.
- </p>
- <div class="space-y-4">
- <For each={commandSections()}>
- {(section) => (
- <div class="space-y-3 rounded-lg border border-gray-200 dark:border-gray-700 p-4">
- <div class="space-y-1">
- <h5 class="text-sm font-semibold text-gray-900 dark:text-gray-100">{section.title}</h5>
- <p class="text-xs text-gray-500 dark:text-gray-400">{section.description}</p>
- </div>
- <div class="space-y-3">
- <For each={section.snippets}>
- {(snippet) => {
- const copyCommand = () =>
- snippet.command.replace(TOKEN_PLACEHOLDER, resolvedToken());
-
- return (
- <div class="space-y-2">
- <div class="flex items-center justify-between gap-3">
- <h6 class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
- {snippet.label}
- </h6>
- <button
- type="button"
- onClick={async () => {
- const success = await copyToClipboard(copyCommand());
- if (typeof window !== 'undefined' && window.showToast) {
- window.showToast(success ? 'success' : 'error', success ? 'Copied!' : 'Failed to copy');
- }
- }}
- class="px-3 py-1.5 text-xs font-medium rounded-lg transition-colors bg-blue-600 text-white hover:bg-blue-700"
- >
- Copy command
- </button>
- </div>
- <pre class="overflow-x-auto rounded-md bg-gray-900/90 p-3 text-xs text-gray-100">
- <code>{copyCommand()}</code>
- </pre>
- <Show when={snippet.note}>
- <p class="text-xs text-gray-500 dark:text-gray-400">{snippet.note}</p>
- </Show>
- </div>
- );
- }}
- </For>
- </div>
- </div>
- )}
- </For>
- </div>
- <div class="space-y-3 rounded-lg border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-900 dark:border-blue-800 dark:bg-blue-900/20 dark:text-blue-100">
- <div class="flex items-center justify-between gap-3">
- <h5 class="text-sm font-semibold">Check installation status</h5>
- <button
- type="button"
- onClick={handleLookup}
- disabled={lookupLoading()}
- class="rounded-lg bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-60"
- >
- {lookupLoading() ? 'Checking…' : 'Check status'}
- </button>
- </div>
- <p class="text-xs text-blue-800 dark:text-blue-200">
- Enter the hostname (or host ID) from the machine you just installed. Pulse returns the latest status instantly.
- </p>
- <div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3">
- <input
- type="text"
- value={lookupValue()}
- onInput={(event) => {
- setLookupValue(event.currentTarget.value);
- setLookupError(null);
- setLookupResult(null);
- }}
- onKeyDown={(event) => {
- if (event.key === 'Enter') {
- event.preventDefault();
- void handleLookup();
- }
- }}
- placeholder="Hostname or host ID"
- class="flex-1 rounded-lg border border-blue-200 bg-white px-3 py-2 text-sm text-blue-900 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-blue-700 dark:bg-blue-900 dark:text-blue-100 dark:focus:border-blue-300 dark:focus:ring-blue-800/60"
- />
- </div>
- <Show when={lookupError()}>
- <p class="text-xs font-medium text-red-600 dark:text-red-300">{lookupError()}</p>
- </Show>
- <Show when={lookupResult()}>
- {(result) => {
- const host = () => result().host;
- const statusBadgeClasses = () =>
- host().connected
- ? 'bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300'
- : 'bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-200';
- return (
- <div class="space-y-1 rounded-lg border border-blue-200 bg-white px-3 py-2 text-xs text-blue-900 dark:border-blue-700 dark:bg-blue-900/40 dark:text-blue-100">
- <div class="flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
- <div class="text-sm font-semibold">
- {host().displayName || host().hostname}
- </div>
- <div class="flex items-center gap-2">
- <span class={`inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-semibold ${statusBadgeClasses()}`}>
- {host().connected ? 'Connected' : 'Not reporting yet'}
- </span>
- <span class="inline-flex items-center rounded-full bg-blue-100 px-2 py-0.5 text-[11px] font-medium text-blue-700 dark:bg-blue-900/60 dark:text-blue-200">
- {host().status || 'unknown'}
- </span>
- </div>
- </div>
- <div>
- Last seen {formatRelativeTime(host().lastSeen)} ({formatAbsoluteTime(host().lastSeen)})
- </div>
- <Show when={host().agentVersion}>
- <div class="text-xs text-blue-700 dark:text-blue-200">
- Agent version {host().agentVersion}
- </div>
- </Show>
- </div>
- );
- }}
- </Show>
- </div>
- <details class="rounded-lg border border-gray-200 bg-gray-50 px-4 py-3 text-sm text-gray-700 dark:border-gray-700 dark:bg-gray-800/50 dark:text-gray-300">
- <summary class="cursor-pointer text-sm font-medium text-gray-900 dark:text-gray-100">
- Advanced options (manual install & uninstall)
- </summary>
- <div class="mt-3 space-y-4">
- <div class="space-y-3 rounded-lg border border-gray-200 bg-white p-3 text-xs dark:border-gray-700 dark:bg-gray-900">
- <p class="font-medium text-gray-900 dark:text-gray-100">Manual Linux install</p>
- <p class="text-xs text-gray-500 dark:text-gray-400">
- Build the agent from source and manage the service yourself instead of using the helper script.
- </p>
- <p class="font-medium text-gray-900 dark:text-gray-100">1. Build the binary</p>
- <div class="rounded bg-gray-900 p-3 font-mono text-xs text-gray-100 dark:bg-gray-950">
- <code>
- cd /opt/pulse
- <br />
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pulse-agent ./cmd/pulse-agent
- </code>
- </div>
- <p class="font-medium text-gray-900 dark:text-gray-100">2. Copy to host</p>
- <div class="rounded bg-gray-900 p-3 font-mono text-xs text-gray-100 dark:bg-gray-950">
- <code>
- scp pulse-agent user@host:/usr/local/bin/
- <br />
- ssh user@host sudo chmod +x /usr/local/bin/pulse-agent
- </code>
- </div>
- <p class="font-medium text-gray-900 dark:text-gray-100">3. Systemd service template</p>
- <div class="relative">
- <button
- type="button"
- onClick={async () => {
- const success = await copyToClipboard(getSystemdServiceUnit());
- if (typeof window !== 'undefined' && window.showToast) {
- window.showToast(success ? 'success' : 'error', success ? 'Copied to clipboard' : 'Failed to copy to clipboard');
- }
- }}
- class="absolute right-2 top-2 rounded-lg bg-gray-700 px-3 py-1.5 text-xs font-medium text-gray-200 transition-colors hover:bg-gray-600"
- >
- Copy
- </button>
- <div class="rounded bg-gray-900 p-3 font-mono text-xs text-gray-100 dark:bg-gray-950 overflow-x-auto">
- <pre>{getSystemdServiceUnit()}</pre>
- </div>
- </div>
- <p class="font-medium text-gray-900 dark:text-gray-100">4. Enable & start</p>
- <div class="rounded bg-gray-900 p-3 font-mono text-xs text-gray-100 dark:bg-gray-950">
- <code>
- sudo systemctl daemon-reload
- <br />
- sudo systemctl enable --now pulse-host-agent
- </code>
- </div>
- </div>
- <div>
- <p class="text-xs uppercase tracking-wide text-gray-500 dark:text-gray-400">Manual uninstall</p>
- <div class="mt-2 flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3">
- <code class="flex-1 break-all rounded bg-gray-900 px-3 py-2 font-mono text-xs text-gray-100 dark:bg-gray-950">
- {getManualUninstallCommand()}
- </code>
- <button
- type="button"
- onClick={async () => {
- const success = await copyToClipboard(getManualUninstallCommand());
- if (typeof window !== 'undefined' && window.showToast) {
- window.showToast(success ? 'success' : 'error', success ? 'Copied to clipboard' : 'Failed to copy to clipboard');
- }
- }}
- class="self-start rounded-lg bg-red-50 px-3 py-1.5 text-xs font-medium text-red-700 transition-colors hover:bg-red-100 dark:bg-red-900/30 dark:text-red-300 dark:hover:bg-red-900/50"
- >
- Copy
- </button>
- </div>
- <p class="mt-2 text-xs text-gray-500 dark:text-gray-400">
- Stops the agent, removes the systemd unit, and deletes the binary.
- </p>
- </div>
- </div>
- </details>
- </div>
- </Show>
-
- <Show when={requiresToken() && !hasToken()}>
- <p class="text-xs text-gray-500 dark:text-gray-400">
- Generate a new token to unlock the install commands.
- </p>
- </Show>
- <Show when={!requiresToken() && !confirmedNoToken() && !hasToken()}>
- <p class="text-xs text-gray-500 dark:text-gray-400">Confirm the no-token setup to continue.</p>
- </Show>
- </div>
- </Card>
-
- <Card>
- <div class="space-y-4">
- <div class="flex items-center justify-between">
- <h3 class="text-base font-semibold text-gray-900 dark:text-gray-100">Reporting hosts</h3>
- <span class="text-sm text-gray-500 dark:text-gray-400">{allHosts().length} connected</span>
- </div>
-
- <Show when={reusedTokens().length > 0}>
- <div class="rounded-lg border border-amber-300 bg-amber-50 px-4 py-3 text-sm text-amber-900 shadow-sm dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-100">
- <div class="flex items-start gap-3">
- <svg class="h-4 w-4 mt-0.5 text-amber-600 dark:text-amber-300" viewBox="0 0 20 20" fill="currentColor">
- <path
- fill-rule="evenodd"
- d="M8.257 3.099c.764-1.36 2.722-1.36 3.486 0l6.518 11.62c.75 1.338-.213 3.005-1.743 3.005H3.482c-1.53 0-2.493-1.667-1.743-3.005l6.518-11.62ZM11 5a1 1 0 1 0-2 0v4.5a1 1 0 1 0 2 0V5Zm0 8a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z"
- clip-rule="evenodd"
- />
- </svg>
- <div class="space-y-1">
- <p class="font-semibold">Token re-use detected across host agents.</p>
- <p class="leading-snug text-sm">
- Generate a new host-agent token per machine or set a unique <code class="rounded bg-amber-100 px-1 py-0.5 font-mono text-[11px] text-amber-800 dark:bg-amber-900/40 dark:text-amber-100">--agent-id</code> to stop hosts from overwriting each other.
- </p>
- <Show when={requiresToken()}>
- <button
- type="button"
- class="inline-flex items-center gap-2 rounded-md bg-amber-600 px-3 py-1.5 text-xs font-semibold text-white shadow-sm transition hover:bg-amber-700 disabled:opacity-60 disabled:cursor-not-allowed dark:bg-amber-500 dark:hover:bg-amber-400"
- disabled={isGeneratingToken()}
- onClick={() => {
- void handleGenerateToken();
- }}
- >
- <svg class="h-3.5 w-3.5" viewBox="0 0 20 20" fill="currentColor">
- <path d="M11 17a1 1 0 01-2 0v-4.086l-1.293 1.293a1 1 0 11-1.414-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L11 12.914V17z" />
- <path d="M5 3a2 2 0 00-2 2v6a2 2 0 002 2h2a1 1 0 100-2H5V5h10v6h-2a1 1 0 100 2h2a2 2 0 002-2V5a2 2 0 00-2-2H5z" />
- </svg>
- {isGeneratingToken() ? 'Generating…' : 'Generate fresh token'}
- </button>
- </Show>
- <div class="text-xs text-amber-800 dark:text-amber-200">
- <For each={reusedTokens()}>
- {(item) => (
- <div class="flex flex-wrap gap-1 py-0.5">
- <span class="rounded-full bg-amber-100 px-2 py-0.5 font-mono text-[11px] font-semibold text-amber-800 dark:bg-amber-900/50 dark:text-amber-200">
- token {item.tokenId.slice(0, 6)}…{item.tokenId.slice(-4)}
- </span>
- <span class="text-amber-900 dark:text-amber-100">
- used by {item.hosts.length} hosts: {item.hosts.map((host) => host.label).join(', ')}
- </span>
- </div>
- )}
- </For>
- </div>
- </div>
- </div>
- </div>
- </Show>
-
- <Show
- when={allHosts().length > 0}
- fallback={
- <div class="text-center py-8">
- <div class="text-gray-400 dark:text-gray-500 mb-2">
- <svg class="w-12 h-12 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"
- />
- </svg>
- </div>
- <p class="text-sm text-gray-600 dark:text-gray-400">
- No host agents are reporting yet.
- </p>
- <p class="text-xs text-gray-500 dark:text-gray-500 mt-1">
- Deploy the agent using the commands above to see hosts listed here.
- </p>
- </div>
- }
- >
- <div class="overflow-x-auto">
- <table class="w-full text-sm">
- <thead>
- <tr class="border-b border-gray-200 dark:border-gray-700">
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Host</th>
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Status</th>
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Platform</th>
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Uptime</th>
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Memory</th>
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Last Seen</th>
- <th class="text-left py-3 px-4 font-medium text-gray-600 dark:text-gray-400">Tags</th>
- <th class="py-3 px-4" />
- </tr>
- </thead>
- <tbody class="divide-y divide-gray-200 dark:divide-gray-700">
- <For each={allHosts()}>
- {(host) => {
- const staleness = computeHostStaleness(host);
- const isStale = staleness.isStale;
- const tokenRevokedAt = host.tokenRevokedAt;
- const tokenRevoked = typeof tokenRevokedAt === 'number';
- const tokenUsageEntry = host.tokenId ? hostTokenUsage().get(host.tokenId) : undefined;
- const tokenReused = tokenUsageEntry ? tokenUsageEntry.count > 1 : false;
- const status = (host.status || 'unknown').toLowerCase();
- const isOnline =
- status === 'online' || status === 'running' || status === 'healthy';
- const isHighlighted = highlightedHostId() === host.id;
- const isRemovingThisHost = hostToRemoveId() === host.id && removeActionLoading() !== null;
-
- const baseRowClass = isStale
- ? 'bg-gray-50 dark:bg-gray-800/50 opacity-60'
- : 'bg-white dark:bg-gray-900';
-
- const rowClass =
- tokenRevoked && !isStale ? `${baseRowClass} opacity-60` : baseRowClass;
- const highlightClass = isHighlighted
- ? 'ring-2 ring-blue-500/70 dark:ring-blue-400/70 shadow-md'
- : '';
-
- const handleRemoveClick = () => {
- openRemoveModal(host);
- };
-
- return (
- <tr data-host-id={host.id} class={`${rowClass} ${highlightClass}`}>
- <td class="py-3 px-4">
- <div class="font-medium text-gray-900 dark:text-gray-100">
- {host.displayName || host.hostname || host.id}
- </div>
- <div class="text-xs text-gray-500 dark:text-gray-400">
- {host.hostname}
- </div>
- <Show when={tokenReused}>
- <div class="mt-1 inline-flex items-center gap-1 rounded-full bg-amber-100 px-2 py-0.5 text-[11px] font-semibold text-amber-800 dark:bg-amber-900/40 dark:text-amber-200">
- <svg class="h-3 w-3" viewBox="0 0 20 20" fill="currentColor">
- <path
- fill-rule="evenodd"
- d="M8.257 3.099c.764-1.36 2.722-1.36 3.486 0l6.518 11.62c.75 1.338-.213 3.005-1.743 3.005H3.482c-1.53 0-2.493-1.667-1.743-3.005l6.518-11.62ZM11 5a1 1 0 1 0-2 0v4.5a1 1 0 1 0 2 0V5Zm0 8a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z"
- clip-rule="evenodd"
- />
- </svg>
- Token reused ({tokenUsageEntry?.count})
- </div>
- </Show>
- <Show when={host.agentVersion}>
- <div class="text-xs text-gray-400 dark:text-gray-500 mt-1">
- Agent {host.agentVersion}
- </div>
- </Show>
- </td>
- <td class="py-3 px-4">
- <div class="flex items-center gap-2">
- <span
- class={`inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ${isOnline
- ? 'bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300'
- : 'bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300'
- }`}
- >
- {host.status || 'unknown'}
- </span>
- <Show when={isStale}>
- <span class="inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-yellow-100 text-yellow-700 dark:bg-yellow-900/40 dark:text-yellow-300">
- <svg class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
- </svg>
- No recent data
- </span>
- </Show>
- <Show when={tokenRevoked}>
- <span class="inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-semibold bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300">
- <svg class="h-3 w-3" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
- <path
- fill-rule="evenodd"
- d="M8.257 3.099c.764-1.36 2.722-1.36 3.486 0l6.518 11.62c.75 1.338-.213 3.005-1.743 3.005H3.482c-1.53 0-2.493-1.667-1.743-3.005l6.518-11.62ZM11 5a1 1 0 1 0-2 0v4.5a1 1 0 1 0 2 0V5Zm0 8a1 1 0 1 0-2 0 1 1 0 0 0 2 0Z"
- clip-rule="evenodd"
- />
- </svg>
- Token revoked
- </span>
- </Show>
- </div>
- </td>
- <td class="py-3 px-4 text-gray-700 dark:text-gray-300 capitalize">
- {host.platform || '—'}
- </td>
- <td class="py-3 px-4 text-gray-700 dark:text-gray-300">
- {host.uptimeSeconds ? formatUptime(host.uptimeSeconds) : '—'}
- </td>
- <td class="py-3 px-4 text-gray-700 dark:text-gray-300">
- {host.memory?.total
- ? `${formatBytes(host.memory.used ?? 0)} / ${formatBytes(host.memory.total)}`
- : '—'}
- </td>
- <td class="py-3 px-4">
- <div class="text-gray-900 dark:text-gray-100">
- {host.lastSeen ? formatRelativeTime(host.lastSeen) : '—'}
- </div>
- <Show when={host.lastSeen}>
- <div class="text-xs text-gray-500 dark:text-gray-400">
- {formatAbsoluteTime(host.lastSeen!)}
- </div>
- </Show>
- </td>
- <td class="py-3 px-4 text-gray-700 dark:text-gray-300">
- {renderTags(host)}
- </td>
- <td class="py-3 px-4 text-right">
- <button
- type="button"
- onClick={handleRemoveClick}
- disabled={isRemovingThisHost}
- class="inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
- title={
- isStale
- ? 'Remove this stale host entry from the inventory'
- : 'Host is still reporting — review the removal steps first'
- }
- >
- {isRemovingThisHost ? (
- <>
- <svg class="animate-spin h-3 w-3" fill="none" viewBox="0 0 24 24">
- <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
- <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
- </svg>
- <span>Removing...</span>
- </>
- ) : (
- <>
- <svg class="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1 1v3M4 7h16" />
- </svg>
- <span>Remove</span>
- </>
- )}
- </button>
- </td>
- </tr>
- );
- }}
- </For>
- </tbody>
- </table>
- </div>
- </Show>
- </div>
- </Card>
-
- <Show when={showRemoveModal()}>
- <div class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
- <div class="w-full max-w-2xl rounded-lg bg-white p-6 shadow-xl dark:bg-gray-800">
- <div class="space-y-2">
- <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100">
- Remove host "{hostRemovalDisplayName()}"
- </h3>
- <p class="text-sm text-gray-600 dark:text-gray-400">
- Walk through uninstalling the agent and cleaning up the entry in Pulse.
- </p>
- </div>
-
- <div class="mt-4 space-y-4">
- <div class="space-y-3 rounded-lg border border-blue-200 bg-blue-50 p-4 dark:border-blue-800 dark:bg-blue-900/20">
- <div class="flex items-start gap-3">
- <svg class="w-5 h-5 text-blue-600 dark:text-blue-400 mt-0.5 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
- </svg>
- <div class="flex-1 space-y-2">
- <h4 class="text-sm font-semibold text-blue-900 dark:text-blue-100">Step 1 · Stop the agent on {hostRemovalDisplayName()}</h4>
- <p class="text-sm text-blue-800 dark:text-blue-200">
- Copy the tailored uninstall script below, run it on the host, then confirm once the command finishes. It runs silently, so no terminal output is expected.
- </p>
- </div>
- </div>
-
- <div class="space-y-2 rounded border border-blue-200 bg-white p-3 text-xs text-blue-800 dark:border-blue-700 dark:bg-blue-800/20 dark:text-blue-200">
- <div class="flex items-center justify-between gap-2">
- <span class="font-semibold uppercase tracking-wide text-[11px] text-blue-600 dark:text-blue-300">Manual uninstall</span>
- <button
- type="button"
- onClick={async () => {
- const command = hostRemovalUninstallCommand();
- if (!command) return;
- const success = await copyToClipboard(command);
- if (success) {
- setUninstallCommandCopied(true);
- setUninstallCommandCopiedAt(Date.now());
- }
- if (typeof window !== 'undefined' && window.showToast) {
- window.showToast(success ? 'success' : 'error', success ? 'Copied!' : 'Failed to copy');
- }
- }}
- class="inline-flex items-center gap-2 rounded bg-blue-600 px-3 py-1.5 text-[11px] font-semibold text-white transition-colors hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-400"
- >
- <svg class="h-3 w-3" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
- <path d="M4 4a2 2 0 012-2h5a2 2 0 012 2v2h-2V4H6v10h5v-2h2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V4z" />
- <path d="M14.293 7.293a1 1 0 011.414 0L18 9.586l-2.293 2.293a1 1 0 01-1.414-1.415L14.586 10H9a1 1 0 110-2h5.586l-.293-.293a1 1 0 010-1.414z" />
- </svg>
- {uninstallCommandCopied() ? 'Copied' : 'Copy command'}
- </button>
- </div>
- <code class="block overflow-x-auto rounded bg-gray-900 px-3 py-2 font-mono text-xs text-gray-100 dark:bg-gray-950 whitespace-pre-wrap">
- {hostRemovalUninstallCommand()}
- </code>
- <p class="text-[11px] leading-snug">{hostRemovalUninstallNote()}</p>
- <Show when={uninstallCommandCopied()}>
- <div class="space-y-2 rounded border border-blue-200 bg-white p-3 text-[11px] text-blue-800 dark:border-blue-700 dark:bg-blue-800/20 dark:text-blue-200">
- <p class="font-medium">Command copied.</p>
- <p>This script runs silently—no CLI output is expected. Once it completes, mark it finished below.</p>
- <Show when={uninstallCommandCopiedAt()}>
- <p class="text-blue-700/80 dark:text-blue-200/80">Copied {formatRelativeTime(uninstallCommandCopiedAt()!)}.</p>
- </Show>
- <button
- type="button"
- onClick={() => setUninstallConfirmed(true)}
- disabled={uninstallConfirmed()}
- class={`inline-flex items-center gap-2 rounded ${uninstallConfirmed() ? 'bg-blue-100 text-blue-500 cursor-default' : 'bg-blue-600 text-white hover:bg-blue-700'} px-3 py-1.5 text-[11px] font-semibold transition-colors dark:${uninstallConfirmed() ? 'bg-blue-900/30 text-blue-200' : 'bg-blue-500 hover:bg-blue-400'}`}
- >
- <svg class="h-3.5 w-3.5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
- <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.707a1 1 0 00-1.414-1.414L9 10.172 7.707 8.879A1 1 0 006.293 10.293l2 2a1 1 0 001.414 0l3-3z" clip-rule="evenodd" />
- </svg>
- {uninstallConfirmed() ? 'Marked complete' : 'I ran this command'}
- </button>
- <Show when={!uninstallConfirmed()}>
- <p>Click once you have run the script on {hostRemovalDisplayName()}.</p>
- </Show>
- </div>
- </Show>
- </div>
- </div>
-
- <div class="space-y-3 rounded-lg border border-gray-200 bg-white p-4 shadow-sm dark:border-gray-700 dark:bg-gray-900">
- <div class="flex items-center justify-between text-xs text-gray-600 dark:text-gray-300">
- <span class="font-semibold uppercase tracking-wide text-[11px] text-gray-500 dark:text-gray-400">Host status</span>
- <span
- class={`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-semibold uppercase ${hostRemovalIsOnline()
- ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-200'
- : 'bg-gray-200 text-gray-700 dark:bg-gray-700 dark:text-gray-200'
- }`}
- >
- {hostRemovalStatusLabel()}
- </span>
- </div>
- <div class="text-xs text-gray-600 dark:text-gray-300">
- <div class="flex items-center justify-between">
- <span class="font-medium">Last heartbeat</span>
- <span class="text-gray-700 dark:text-gray-200">
- {hostRemovalLastSeen()?.relative ?? 'No reports yet'}
- </span>
- </div>
- <Show when={hostRemovalLastSeen()}>
- <div class="text-[11px] text-gray-500 dark:text-gray-400 text-right">
- {hostRemovalLastSeen()?.absolute}
- </div>
- </Show>
- </div>
- <Show when={!hostRemovalIsStale()}>
- <div class="rounded border border-yellow-200 bg-yellow-50 p-3 text-xs text-yellow-800 dark:border-yellow-700 dark:bg-yellow-900/20 dark:text-yellow-200">
- <p class="font-semibold">Host still reporting</p>
- <p class="mt-1 leading-snug">
- Pulse revokes the host's API token as soon as you remove it. After the uninstall script stops the service, the next heartbeat will fail and the agent will disappear within about {hostRemovalStaleThresholdSeconds()} seconds.
- </p>
- <Show when={countdownLabel()}>
- <p class="mt-2 rounded bg-yellow-100/60 px-2 py-1 text-[11px] font-medium text-yellow-800 dark:bg-yellow-900/40 dark:text-yellow-100">
- Waiting for the next missed heartbeat ({countdownLabel()}).
- </p>
- </Show>
- </div>
- </Show>
- <Show when={hostRemovalIsStale()}>
- <div class="rounded border border-emerald-200 bg-emerald-50 p-3 text-xs text-emerald-800 dark:border-emerald-700 dark:bg-emerald-900/20 dark:text-emerald-200">
- <p class="flex items-center gap-1 font-semibold">
- <svg class="h-3.5 w-3.5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
- <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.707a1 1 0 00-1.414-1.414L9 10.172 7.707 8.879A1 1 0 006.293 10.293l2 2a1 1 0 001.414 0l3-3z" clip-rule="evenodd" />
- </svg>
- Host offline
- </p>
- <p class="mt-1 leading-snug">
- Pulse no longer receives heartbeats from {hostRemovalDisplayName()}. It’s safe to remove the entry now.
- </p>
- </div>
- </Show>
- </div>
- </div>
-
- <div class="mt-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
- <button
- type="button"
- onClick={closeRemoveModal}
- class="self-start rounded-lg px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700"
- >
- Close
- </button>
- <Show
- when={canRemoveHost()}
- fallback={
- <div class="max-w-sm text-xs text-gray-500 dark:text-gray-400">
- <p class="font-semibold text-gray-600 dark:text-gray-200">Run the uninstall script and mark it complete above.</p>
- <p class="mt-1">Once confirmed, Pulse will enable the final removal step.</p>
- </div>
- }
- >
- <div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3">
- <button
- type="button"
- onClick={handleRemoveHost}
- disabled={removeActionLoading() !== null}
- class="rounded bg-red-600 px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-red-500 dark:hover:bg-red-400"
- >
- {removeActionLoading() === 'remove' ? 'Removing…' : 'Remove host'}
- </button>
- <div class="text-xs text-gray-500 dark:text-gray-400">
- <p>
- Removing a host revokes its API token so it cannot register again. With the service already uninstalled, Pulse just needs one more missed heartbeat to clear the row automatically.
- </p>
- </div>
- </div>
- </Show>
- </div>
- </div>
- </div>
- </Show>
- </div>
- );
-};
-
-export default HostAgents;
diff --git a/frontend-modern/src/components/Settings/Settings.tsx b/frontend-modern/src/components/Settings/Settings.tsx
index 293c46be6c..f23fa148f2 100644
--- a/frontend-modern/src/components/Settings/Settings.tsx
+++ b/frontend-modern/src/components/Settings/Settings.tsx
@@ -24,8 +24,7 @@ import {
} from '@/utils/apiClient';
import { NodeModal } from './NodeModal';
import { ChangePasswordModal } from './ChangePasswordModal';
-import { DockerAgents } from './DockerAgents';
-import { HostAgents } from './HostAgents';
+import { UnifiedAgents } from './UnifiedAgents';
import APITokenManager from './APITokenManager';
import { OIDCPanel } from './OIDCPanel';
import { QuickSecuritySetup } from './QuickSecuritySetup';
@@ -1231,8 +1230,7 @@ const Settings: Component<SettingsProps> = (props) => {
label: 'Platforms',
items: [
{ id: 'proxmox', label: 'Proxmox', icon: ProxmoxIcon },
- { id: 'docker', label: 'Docker', icon: Boxes },
- { id: 'hosts', label: 'Hosts', icon: Monitor, iconProps: { strokeWidth: 2 } },
+ { id: 'agents', label: 'Agents', icon: Monitor, iconProps: { strokeWidth: 2 } },
],
},
{
@@ -3535,14 +3533,9 @@ const Settings: Component<SettingsProps> = (props) => {
</div>
</div>
</Show>
- {/* Docker Platform Tab */}
- <Show when={activeTab() === 'docker'}>
- <DockerAgents />
- </Show>
-
- {/* Servers Platform Tab */}
- <Show when={activeTab() === 'hosts'}>
- <HostAgents />
+ {/* Unified Agents Tab */}
+ <Show when={activeTab() === 'agents'}>
+ <UnifiedAgents />
</Show>
{/* System General Tab */}
diff --git a/frontend-modern/src/components/Settings/UnifiedAgents.tsx b/frontend-modern/src/components/Settings/UnifiedAgents.tsx
new file mode 100644
index 0000000000..0363b92c56
--- /dev/null
+++ b/frontend-modern/src/components/Settings/UnifiedAgents.tsx
@@ -0,0 +1,510 @@
+import { Component, createSignal, Show, For, onMount, createEffect, createMemo, onCleanup } from 'solid-js';
+import { useWebSocket } from '@/App';
+import { Card } from '@/components/shared/Card';
+import { formatRelativeTime, formatAbsoluteTime } from '@/utils/format';
+import { MonitoringAPI } from '@/api/monitoring';
+import { SecurityAPI } from '@/api/security';
+import { notificationStore } from '@/stores/notifications';
+import type { SecurityStatus } from '@/types/config';
+import type { Host, HostLookupResponse } from '@/types/api';
+import type { APITokenRecord } from '@/api/security';
+import { HOST_AGENT_SCOPE, DOCKER_REPORT_SCOPE } from '@/constants/apiScopes';
+import { copyToClipboard } from '@/utils/clipboard';
+import { getPulseBaseUrl } from '@/utils/url';
+import { logger } from '@/utils/logger';
+
+const TOKEN_PLACEHOLDER = '<api-token>';
+const pulseUrl = () => getPulseBaseUrl();
+
+const buildDefaultTokenName = () => {
+ const now = new Date();
+ const iso = now.toISOString().slice(0, 16); // YYYY-MM-DDTHH:MM
+ const stamp = iso.replace('T', ' ').replace(/:/g, '-');
+ return `Agent ${stamp}`;
+};
+
+type AgentPlatform = 'linux' | 'macos' | 'windows';
+
+const commandsByPlatform: Record<
+ AgentPlatform,
+ {
+ title: string;
+ description: string;
+ snippets: { label: string; command: string; note?: string | any }[];
+ }
+> = {
+ linux: {
+ title: 'Install on Linux',
+ description:
+ 'The unified installer downloads the agent binary and configures it as a systemd service.',
+ snippets: [
+ {
+ label: 'Install with systemd',
+ command: `curl -fsSL ${pulseUrl()}/install.sh | sudo bash -s -- --url ${pulseUrl()} --token ${TOKEN_PLACEHOLDER} --interval 30s`,
+ note: (
+ <span>
+ Automatically installs to <code>/usr/local/bin/pulse-agent</code> and creates <code>/etc/systemd/system/pulse-agent.service</code>.
+ </span>
+ ),
+ },
+ ],
+ },
+ macos: {
+ title: 'Install on macOS',
+ description:
+ 'The unified installer downloads the universal binary and sets up a launchd service for background monitoring.',
+ snippets: [
+ {
+ label: 'Install with launchd',
+ command: `curl -fsSL ${pulseUrl()}/install.sh | sudo bash -s -- --url ${pulseUrl()} --token ${TOKEN_PLACEHOLDER} --interval 30s`,
+ note: (
+ <span>
+ Creates <code>/Library/LaunchDaemons/com.pulse.agent.plist</code> and starts the agent automatically.
+ </span>
+ ),
+ },
+ ],
+ },
+ windows: {
+ title: 'Install on Windows',
+ description:
+ 'Run the PowerShell script to install and configure the unified agent as a Windows service with automatic startup.',
+ snippets: [
+ {
+ label: 'Install as Windows Service (PowerShell)',
+ command: `irm ${pulseUrl()}/install.ps1 | iex`,
+ note: (
+ <span>
+ Run in PowerShell as Administrator. The script will prompt for the Pulse URL and API token, download the agent binary, and install it as a Windows service with automatic startup.
+ </span>
+ ),
+ },
+ {
+ label: 'Install with parameters (PowerShell)',
+ command: `$env:PULSE_URL="${pulseUrl()}"; $env:PULSE_TOKEN="${TOKEN_PLACEHOLDER}"; irm ${pulseUrl()}/install.ps1 | iex`,
+ note: (
+ <span>
+ Non-interactive installation. Set environment variables before running to skip prompts.
+ </span>
+ ),
+ },
+ ],
+ },
+};
+
+export const UnifiedAgents: Component = () => {
+ const { state } = useWebSocket();
+
+ let hasLoggedSecurityStatusError = false;
+
+ const [securityStatus, setSecurityStatus] = createSignal<SecurityStatus | null>(null);
+ const [latestRecord, setLatestRecord] = createSignal<APITokenRecord | null>(null);
+ const [tokenName, setTokenName] = createSignal('');
+ const [confirmedNoToken, setConfirmedNoToken] = createSignal(false);
+ const [currentToken, setCurrentToken] = createSignal<string | null>(null);
+ const [isGeneratingToken, setIsGeneratingToken] = createSignal(false);
+ const [lookupValue, setLookupValue] = createSignal('');
+ const [lookupResult, setLookupResult] = createSignal<HostLookupResponse | null>(null);
+ const [lookupError, setLookupError] = createSignal<string | null>(null);
+ const [lookupLoading, setLookupLoading] = createSignal(false);
+ const [enableDocker, setEnableDocker] = createSignal(true); // Default to true for unified experience
+
+ createEffect(() => {
+ if (requiresToken()) {
+ setConfirmedNoToken(false);
+ } else {
+ setCurrentToken(null);
+ setLatestRecord(null);
+ }
+ });
+
+ const commandSections = createMemo(() =>
+ Object.entries(commandsByPlatform).map(([platform, meta]) => ({
+ platform: platform as AgentPlatform,
+ ...meta,
+ })),
+ );
+
+ const connectedFromStatus = (status: string | undefined | null) => {
+ if (!status) return false;
+ const value = status.toLowerCase();
+ return value === 'online' || value === 'running' || value === 'healthy';
+ };
+
+ onMount(() => {
+ if (typeof window === 'undefined') {
+ return;
+ }
+
+ const fetchSecurityStatus = async () => {
+ try {
+ const response = await fetch('/api/security/status', { credentials: 'include' });
+ if (response.ok) {
+ const data = (await response.json()) as SecurityStatus;
+ setSecurityStatus(data);
+ }
+ } catch (err) {
+ if (!hasLoggedSecurityStatusError) {
+ hasLoggedSecurityStatusError = true;
+ logger.error('Failed to load security status', err);
+ }
+ }
+ };
+ fetchSecurityStatus();
+ });
+
+ const requiresToken = () => {
+ const status = securityStatus();
+ if (status) {
+ return status.requiresAuth || status.apiTokenConfigured;
+ }
+ return true;
+ };
+
+ const hasToken = () => Boolean(currentToken());
+ const commandsUnlocked = () => (requiresToken() ? hasToken() : hasToken() || confirmedNoToken());
+
+ const acknowledgeNoToken = () => {
+ if (requiresToken()) {
+ notificationStore.info('Generate or select a token before continuing.', 4000);
+ return;
+ }
+ setCurrentToken(null);
+ setLatestRecord(null);
+ setConfirmedNoToken(true);
+ notificationStore.success('Confirmed install commands without an API token.', 3500);
+ };
+
+ const handleGenerateToken = async () => {
+ if (isGeneratingToken()) return;
+
+ setIsGeneratingToken(true);
+ try {
+ const desiredName = tokenName().trim() || buildDefaultTokenName();
+ // Generate token with BOTH scopes
+ const scopes = [HOST_AGENT_SCOPE, DOCKER_REPORT_SCOPE];
+ const { token, record } = await SecurityAPI.createToken(desiredName, scopes);
+
+ setCurrentToken(token);
+ setLatestRecord(record);
+ setTokenName('');
+ setConfirmedNoToken(false);
+ notificationStore.success('Token generated with Host and Docker permissions.', 4000);
+ } catch (err) {
+ logger.error('Failed to generate agent token', err);
+ notificationStore.error('Failed to generate agent token. Confirm you are signed in as an administrator.', 6000);
+ } finally {
+ setIsGeneratingToken(false);
+ }
+ };
+
+ const resolvedToken = () => {
+ if (requiresToken()) {
+ return currentToken() || TOKEN_PLACEHOLDER;
+ }
+ return currentToken() || 'disabled';
+ };
+
+ const handleLookup = async () => {
+ const query = lookupValue().trim();
+ setLookupError(null);
+
+ if (!query) {
+ setLookupResult(null);
+ setLookupError('Enter a hostname or host ID to check.');
+ return;
+ }
+
+ setLookupLoading(true);
+ try {
+ const result = await MonitoringAPI.lookupHost({ id: query, hostname: query });
+ if (!result) {
+ setLookupResult(null);
+ setLookupError(`No host has reported with "${query}" yet. Try again in a few seconds.`);
+ } else {
+ setLookupResult(result);
+ setLookupError(null);
+ }
+ } catch (err) {
+ const message = err instanceof Error ? err.message : 'Host lookup failed.';
+ setLookupResult(null);
+ setLookupError(message);
+ } finally {
+ setLookupLoading(false);
+ }
+ };
+
+ const getDockerFlag = () => enableDocker() ? ' --enable-docker' : '';
+
+ const getUninstallCommand = () => {
+ return `curl -fsSL ${pulseUrl()}/install.sh | sudo bash -s -- --uninstall`;
+ };
+
+ return (
+ <div class="space-y-6">
+ <Card padding="lg" class="space-y-5">
+ <div class="space-y-1">
+ <h3 class="text-base font-semibold text-gray-900 dark:text-gray-100">Add a unified agent</h3>
+ <p class="text-sm text-gray-600 dark:text-gray-400">
+ Monitor server metrics (CPU, RAM, Disk) and Docker containers with a single agent.
+ </p>
+ </div>
+
+ <div class="space-y-5">
+ <Show when={requiresToken()}>
+ <div class="space-y-3">
+ <div class="space-y-1">
+ <p class="text-sm font-semibold text-gray-900 dark:text-gray-100">Generate API token</p>
+ <p class="text-sm text-gray-600 dark:text-gray-400">
+ Create a fresh token scoped for both Host and Docker monitoring.
+ </p>
+ </div>
+
+ <div class="flex gap-2">
+ <input
+ type="text"
+ value={tokenName()}
+ onInput={(event) => setTokenName(event.currentTarget.value)}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter' && !isGeneratingToken()) {
+ handleGenerateToken();
+ }
+ }}
+ placeholder="Token name (optional)"
+ class="flex-1 rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-100 dark:focus:border-blue-400 dark:focus:ring-blue-900/60"
+ />
+ <button
+ type="button"
+ onClick={handleGenerateToken}
+ disabled={isGeneratingToken()}
+ class="inline-flex items-center justify-center gap-2 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-60"
+ >
+ {isGeneratingToken() ? 'Generating…' : hasToken() ? 'Generate another' : 'Generate token'}
+ </button>
+ </div>
+
+ <Show when={latestRecord()}>
+ <div class="flex items-center gap-2 rounded-lg border border-blue-200 bg-blue-50 px-4 py-2 text-xs text-blue-800 dark:border-blue-800 dark:bg-blue-900/20 dark:text-blue-200">
+ <svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
+ <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
+ </svg>
+ <span>
+ Token <strong>{latestRecord()?.name}</strong> created. Commands below now include this credential.
+ </span>
+ </div>
+ </Show>
+
+ </div>
+ </Show>
+
+ <Show when={!requiresToken()}>
+ <div class="space-y-3">
+ <div class="rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800 dark:border-amber-700 dark:bg-amber-900/30 dark:text-amber-200">
+ Tokens are optional on this Pulse instance. Confirm to generate commands without embedding a token.
+ </div>
+ <button
+ type="button"
+ onClick={acknowledgeNoToken}
+ disabled={confirmedNoToken()}
+ class={`inline-flex items-center justify-center rounded-md px-4 py-2 text-sm font-medium transition-colors ${confirmedNoToken()
+ ? 'bg-green-600 text-white cursor-default'
+ : 'bg-gray-900 text-white hover:bg-black dark:bg-gray-100 dark:text-gray-900 dark:hover:bg-white'
+ }`}
+ >
+ {confirmedNoToken() ? 'No token confirmed' : 'Confirm without token'}
+ </button>
+ </div>
+ </Show>
+
+ <Show when={commandsUnlocked()}>
+ <div class="space-y-3">
+ <div class="flex items-center justify-between">
+ <h4 class="text-sm font-semibold text-gray-900 dark:text-gray-100">Installation commands</h4>
+ <label class="flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
+ <input
+ type="checkbox"
+ checked={enableDocker()}
+ onChange={(e) => setEnableDocker(e.currentTarget.checked)}
+ class="rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700"
+ />
+ Enable Docker monitoring
+ </label>
+ </div>
+
+ <div class="space-y-4">
+ <For each={commandSections()}>
+ {(section) => (
+ <div class="space-y-3 rounded-lg border border-gray-200 dark:border-gray-700 p-4">
+ <div class="space-y-1">
+ <h5 class="text-sm font-semibold text-gray-900 dark:text-gray-100">{section.title}</h5>
+ <p class="text-xs text-gray-500 dark:text-gray-400">{section.description}</p>
+ </div>
+ <div class="space-y-3">
+ <For each={section.snippets}>
+ {(snippet) => {
+ const copyCommand = () => {
+ let cmd = snippet.command.replace(TOKEN_PLACEHOLDER, resolvedToken());
+ // Append docker flag if enabled
+ if (enableDocker()) {
+ // For PowerShell, we need to handle the env var or args differently
+ if (cmd.includes('$env:PULSE_URL')) {
+ // Env var style: add $env:PULSE_ENABLE_DOCKER="true";
+ cmd = `$env:PULSE_ENABLE_DOCKER="true"; ` + cmd;
+ } else if (cmd.includes('irm')) {
+ // Simple irm style: no args passed to script directly in this snippet style
+ // Actually, the simple irm style relies on prompts, so flags don't apply directly unless we change the snippet
+ // But for the bash script, we append flags
+ if (!cmd.includes('irm')) {
+ cmd += getDockerFlag();
+ }
+ } else {
+ cmd += getDockerFlag();
+ }
+ }
+ return cmd;
+ };
+
+ return (
+ <div class="space-y-2">
+ <div class="flex items-center justify-between gap-3">
+ <h6 class="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
+ {snippet.label}
+ </h6>
+ <button
+ type="button"
+ onClick={async () => {
+ const success = await copyToClipboard(copyCommand());
+ if (typeof window !== 'undefined' && window.showToast) {
+ window.showToast(success ? 'success' : 'error', success ? 'Copied!' : 'Failed to copy');
+ }
+ }}
+ class="px-3 py-1.5 text-xs font-medium rounded-lg transition-colors bg-blue-600 text-white hover:bg-blue-700"
+ >
+ Copy command
+ </button>
+ </div>
+ <pre class="overflow-x-auto rounded-md bg-gray-900/90 p-3 text-xs text-gray-100">
+ <code>{copyCommand()}</code>
+ </pre>
+ <Show when={snippet.note}>
+ <p class="text-xs text-gray-500 dark:text-gray-400">{snippet.note}</p>
+ </Show>
+ </div>
+ );
+ }}
+ </For>
+ </div>
+ </div>
+ )}
+ </For>
+ </div>
+
+ <div class="space-y-3 rounded-lg border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-900 dark:border-blue-800 dark:bg-blue-900/20 dark:text-blue-100">
+ <div class="flex items-center justify-between gap-3">
+ <h5 class="text-sm font-semibold">Check installation status</h5>
+ <button
+ type="button"
+ onClick={handleLookup}
+ disabled={lookupLoading()}
+ class="rounded-lg bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-60"
+ >
+ {lookupLoading() ? 'Checking…' : 'Check status'}
+ </button>
+ </div>
+ <p class="text-xs text-blue-800 dark:text-blue-200">
+ Enter the hostname (or host ID) from the machine you just installed. Pulse returns the latest status instantly.
+ </p>
+ <div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3">
+ <input
+ type="text"
+ value={lookupValue()}
+ onInput={(event) => {
+ setLookupValue(event.currentTarget.value);
+ setLookupError(null);
+ setLookupResult(null);
+ }}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter') {
+ event.preventDefault();
+ void handleLookup();
+ }
+ }}
+ placeholder="Hostname or host ID"
+ class="flex-1 rounded-lg border border-blue-200 bg-white px-3 py-2 text-sm text-blue-900 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 dark:border-blue-700 dark:bg-blue-900 dark:text-blue-100 dark:focus:border-blue-300 dark:focus:ring-blue-800/60"
+ />
+ </div>
+ <Show when={lookupError()}>
+ <p class="text-xs font-medium text-red-600 dark:text-red-300">{lookupError()}</p>
+ </Show>
+ <Show when={lookupResult()}>
+ {(result) => {
+ const host = () => result().host;
+ const statusBadgeClasses = () =>
+ host().connected
+ ? 'bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300'
+ : 'bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-200';
+ return (
+ <div class="space-y-1 rounded-lg border border-blue-200 bg-white px-3 py-2 text-xs text-blue-900 dark:border-blue-700 dark:bg-blue-900/40 dark:text-blue-100">
+ <div class="flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
+ <div class="text-sm font-semibold">
+ {host().displayName || host().hostname}
+ </div>
+ <div class="flex items-center gap-2">
+ <span class={`inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-semibold ${statusBadgeClasses()}`}>
+ {host().connected ? 'Connected' : 'Not reporting yet'}
+ </span>
+ <span class="inline-flex items-center rounded-full bg-blue-100 px-2 py-0.5 text-[11px] font-medium text-blue-700 dark:bg-blue-900/60 dark:text-blue-200">
+ {host().status || 'unknown'}
+ </span>
+ </div>
+ </div>
+ <div>
+ Last seen {formatRelativeTime(host().lastSeen)} ({formatAbsoluteTime(host().lastSeen)})
+ </div>
+ <Show when={host().agentVersion}>
+ <div class="text-xs text-blue-700 dark:text-blue-200">
+ Agent version {host().agentVersion}
+ </div>
+ </Show>
+ </div>
+ );
+ }}
+ </Show>
+ </div>
+ <details class="rounded-lg border border-gray-200 bg-gray-50 px-4 py-3 text-sm text-gray-700 dark:border-gray-700 dark:bg-gray-800/50 dark:text-gray-300">
+ <summary class="cursor-pointer text-sm font-medium text-gray-900 dark:text-gray-100">
+ Advanced options (uninstall & manual install)
+ </summary>
+ <div class="mt-3 space-y-4">
+ <div>
+ <p class="text-xs uppercase tracking-wide text-gray-500 dark:text-gray-400">Uninstall</p>
+ <div class="mt-2 flex items-center gap-2">
+ <code class="flex-1 break-all rounded bg-gray-900 px-3 py-2 font-mono text-xs text-red-400 dark:bg-gray-950">
+ {getUninstallCommand()}
+ </code>
+ <button
+ type="button"
+ onClick={async () => {
+ const success = await copyToClipboard(getUninstallCommand());
+ if (typeof window !== 'undefined' && window.showToast) {
+ window.showToast(success ? 'success' : 'error', success ? 'Copied to clipboard' : 'Failed to copy to clipboard');
+ }
+ }}
+ class="rounded-lg bg-red-50 px-3 py-1.5 text-xs font-medium text-red-700 transition-colors hover:bg-red-100 dark:bg-red-900/30 dark:text-red-300 dark:hover:bg-red-900/50"
+ >
+ Copy
+ </button>
+ </div>
+ <p class="mt-2 text-xs text-gray-500 dark:text-gray-400">
+ Stops the agent, removes the binary, the systemd unit, and related files.
+ </p>
+ </div>
+ </div>
+ </details>
+ </div>
+ </Show>
+ </div>
+ </Card>
+ </div>
+ );
+};
diff --git a/scripts/install.sh b/scripts/install.sh
index d43b9a6ffb..efff30951c 100644
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -14,6 +14,12 @@
set -euo pipefail
+# --- Check Root ---
+if [[ $EUID -ne 0 ]]; then
+ echo "This script must be run as root. Please use sudo."
+ exit 1
+fi
+
# --- Configuration ---
AGENT_NAME="pulse-agent"
BINARY_NAME="pulse-agent"