Render the Generated timestamp using src/display-date.ts (DD.mmm.YYYY HH:MM:SS) instead of ISO 8601. --- Build: pass | Tests: not run
75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import { hostd } from '../src/hostd/client.js';
|
|
import { parseBastilleList } from '../src/bastille-list.js';
|
|
import { formatDisplayDate } from '../src/display-date.js';
|
|
|
|
async function main(): Promise<void> {
|
|
const [jailRes, zfsRes, pfRes] = await Promise.all([
|
|
hostd('bastille-list').catch(() => ({
|
|
ok: false as const,
|
|
output: '',
|
|
error: 'unreachable',
|
|
})),
|
|
hostd('zfs-list').catch(() => ({
|
|
ok: false as const,
|
|
output: '',
|
|
error: 'unreachable',
|
|
})),
|
|
hostd('service-status', { name: 'pf' }).catch(() => ({
|
|
ok: false as const,
|
|
output: '',
|
|
error: 'unreachable',
|
|
})),
|
|
]);
|
|
|
|
console.log('=== SYSTEM HEALTH ===\n');
|
|
|
|
console.log('-- Jails --');
|
|
if (jailRes.ok) {
|
|
const jails = parseBastilleList(jailRes.output).map((j) => ({
|
|
jid: j.jid,
|
|
name: j.name,
|
|
ip: j.ip,
|
|
state: j.state,
|
|
}));
|
|
|
|
const running = jails.filter((j) => j.state === 'running').length;
|
|
console.log(
|
|
` ${jails.length} jail(s), ${running} running, ${jails.length - running} stopped`,
|
|
);
|
|
for (const j of jails) {
|
|
console.log(` ${j.state === 'running' ? '●' : '○'} ${j.name} (${j.ip})`);
|
|
}
|
|
} else {
|
|
console.log(' Unable to reach hostd');
|
|
}
|
|
|
|
console.log('\n-- ZFS --');
|
|
if (zfsRes.ok) {
|
|
const lines = zfsRes.output
|
|
.split('\n')
|
|
.filter((l) => l.trim() && !/^NAME/i.test(l));
|
|
for (const line of lines.slice(0, 8)) {
|
|
const parts = line.trim().split(/\s+/);
|
|
console.log(` ${parts[0]}: used=${parts[1]} avail=${parts[2]}`);
|
|
}
|
|
if (lines.length > 8) console.log(` ... and ${lines.length - 8} more`);
|
|
} else {
|
|
console.log(' Unable to reach hostd');
|
|
}
|
|
|
|
console.log('\n-- PF Firewall --');
|
|
if (pfRes.ok) {
|
|
console.log(` ${pfRes.output.trim()}`);
|
|
} else if (pfRes.output.trim()) {
|
|
console.log(` ${pfRes.output.trim()}`);
|
|
} else {
|
|
console.log(' Unable to reach hostd');
|
|
}
|
|
|
|
console.log(`\nGenerated: ${formatDisplayDate(new Date())}`);
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error('Error:', err instanceof Error ? err.message : String(err));
|
|
process.exit(1);
|
|
});
|