feat: ingest data from new agent system

This commit is contained in:
Aarnav Tale 2025-03-11 22:34:30 -04:00
parent e36352b7f3
commit 5b9dc7cfc6
No known key found for this signature in database
3 changed files with 23 additions and 3 deletions

View File

@ -15,6 +15,7 @@ interface Props {
machine: Machine;
routes: Route[];
users: User[];
isAgent?: boolean;
magic?: string;
stats?: HostInfo;
}
@ -22,8 +23,9 @@ interface Props {
export default function MachineRow({
machine,
routes,
magic,
users,
isAgent,
magic,
stats,
}: Props) {
const expired =
@ -79,6 +81,10 @@ export default function MachineRow({
tags.unshift('Subnets');
}
if (isAgent) {
tags.unshift('Headplane Agent');
}
const ipOptions = useMemo(() => {
if (magic) {
return [...machine.ipAddresses, `${machine.givenName}.${prefix}`];

View File

@ -14,11 +14,16 @@ import cn from '~/utils/cn';
import { hs_getConfig } from '~/utils/config/loader';
import { pull } from '~/utils/headscale';
import { getSession } from '~/utils/sessions.server';
import type { AppContext } from '~server/context/app';
import { menuAction } from './action';
import MenuOptions from './components/menu';
import Routes from './dialogs/routes';
export async function loader({ request, params }: LoaderFunctionArgs) {
export async function loader({
request,
params,
context,
}: LoaderFunctionArgs<AppContext>) {
const session = await getSession(request.headers.get('Cookie'));
if (!params.id) {
throw new Error('No machine ID provided');
@ -44,6 +49,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
routes: routes.routes.filter((route) => route.node.id === params.id),
users: users.users,
magic,
agent: context?.agents.includes(machine.node.id),
};
}
@ -52,8 +58,10 @@ export async function action({ request }: ActionFunctionArgs) {
}
export default function Page() {
const { machine, magic, routes, users } = useLoaderData<typeof loader>();
const { machine, magic, routes, users, agent } =
useLoaderData<typeof loader>();
const [showRouting, setShowRouting] = useState(false);
console.log(machine.expiry);
const expired =
machine.expiry === '0001-01-01 00:00:00' ||
@ -68,6 +76,10 @@ export default function Page() {
tags.unshift('Expired');
}
if (agent) {
tags.unshift('Headplane Agent');
}
// This is much easier with Object.groupBy but it's too new for us
const { exit, subnet, subnetApproved } = routes.reduce<{
exit: Route[];

View File

@ -51,6 +51,7 @@ export async function loader({
magic,
server: ctx.headscale.url,
publicServer: ctx.headscale.public_url,
agents: context.agents,
};
}
@ -124,6 +125,7 @@ export default function Page() {
users={data.users}
magic={data.magic}
stats={stats?.[machine.nodeKey]}
isAgent={data.agents.includes(machine.id)}
/>
))}
</tbody>