2026-08-03 22:22:59 +00:00
|
|
|
import type { NetObject, ServiceInfo } from '../types';
|
2026-08-03 22:06:00 +00:00
|
|
|
|
2026-08-03 22:22:59 +00:00
|
|
|
const AGENT_BASE = 'http://127.0.0.1:8001';
|
2026-08-03 22:06:00 +00:00
|
|
|
|
|
|
|
|
export async function fetchObjects(): Promise<NetObject[]> {
|
|
|
|
|
return [
|
|
|
|
|
{ id: '1', name: 'Site HQ', slug: 'site-hq', type: 'site', status: 'active' },
|
|
|
|
|
{ id: '2', name: 'Rack A', slug: 'rack-a', type: 'rack', status: 'active' },
|
|
|
|
|
{ id: '3', name: 'Server Proxmox', slug: 'server-proxmox', type: 'physical_host', vendor: 'Dell', model: 'R730', status: 'active' },
|
|
|
|
|
{ id: '4', name: 'Switch Core', slug: 'switch-core', type: 'switch', vendor: 'Mikrotik', status: 'active' },
|
|
|
|
|
{ id: '5', name: 'Firewall Edge', slug: 'firewall-edge', type: 'firewall', status: 'active' },
|
|
|
|
|
];
|
|
|
|
|
}
|
2026-08-03 22:22:59 +00:00
|
|
|
|
|
|
|
|
export async function fetchServices(): Promise<ServiceInfo[]> {
|
|
|
|
|
const res = await fetch(`${AGENT_BASE}/services`);
|
|
|
|
|
if (!res.ok) throw new Error('Impossibile leggere lo stato dei servizi');
|
|
|
|
|
return res.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function serviceAction(name: string, action: 'start' | 'stop' | 'restart') {
|
|
|
|
|
const res = await fetch(`${AGENT_BASE}/services/${encodeURIComponent(name)}/${action}`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
});
|
|
|
|
|
if (!res.ok) throw new Error(`Azione ${action} fallita su ${name}`);
|
|
|
|
|
return res.json();
|
|
|
|
|
}
|