@intflow/sentinelctl 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -8
- package/package.json +2 -2
- package/src/client.mjs +3 -3
- package/src/commands.mjs +200 -79
- package/src/main.mjs +77 -74
package/README.md
CHANGED
|
@@ -25,12 +25,34 @@ sentinelctl login
|
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
27
|
sentinelctl whoami
|
|
28
|
-
sentinelctl sessions list # your web sessions and
|
|
28
|
+
sentinelctl sessions list # your web sessions, CLI tokens and access keys
|
|
29
29
|
sentinelctl logout # revoke on the server and delete local credentials
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
Credentials live in `~/.config/sentinelctl/credentials.json` (Linux/macOS) or `%APPDATA%\sentinelctl\credentials.json` (Windows); override with `SENTINELCTL_CONFIG`. The server is taken from `--server`, then `SENTINEL_URL`, then the saved profile, then the default. Automation can pass `SENTINEL_TOKEN` instead of a credentials file.
|
|
33
33
|
|
|
34
|
+
## Access keys and MCP
|
|
35
|
+
|
|
36
|
+
An access key is a long-lived credential for MCP clients and scripts. It carries your account and your current role, and it keeps working without any browser or CLI login: logging out, an expired web session or a revoked CLI token do not affect it.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
sentinelctl access create "Claude Code on laptop" # prints the key once
|
|
40
|
+
sentinelctl access list
|
|
41
|
+
sentinelctl access revoke <key-id>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- A key lasts 30 days. Each time it is used a week or more after its last extension it gains 7 days, so a key in regular use does not expire. An unused key expires after 30 days.
|
|
45
|
+
- Up to 10 keys per person. Keys are created and revoked only from a web or CLI login, never with another key.
|
|
46
|
+
- The key stops working when you revoke it or an admin disables your account. A role change applies on the next request.
|
|
47
|
+
|
|
48
|
+
The console serves every command of this CLI as a remote MCP tool at `/api/mcp/` (Streamable HTTP). Nothing is installed on the client, and new server releases update the tools.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
claude mcp add --transport http sentinel https://monitor.intflow.dev/api/mcp/ --header "Authorization: Bearer sentinel_..."
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Other clients: URL `https://monitor.intflow.dev/api/mcp/`, header `Authorization: Bearer <access key>`. Tools are named `sentinel_<group>_<command>` (for example `sentinel_logs_stats`) and take the same options; the tool list contains only what your role may run. The same key also works as `SENTINEL_TOKEN` for this CLI.
|
|
55
|
+
|
|
34
56
|
## Getting help
|
|
35
57
|
|
|
36
58
|
```bash
|
|
@@ -54,6 +76,8 @@ sentinelctl metrics top diskDaysLeft --below 14 # disks that fill up
|
|
|
54
76
|
sentinelctl metrics top cpu --agg p95 -r 24h --compare --sort change
|
|
55
77
|
sentinelctl metrics top reboots -r 7d --above 0 # many devices reboot daily on schedule; compare with p50
|
|
56
78
|
sentinelctl metrics top networkTx -r 24h --label fleet=edge -o json
|
|
79
|
+
sentinelctl devices correlate <agent-id> --peak cpu -r 24h # metrics and logs around the CPU peak
|
|
80
|
+
sentinelctl devices correlate <agent-id> --at 2026-09-30T14:58:00+09:00 --window 30m
|
|
57
81
|
```
|
|
58
82
|
|
|
59
83
|
`metrics top` runs one query over every device: `--agg avg|max|min|p95|last` per device over `-r 1h|6h|24h|7d|30d` (or `--from/--to`, up to 30 days), ranked, with min/p50/p90/p95/max across devices. Metrics: cpu, memory, disk, swap, load, temperature, processes, tcpConnections, networkRx, networkTx, reboots, diskDaysLeft. `--compare` adds the previous window of the same length. Device filters work like `devices list`; retired devices are excluded by default.
|
|
@@ -112,8 +136,8 @@ sentinelctl metadata import backup.json --dry-run
|
|
|
112
136
|
sentinelctl admin users
|
|
113
137
|
sentinelctl admin grant kim@intflow.ai --role editor # works before the first login
|
|
114
138
|
sentinelctl admin reset kim@intflow.ai # back to the default viewer
|
|
115
|
-
sentinelctl admin disable kim@intflow.ai # block access and end all sessions now
|
|
116
|
-
sentinelctl admin sessions --kind cli
|
|
139
|
+
sentinelctl admin disable kim@intflow.ai # block access and end all sessions, tokens and keys now
|
|
140
|
+
sentinelctl admin sessions --kind access # web, cli or access
|
|
117
141
|
sentinelctl admin revoke <session-id>
|
|
118
142
|
sentinelctl admin audit --cleanup
|
|
119
143
|
sentinelctl admin operations -r 7d
|
|
@@ -121,6 +145,10 @@ sentinelctl admin operations -r 7d
|
|
|
121
145
|
|
|
122
146
|
Any other endpoint: `sentinelctl api "/api/devices?status=offline"`.
|
|
123
147
|
|
|
148
|
+
## Updates
|
|
149
|
+
|
|
150
|
+
The server tells the CLI the latest version; when a newer one exists the CLI prints one notice a day on stderr (`{"notice":{"type":"update_available"}}` with -o json). Update with `npm install -g sentinelctl@latest`. A CLI older than the server minimum gets exit code 3 with the same command. `SENTINELCTL_NO_UPDATE_NOTICE=1` turns the notice off.
|
|
151
|
+
|
|
124
152
|
## Output and exit codes
|
|
125
153
|
|
|
126
154
|
- `--select agentId,displayName,status,metadata.role` keeps only those fields of each item in json/ndjson output (plus top-level scalars), e.g. `devices list --all -o json` drops from ~700KB to ~20KB. `devices show --series none` (or `--series cpu,memory`) drops time series.
|
|
@@ -130,9 +158,10 @@ Any other endpoint: `sentinelctl api "/api/devices?status=offline"`.
|
|
|
130
158
|
|
|
131
159
|
## Publishing
|
|
132
160
|
|
|
133
|
-
|
|
161
|
+
GitHub Actions publishes both packages (`.github/workflows/publish-cli.yml`) with npm trusted publishing, so no npm token is stored.
|
|
134
162
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
163
|
+
1. Bump `cli/package.json`, `cli/unscoped/package.json` (version and its `@intflow/sentinelctl` dependency) and `cliLatestVersion` in `config/dashboard.json` to the same version; `node scripts/check-cli-release.mjs` checks this.
|
|
164
|
+
2. Commit, then push a tag: `git tag cli-v0.7.0 && git push origin cli-v0.7.0`.
|
|
165
|
+
3. The workflow runs the CLI checks and tests, publishes `@intflow/sentinelctl`, waits for the registry, then publishes the `sentinelctl` alias. Versions already on npm are skipped. Run it manually (Actions → publish-cli) to verify and pack without publishing.
|
|
166
|
+
|
|
167
|
+
One-time setup on npmjs.com, for each of the two packages: Settings → Trusted Publisher → GitHub Actions, organization or user `yeon3724`, repository `sentinel-fleet-console`, workflow `publish-cli.yml`, environment `npm`.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intflow/sentinelctl",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Sentinel Fleet Console CLI: search device logs, inspect status and metrics, edit metadata and
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Sentinel Fleet Console CLI: search device logs, inspect status and metrics, edit metadata, manage roles and create access keys for MCP",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"sentinelctl": "bin/sentinelctl.mjs"
|
package/src/client.mjs
CHANGED
|
@@ -9,9 +9,7 @@ export class ApiError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export function createClient({ server, token = null, fetch: fetchImplementation = globalThis.fetch, timeoutMs = 60_000, maxRetries = 5, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) }) {
|
|
12
|
+
export function createClient({ server, token = null, userAgent = 'sentinelctl', onVersions = null, fetch: fetchImplementation = globalThis.fetch, timeoutMs = 60_000, maxRetries = 5, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) }) {
|
|
15
13
|
async function request(method, path, { query, body, auth = true, allowStatuses = [] } = {}) {
|
|
16
14
|
const url = new URL(path, server);
|
|
17
15
|
for (const [key, value] of Object.entries(query ?? {})) {
|
|
@@ -36,6 +34,8 @@ export function createClient({ server, token = null, fetch: fetchImplementation
|
|
|
36
34
|
const reason = error?.name === 'TimeoutError' ? 'timed out' : 'could not connect';
|
|
37
35
|
throw new ApiError(`Request to ${url.origin} ${reason}.`, { code: 'network_error' });
|
|
38
36
|
}
|
|
37
|
+
const latest = response.headers.get('x-sentinelctl-latest');
|
|
38
|
+
if (onVersions && latest) onVersions({ latest, minimum: response.headers.get('x-sentinelctl-minimum') });
|
|
39
39
|
const text = await response.text();
|
|
40
40
|
let payload = {};
|
|
41
41
|
try {
|
package/src/commands.mjs
CHANGED
|
@@ -13,17 +13,17 @@ const maxPages = 40;
|
|
|
13
13
|
const deviceSorts = ['attention', 'status', 'displayName', 'cpu', 'memory', 'disk', 'load', 'temperature', 'ageSeconds', 'role', 'site', 'group', 'incidentCount'];
|
|
14
14
|
|
|
15
15
|
const logFilterOptions = {
|
|
16
|
-
query: { alias: 'q', type: 'string', placeholder: 'text', description: 'Words
|
|
17
|
-
pattern: { alias: 'p', type: 'string', placeholder: 'pattern', description: 'Exact
|
|
18
|
-
'case-sensitive': { type: 'boolean', description: '
|
|
19
|
-
agent: { alias: 'a', type: 'string', placeholder: 'id', description: '
|
|
20
|
-
level: { alias: 'l', type: 'string', choices: logLevels, description: 'emergency/critical/error include more severe levels; warning, info
|
|
21
|
-
source: { alias: 's', type: 'string', placeholder: 'source', description: '
|
|
22
|
-
service: { type: 'string', placeholder: 'name', description: '
|
|
23
|
-
env: { type: 'string', placeholder: 'name', description: '
|
|
24
|
-
range: { alias: 'r', type: 'string', choices: logRanges, description: 'Relative window
|
|
25
|
-
from: { type: 'string', placeholder: 'ISO', description: '
|
|
26
|
-
to: { type: 'string', placeholder: 'ISO', description: '
|
|
16
|
+
query: { alias: 'q', type: 'string', placeholder: 'text', description: 'Words in the message, case-insensitive. Positional words are appended.' },
|
|
17
|
+
pattern: { alias: 'p', type: 'string', placeholder: 'pattern', description: 'Exact pattern as printed by logs stats --by message or logs groups (<N> = number).' },
|
|
18
|
+
'case-sensitive': { type: 'boolean', description: 'Case-sensitive -q: much faster, misses other casings.' },
|
|
19
|
+
agent: { alias: 'a', type: 'string', placeholder: 'id', description: 'Agent ID (see devices lookup).' },
|
|
20
|
+
level: { alias: 'l', type: 'string', choices: logLevels, description: 'emergency/critical/error include more severe levels; warning, info, debug are exact.' },
|
|
21
|
+
source: { alias: 's', type: 'string', placeholder: 'source', description: 'systemd unit, container or syslog identifier (see logs sources).' },
|
|
22
|
+
service: { type: 'string', placeholder: 'name', description: '`service` label, across devices.' },
|
|
23
|
+
env: { type: 'string', placeholder: 'name', description: '`env` label.' },
|
|
24
|
+
range: { alias: 'r', type: 'string', choices: logRanges, description: 'Relative window (default 15m).' },
|
|
25
|
+
from: { type: 'string', placeholder: 'ISO', description: 'Start, e.g. 2026-09-30T09:00:00+09:00 (with --to; up to 31 days).' },
|
|
26
|
+
to: { type: 'string', placeholder: 'ISO', description: 'End.' },
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
async function getComplete(context, path, query) {
|
|
@@ -552,6 +552,52 @@ async function devicesOverview(context, { options, positionals }) {
|
|
|
552
552
|
]));
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
+
function durationSeconds(value, name) {
|
|
556
|
+
const match = /^(\d+)([smh])$/.exec(String(value));
|
|
557
|
+
if (!match) throw new UsageError(`--${name} must look like 90s, 15m or 2h: ${value}`);
|
|
558
|
+
return Number(match[1]) * { s: 1, m: 60, h: 3600 }[match[2]];
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const correlateMetricNames = ['cpu', 'memory', 'disk', 'load', 'temperature', 'swap', 'processes', 'tcpConnections', 'networkRx', 'networkTx'];
|
|
562
|
+
const correlateUnits = { cpu: '%', memory: '%', disk: '%', swap: '%', temperature: '°C', networkRx: 'B/s', networkTx: 'B/s' };
|
|
563
|
+
|
|
564
|
+
async function devicesCorrelate(context, { options, positionals }) {
|
|
565
|
+
const agentId = requireAgentId(positionals);
|
|
566
|
+
if (!options.at === !options.peak) throw new UsageError('Give exactly one of --at <time> or --peak <metric>.', { hint: 'Example: sentinelctl devices correlate <agent-id> --peak cpu -r 24h' });
|
|
567
|
+
if (options.at && !Number.isFinite(Date.parse(options.at))) throw new UsageError(`Cannot parse --at: ${options.at}`);
|
|
568
|
+
const body = await context.client.get(`/api/devices/${encodeURIComponent(agentId)}/correlate`, {
|
|
569
|
+
at: options.at ? new Date(options.at).toISOString() : undefined, peak: options.peak, range: options.peak ? options.range : undefined,
|
|
570
|
+
window: durationSeconds(options.window, 'window'), level: options.level, top: options.top, series: options.series ? 1 : undefined,
|
|
571
|
+
});
|
|
572
|
+
const value = (name, number) => metricValueText(number, correlateUnits[name]);
|
|
573
|
+
emit(context, body, () => [
|
|
574
|
+
renderKeyValues([
|
|
575
|
+
['Device', `${body.displayName} (${body.agentId})`],
|
|
576
|
+
['At', `${localTime(body.at)}${body.peak ? ` · peak ${body.peak.metric} ${value(body.peak.metric, body.peak.value)} in ${body.peak.range}` : ''}`],
|
|
577
|
+
['Window', `${localTime(body.window.start)} → ${localTime(body.window.end)} (${body.stepSeconds}s step)`],
|
|
578
|
+
['Reboots', body.reboots.map(localTime).join(', ') || 'none'],
|
|
579
|
+
['Logs', `${body.logs.total} (${Object.entries(body.logs.levels).map(([level, count]) => `${level} ${count}`).join(', ') || '-'})`],
|
|
580
|
+
]),
|
|
581
|
+
'',
|
|
582
|
+
renderTable(Object.entries(body.metrics), [
|
|
583
|
+
{ header: 'METRIC', value: ([name]) => name },
|
|
584
|
+
{ header: 'AT', value: ([name, item]) => value(name, item.atValue) },
|
|
585
|
+
{ header: 'MIN', value: ([name, item]) => value(name, item.min) },
|
|
586
|
+
{ header: 'MAX', value: ([name, item]) => value(name, item.max) },
|
|
587
|
+
{ header: 'BIGGEST STEP', value: ([name, item]) => (item.biggestStep ? `${item.biggestStep.delta > 0 ? '+' : ''}${value(name, item.biggestStep.delta)} at ${localTime(item.biggestStep.at).slice(11)}` : '-') },
|
|
588
|
+
], { width: context.width }),
|
|
589
|
+
'',
|
|
590
|
+
body.logs.groups.length ? renderTable(body.logs.groups, [
|
|
591
|
+
{ header: 'COUNT', value: (group) => String(group.count) },
|
|
592
|
+
{ header: 'FIRST', value: (group) => localTime(group.first).slice(11) },
|
|
593
|
+
{ header: 'SOURCE', value: (group) => group.source, max: 22 },
|
|
594
|
+
{ header: 'PATTERN', value: (group) => group.pattern },
|
|
595
|
+
], { width: context.width, wide: options.wide }) : 'No logs in the window.',
|
|
596
|
+
].join('\n'));
|
|
597
|
+
if (!body.logs.complete) context.hint('Log counts are partial; run again to complete.');
|
|
598
|
+
if (body.logs.truncated) context.hint(`Showing ${body.logs.groups.length} of ${body.logs.groupCount} log groups. Raise --top or add -l.`);
|
|
599
|
+
}
|
|
600
|
+
|
|
555
601
|
async function health(context) {
|
|
556
602
|
const body = await context.client.get('/api/health');
|
|
557
603
|
emit(context, body, () => [
|
|
@@ -698,12 +744,15 @@ async function metadataExport(context, { options }) {
|
|
|
698
744
|
}
|
|
699
745
|
|
|
700
746
|
async function metadataImport(context, { options, positionals }) {
|
|
701
|
-
if (!positionals[0]
|
|
747
|
+
if (!positionals[0] && options.data === undefined) {
|
|
748
|
+
throw new UsageError('A JSON file path or --data is required.', { hint: 'Use the format produced by `sentinelctl metadata export`.' });
|
|
749
|
+
}
|
|
750
|
+
if (positionals[0] && options.data !== undefined) throw new UsageError('Give either a file or --data, not both.');
|
|
702
751
|
let payload;
|
|
703
752
|
try {
|
|
704
|
-
payload = JSON.parse(await readFile(positionals[0], 'utf8'));
|
|
753
|
+
payload = JSON.parse(options.data ?? await readFile(positionals[0], 'utf8'));
|
|
705
754
|
} catch {
|
|
706
|
-
throw new UsageError(`Cannot read JSON file: ${positionals[0]}`);
|
|
755
|
+
throw new UsageError(options.data === undefined ? `Cannot read JSON file: ${positionals[0]}` : '--data must be JSON in export format.');
|
|
707
756
|
}
|
|
708
757
|
const path = options['dry-run'] ? '/api/metadata/import/validate' : '/api/metadata/import';
|
|
709
758
|
const body = (await context.client.request('POST', path, { query: { conflictPolicy: options.conflict }, body: payload })).body;
|
|
@@ -713,7 +762,7 @@ async function metadataImport(context, { options, positionals }) {
|
|
|
713
762
|
|
|
714
763
|
const sessionColumns = [
|
|
715
764
|
{ header: 'ID', value: (session) => session.id },
|
|
716
|
-
{ header: 'KIND', value: (session) => (
|
|
765
|
+
{ header: 'KIND', value: (session) => ({ cli: 'cli', access: 'key' })[session.kind] ?? 'web' },
|
|
717
766
|
{ header: 'USER', value: (session) => session.user, max: 32 },
|
|
718
767
|
{ header: 'CLIENT', value: (session) => session.clientName ?? '-', max: 28 },
|
|
719
768
|
{ header: 'LAST USED', value: (session) => localTime(session.lastSeenAt) },
|
|
@@ -733,13 +782,47 @@ async function sessionsRevoke(context, { positionals }) {
|
|
|
733
782
|
context.out(`Revoked session ${positionals[0]}.`);
|
|
734
783
|
}
|
|
735
784
|
|
|
785
|
+
const accessKeyColumns = [
|
|
786
|
+
{ header: 'ID', value: (key) => key.id },
|
|
787
|
+
{ header: 'NAME', value: (key) => key.name, max: 32 },
|
|
788
|
+
{ header: 'CREATED', value: (key) => localTime(key.createdAt) },
|
|
789
|
+
{ header: 'LAST USED', value: (key) => (key.lastUsedAt ? localTime(key.lastUsedAt) : 'never') },
|
|
790
|
+
{ header: 'EXPIRES', value: (key) => localTime(key.expiresAt) },
|
|
791
|
+
];
|
|
792
|
+
|
|
793
|
+
async function accessList(context) {
|
|
794
|
+
const body = await context.client.get('/api/access');
|
|
795
|
+
emit(context, context.global.output === 'ndjson' ? body.keys : body, () => (body.keys.length
|
|
796
|
+
? renderTable(body.keys, accessKeyColumns, { width: context.width })
|
|
797
|
+
: 'No access keys. Create one with `sentinelctl access create <name>`.'));
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
async function accessCreate(context, { positionals }) {
|
|
801
|
+
const name = positionals.join(' ').trim();
|
|
802
|
+
if (!name) throw new UsageError('A key name is required.', { hint: 'Example: sentinelctl access create "Claude Code on laptop"' });
|
|
803
|
+
const key = await context.client.post('/api/access', { name });
|
|
804
|
+
const mcpUrl = new URL('/api/mcp/', context.client.server).href;
|
|
805
|
+
emit(context, { ...key, mcpUrl }, () => [
|
|
806
|
+
renderKeyValues([['Name', key.name], ['ID', key.id], ['Expires', localTime(key.expiresAt)], ['MCP URL', mcpUrl]]),
|
|
807
|
+
'',
|
|
808
|
+
key.token,
|
|
809
|
+
].join('\n'));
|
|
810
|
+
context.hint(`Shown once; store it now. Connect an MCP client: claude mcp add --transport http sentinel ${mcpUrl} --header "Authorization: Bearer <key>"`);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
async function accessRevoke(context, { positionals }) {
|
|
814
|
+
if (!positionals[0]) throw new UsageError('A key ID is required.', { hint: 'List them with `sentinelctl access list`.' });
|
|
815
|
+
await context.client.request('DELETE', `/api/access/${encodeURIComponent(positionals[0])}`);
|
|
816
|
+
context.out(`Revoked access key ${positionals[0]}.`);
|
|
817
|
+
}
|
|
818
|
+
|
|
736
819
|
async function adminUsers(context) {
|
|
737
820
|
const body = await context.client.get('/api/admin/users');
|
|
738
821
|
emit(context, context.global.output === 'ndjson' ? body.users : body, () => renderTable(body.users, [
|
|
739
822
|
{ header: 'EMAIL', value: (user) => user.email, max: 36 },
|
|
740
823
|
{ header: 'ROLE', value: (user) => (user.disabled ? 'disabled' : user.effectiveRole) },
|
|
741
824
|
{ header: 'SOURCE', value: (user) => ({ bootstrap: 'bootstrap admin', grant: 'granted', default: 'default', disabled: 'disabled', intflow_app_admin: 'intflow app admin' })[user.roleSource] ?? user.roleSource },
|
|
742
|
-
{ header: 'WEB/CLI', value: (user) => `${user.sessions.web}/${user.sessions.cli}` },
|
|
825
|
+
{ header: 'WEB/CLI/KEY', value: (user) => `${user.sessions.web}/${user.sessions.cli}/${user.sessions.access ?? 0}` },
|
|
743
826
|
{ header: 'LAST LOGIN', value: (user) => localTime(user.lastLoginAt) },
|
|
744
827
|
], { width: context.width }));
|
|
745
828
|
}
|
|
@@ -821,22 +904,22 @@ async function rawApi(context, { options, positionals }) {
|
|
|
821
904
|
const commands = [
|
|
822
905
|
{
|
|
823
906
|
group: 'logs', name: 'search', run: logsSearch, role: 'viewer', mutates: false,
|
|
824
|
-
summary: 'Raw log lines
|
|
825
|
-
description: '
|
|
907
|
+
summary: 'Raw log lines, newest first',
|
|
908
|
+
description: 'Stops at 10,000 lines, which covers minutes of this fleet: read examples here after logs stats/groups, never count with it.',
|
|
826
909
|
args: [{ name: 'text', optional: true, description: 'Same as -q (words are joined with spaces).' }],
|
|
827
910
|
options: {
|
|
828
911
|
...logFilterOptions,
|
|
829
|
-
limit: { alias: 'n', type: 'integer', choices: [50, 100, 250], description: '
|
|
830
|
-
pages: { type: 'integer', placeholder: 'N', description: `
|
|
831
|
-
all: { type: 'boolean', description: '
|
|
832
|
-
fields: { type: 'boolean', description: '
|
|
833
|
-
collapse: { type: 'boolean', description: '
|
|
834
|
-
top: { type: 'integer', placeholder: 'N', description: '
|
|
835
|
-
dedupe: { type: 'boolean', description: 'Fold
|
|
836
|
-
since: { type: 'string', placeholder: 'ISO', description: 'Only logs after this
|
|
837
|
-
follow: { alias: 'f', type: 'boolean', description: '
|
|
838
|
-
interval: { type: 'integer', default: 5, placeholder: 'seconds', description: '
|
|
839
|
-
wide: { alias: 'w', type: 'boolean', description: 'Do not truncate
|
|
912
|
+
limit: { alias: 'n', type: 'integer', choices: [50, 100, 250], description: 'Lines per page (default 100; 250 when paging).' },
|
|
913
|
+
pages: { type: 'integer', placeholder: 'N', description: `Pages to follow (1-${maxPages}).` },
|
|
914
|
+
all: { type: 'boolean', description: 'All pages, up to 10,000 lines.' },
|
|
915
|
+
fields: { type: 'boolean', description: 'Raw fields (admin, audited, 50 per page).' },
|
|
916
|
+
collapse: { type: 'boolean', description: 'Same as logs groups.' },
|
|
917
|
+
top: { type: 'integer', placeholder: 'N', description: 'Groups with --collapse (1-500, default 50).' },
|
|
918
|
+
dedupe: { type: 'boolean', description: 'Fold same-second repeats into one line with a count.' },
|
|
919
|
+
since: { type: 'string', placeholder: 'ISO', description: 'Only logs after this time; poll with the printed nextSince.' },
|
|
920
|
+
follow: { alias: 'f', type: 'boolean', description: 'Stream new logs (humans only; never ends).' },
|
|
921
|
+
interval: { type: 'integer', default: 5, placeholder: 'seconds', description: 'Seconds between --follow polls (min 5).' },
|
|
922
|
+
wide: { alias: 'w', type: 'boolean', description: 'Do not truncate.' },
|
|
840
923
|
},
|
|
841
924
|
roleFor: (options) => (options.fields ? 'admin' : 'viewer'),
|
|
842
925
|
roleNote: '--fields requires admin',
|
|
@@ -849,21 +932,21 @@ const commands = [
|
|
|
849
932
|
'sentinelctl logs search -a <agent-id> -s ssh.service -r 6h --all -o json',
|
|
850
933
|
'sentinelctl logs search --from 2026-09-30T09:00:00+09:00 --to 2026-09-30T10:00:00+09:00 -l warning',
|
|
851
934
|
],
|
|
852
|
-
output: 'logs[]: timestamp
|
|
935
|
+
output: 'logs[]: {timestamp, severity, agentId, displayName, source, message, repeat?, fields?}; json adds {window, count, hasMore, nextSince?}.',
|
|
853
936
|
},
|
|
854
937
|
{
|
|
855
938
|
group: 'logs', name: 'stats', run: logsStats, role: 'viewer', mutates: false,
|
|
856
|
-
summary: '
|
|
857
|
-
description: '
|
|
939
|
+
summary: 'Exact counts by source, device, level, message pattern or service',
|
|
940
|
+
description: 'Counts every log in the window on the server. --compare shows what changed, --timeline when.',
|
|
858
941
|
args: [{ name: 'text', optional: true, description: 'Same as -q.' }],
|
|
859
942
|
options: {
|
|
860
943
|
...logFilterOptions,
|
|
861
|
-
by: { alias: 'b', type: 'string', choices: statsDimensions, default: 'source', description: '
|
|
862
|
-
top: { type: 'integer', default: 20, placeholder: 'N', description: 'Groups
|
|
863
|
-
compare: { type: 'boolean', description: '
|
|
864
|
-
timeline: { type: 'boolean', description: 'Add
|
|
865
|
-
sort: { type: 'string', choices: ['count', 'change'], description: '
|
|
866
|
-
wide: { alias: 'w', type: 'boolean', description: 'Do not truncate
|
|
944
|
+
by: { alias: 'b', type: 'string', choices: statsDimensions, default: 'source', description: 'Grouping (agent = device).' },
|
|
945
|
+
top: { type: 'integer', default: 20, placeholder: 'N', description: 'Groups (1-100).' },
|
|
946
|
+
compare: { type: 'boolean', description: 'Add the previous window: previousCount, change, isNew.' },
|
|
947
|
+
timeline: { type: 'boolean', description: 'Add counts over time per group (~48 buckets).' },
|
|
948
|
+
sort: { type: 'string', choices: ['count', 'change'], description: 'count or change (needs --compare).' },
|
|
949
|
+
wide: { alias: 'w', type: 'boolean', description: 'Do not truncate.' },
|
|
867
950
|
},
|
|
868
951
|
examples: [
|
|
869
952
|
'sentinelctl logs stats -l error -r 1h --by source',
|
|
@@ -873,36 +956,36 @@ const commands = [
|
|
|
873
956
|
'sentinelctl logs stats -a <agent-id> -r 7d --by message',
|
|
874
957
|
'sentinelctl logs stats "connection refused" -r 24h --by agent',
|
|
875
958
|
],
|
|
876
|
-
output: '{
|
|
959
|
+
output: '{total, devices, groupCount, truncated, complete, groups[]: {key, count, devices, displayName?, previousCount?, change?, isNew?, timeline?[[epoch, count]], first?, last?}, previous?, newGroupCount?, rising?, falling?}.',
|
|
877
960
|
},
|
|
878
961
|
{
|
|
879
962
|
group: 'logs', name: 'groups', run: logsGroups, role: 'viewer', mutates: false,
|
|
880
|
-
summary: 'Every
|
|
881
|
-
description: '
|
|
963
|
+
summary: 'Every device × source × pattern with count, first/last time and latest line',
|
|
964
|
+
description: 'Lossless summary of the window, typically 50-100x smaller than the raw lines.',
|
|
882
965
|
args: [{ name: 'text', optional: true, description: 'Same as -q.' }],
|
|
883
966
|
options: {
|
|
884
967
|
...logFilterOptions,
|
|
885
|
-
top: { type: 'integer', default: 50, placeholder: 'N', description: 'Groups
|
|
886
|
-
wide: { alias: 'w', type: 'boolean', description: 'Do not truncate
|
|
968
|
+
top: { type: 'integer', default: 50, placeholder: 'N', description: 'Groups, largest first (1-500).' },
|
|
969
|
+
wide: { alias: 'w', type: 'boolean', description: 'Do not truncate.' },
|
|
887
970
|
},
|
|
888
971
|
examples: [
|
|
889
972
|
'sentinelctl logs groups -l error -r 1h',
|
|
890
973
|
'sentinelctl logs groups -a <agent-id> -r 7d -o json',
|
|
891
974
|
'sentinelctl logs groups -p "Failed to start <N>.service" -r 24h',
|
|
892
975
|
],
|
|
893
|
-
output: '{
|
|
976
|
+
output: '{total, devices, groupCount, patternCount, truncated, complete, groups[]: {agentId, displayName, source, pattern, count, first, last, latest{timestamp, severity, message}}}.',
|
|
894
977
|
},
|
|
895
978
|
{
|
|
896
979
|
group: 'logs', name: 'facets', run: logsFacets, role: 'viewer', mutates: false,
|
|
897
|
-
summary: 'Top
|
|
898
|
-
description: '
|
|
980
|
+
summary: 'Top devices, severities, sources and labels in one query',
|
|
981
|
+
description: 'Fleet-wide up to 24h; up to 7 days with -a, -s, --service or -p.',
|
|
899
982
|
options: {
|
|
900
983
|
...logFilterOptions,
|
|
901
984
|
range: { alias: 'r', type: 'string', choices: logRanges, description: 'Window (default 1h).' },
|
|
902
985
|
top: { type: 'integer', default: 10, placeholder: 'N', description: 'Values per field (1-50).' },
|
|
903
986
|
},
|
|
904
987
|
examples: ['sentinelctl logs facets -l error -r 24h', 'sentinelctl logs facets -a <agent-id> -r 7d -o json'],
|
|
905
|
-
output: '{
|
|
988
|
+
output: '{facets{agent_id[{value, count, displayName}], severity[], _SYSTEMD_UNIT[], service[], …}}.',
|
|
906
989
|
},
|
|
907
990
|
{
|
|
908
991
|
group: 'logs', name: 'context', run: logsContext, role: 'viewer', mutates: false,
|
|
@@ -925,14 +1008,14 @@ const commands = [
|
|
|
925
1008
|
args: [{ name: 'text', optional: true, description: 'Same as -q.' }],
|
|
926
1009
|
options: logFilterOptions,
|
|
927
1010
|
examples: ['sentinelctl logs histogram -r 24h', 'sentinelctl logs histogram -a <agent-id> -r 30d -o json'],
|
|
928
|
-
output: '{
|
|
1011
|
+
output: '{stepSeconds, total, complete, buckets[]: {at (epoch), total, errors}}.',
|
|
929
1012
|
},
|
|
930
1013
|
{
|
|
931
1014
|
group: 'logs', name: 'sources', run: logsSources, role: 'viewer', mutates: false,
|
|
932
1015
|
summary: 'Log sources (systemd units, containers) ranked by exact count',
|
|
933
1016
|
options: { range: { alias: 'r', type: 'string', choices: logRanges, default: '24h', description: 'Sample window.' } },
|
|
934
1017
|
examples: ['sentinelctl logs sources -r 1h'],
|
|
935
|
-
output: '{
|
|
1018
|
+
output: '{total, sources[]: {value, count}} (top 50).',
|
|
936
1019
|
},
|
|
937
1020
|
{
|
|
938
1021
|
group: 'devices', name: 'list', run: devicesList, role: 'viewer', mutates: false,
|
|
@@ -990,21 +1073,21 @@ const commands = [
|
|
|
990
1073
|
},
|
|
991
1074
|
{
|
|
992
1075
|
group: 'metrics', name: 'top', run: metricsTop, role: 'viewer', mutates: false,
|
|
993
|
-
summary: 'Rank devices by a metric
|
|
994
|
-
description: '
|
|
1076
|
+
summary: 'Rank all devices by a metric over a window, with the fleet distribution',
|
|
1077
|
+
description: 'reboots = uptime resets (daily scheduled reboots are normal; compare with p50). diskDaysLeft = days until the root disk is full at the current growth. Device filters match devices list.',
|
|
995
1078
|
args: [{ name: 'metric', description: metricNames.join(', ') }],
|
|
996
1079
|
options: {
|
|
997
|
-
agg: { type: 'string', choices: ['avg', 'max', 'min', 'p95', 'last'], default: 'avg', description: 'Per-device aggregation
|
|
1080
|
+
agg: { type: 'string', choices: ['avg', 'max', 'min', 'p95', 'last'], default: 'avg', description: 'Per-device aggregation.' },
|
|
998
1081
|
range: { alias: 'r', type: 'string', choices: metricWindows, description: 'Window (default 24h).' },
|
|
999
|
-
from: { type: 'string', placeholder: 'ISO', description: '
|
|
1000
|
-
to: { type: 'string', placeholder: 'ISO', description: '
|
|
1001
|
-
top: { type: 'integer', default: 10, placeholder: 'N', description: 'Devices
|
|
1002
|
-
order: { type: 'string', choices: ['desc', 'asc'], description: 'desc
|
|
1003
|
-
compare: { type: 'boolean', description: '
|
|
1004
|
-
sort: { type: 'string', choices: ['value', 'change'], description: '
|
|
1005
|
-
above: { type: 'number', placeholder: 'N', description: 'Only
|
|
1006
|
-
below: { type: 'number', placeholder: 'N', description: 'Only
|
|
1007
|
-
query: { alias: 'q', type: 'string', placeholder: 'text', description: 'Device text
|
|
1082
|
+
from: { type: 'string', placeholder: 'ISO', description: 'Start (with --to; up to 30 days).' },
|
|
1083
|
+
to: { type: 'string', placeholder: 'ISO', description: 'End.' },
|
|
1084
|
+
top: { type: 'integer', default: 10, placeholder: 'N', description: 'Devices (1-100).' },
|
|
1085
|
+
order: { type: 'string', choices: ['desc', 'asc'], description: 'Default desc (asc for diskDaysLeft).' },
|
|
1086
|
+
compare: { type: 'boolean', description: 'Add the previous window: previous, change.' },
|
|
1087
|
+
sort: { type: 'string', choices: ['value', 'change'], description: 'value or change (needs --compare).' },
|
|
1088
|
+
above: { type: 'number', placeholder: 'N', description: 'Only values above N.' },
|
|
1089
|
+
below: { type: 'number', placeholder: 'N', description: 'Only values below N.' },
|
|
1090
|
+
query: { alias: 'q', type: 'string', placeholder: 'text', description: 'Device text.' },
|
|
1008
1091
|
status: { type: 'string', choices: deviceStatuses, description: 'Reception status.' },
|
|
1009
1092
|
lifecycle: { type: 'string', choices: lifecycles, description: 'Lifecycle scope (default operational).' },
|
|
1010
1093
|
role: { type: 'string', placeholder: 'role', description: 'Device role.' },
|
|
@@ -1022,19 +1105,37 @@ const commands = [
|
|
|
1022
1105
|
'sentinelctl metrics top diskDaysLeft -r 24h --below 14',
|
|
1023
1106
|
'sentinelctl metrics top networkTx -r 24h --label fleet=edge -o json',
|
|
1024
1107
|
],
|
|
1025
|
-
output: '{metric,
|
|
1108
|
+
output: '{metric, unit, scope{devices, withData, matched}, distribution{min, avg, p50, p90, p95, max}, devices[]: {agentId, displayName, status, value, previous?, change?}}.',
|
|
1026
1109
|
},
|
|
1027
1110
|
{
|
|
1028
1111
|
group: 'fleet', name: 'summary', run: fleetSummary, role: 'viewer', mutates: false,
|
|
1029
|
-
summary: '
|
|
1030
|
-
description: 'Start here
|
|
1112
|
+
summary: 'Status, attention, trends and error patterns in one call',
|
|
1113
|
+
description: 'Start here. Trends flag disks full within 14 days, temperature rises of 15°C+ and unusual reboot counts; error patterns are compared with the previous window. ~10KB JSON.',
|
|
1031
1114
|
options: {
|
|
1032
1115
|
range: { alias: 'r', type: 'string', choices: logRanges, default: '24h', description: 'Log window.' },
|
|
1033
|
-
logs: { type: 'boolean', description: '
|
|
1034
|
-
trends: { type: 'boolean', description: '
|
|
1116
|
+
logs: { type: 'boolean', description: 'Log statistics (--no-logs skips).' },
|
|
1117
|
+
trends: { type: 'boolean', description: 'Metric trends (--no-trends skips).' },
|
|
1035
1118
|
},
|
|
1036
1119
|
examples: ['sentinelctl fleet summary', 'sentinelctl fleet summary -r 1h -o json', 'sentinelctl fleet summary --no-logs'],
|
|
1037
|
-
output: '{
|
|
1120
|
+
output: '{devices{status, metrics, logs, offline}, attention[]{reason, count, devices}, resources{cpu, memory, disk, temperature}, trends{diskFullWithin14Days, temperatureRise, rebootOutliers}, logs{levels, errors, topErrorPatterns, risingErrorPatterns, fallingErrorPatterns, topErrorDevices}}.',
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
group: 'devices', name: 'correlate', run: devicesCorrelate, role: 'viewer', mutates: false,
|
|
1124
|
+
summary: 'Metrics and logs of one device around a time or metric peak',
|
|
1125
|
+
description: 'For "what happened when X spiked": metric values and biggest change, reboots and log groups around --at or the --peak of a metric.',
|
|
1126
|
+
args: [{ name: 'agent-id' }],
|
|
1127
|
+
options: {
|
|
1128
|
+
at: { type: 'string', placeholder: 'ISO', description: 'Center time.' },
|
|
1129
|
+
peak: { type: 'string', choices: correlateMetricNames, description: 'Center on the highest point of this metric within --range instead.' },
|
|
1130
|
+
range: { alias: 'r', type: 'string', choices: ['1h', '6h', '24h', '7d'], default: '24h', description: 'Where to look for --peak.' },
|
|
1131
|
+
window: { type: 'string', default: '15m', placeholder: 'duration', description: 'Look this far before and after (1m-6h).' },
|
|
1132
|
+
level: { alias: 'l', type: 'string', choices: logLevels, description: 'Only these log levels in the groups.' },
|
|
1133
|
+
top: { type: 'integer', default: 20, placeholder: 'N', description: 'Log groups (1-100).' },
|
|
1134
|
+
series: { type: 'boolean', description: 'Include the metric time series in JSON.' },
|
|
1135
|
+
wide: { alias: 'w', type: 'boolean', description: 'Do not truncate patterns.' },
|
|
1136
|
+
},
|
|
1137
|
+
examples: ['sentinelctl devices correlate <agent-id> --peak cpu -r 24h', 'sentinelctl devices correlate <agent-id> --at 2026-09-30T14:58:00+09:00 --window 30m -o json'],
|
|
1138
|
+
output: '{at, window, peak?, metrics{<name>: {atValue, min, max, change, biggestStep{at, delta}}}, reboots[], logs{total, levels, groups[]: {source, pattern, count, first, last, latest}}}.',
|
|
1038
1139
|
},
|
|
1039
1140
|
{
|
|
1040
1141
|
group: 'metadata', name: 'get', run: metadataGet, role: 'viewer', mutates: false,
|
|
@@ -1086,8 +1187,9 @@ const commands = [
|
|
|
1086
1187
|
{
|
|
1087
1188
|
group: 'metadata', name: 'import', run: metadataImport, role: 'admin', mutates: true,
|
|
1088
1189
|
summary: 'Import metadata in export format',
|
|
1089
|
-
args: [{ name: 'file' }],
|
|
1190
|
+
args: [{ name: 'file', optional: true, description: 'JSON file from metadata export.' }],
|
|
1090
1191
|
options: {
|
|
1192
|
+
data: { type: 'string', placeholder: 'json', description: 'Export-format JSON given inline instead of a file.' },
|
|
1091
1193
|
'dry-run': { type: 'boolean', description: 'Validate only.' },
|
|
1092
1194
|
conflict: { type: 'string', choices: ['error', 'skip', 'overwrite'], default: 'error', description: 'What to do with devices that already have metadata.' },
|
|
1093
1195
|
},
|
|
@@ -1096,19 +1198,37 @@ const commands = [
|
|
|
1096
1198
|
},
|
|
1097
1199
|
{
|
|
1098
1200
|
group: 'sessions', name: 'list', run: sessionsList, role: 'viewer', mutates: false,
|
|
1099
|
-
summary: 'Your web sessions and
|
|
1201
|
+
summary: 'Your web sessions, CLI tokens and access keys', options: {},
|
|
1100
1202
|
examples: ['sentinelctl sessions list'], output: '{sessions[]: {id, kind, user, clientName, createdAt, lastSeenAt, expiresAt, current}}.',
|
|
1101
1203
|
},
|
|
1102
1204
|
{
|
|
1103
1205
|
group: 'sessions', name: 'revoke', run: sessionsRevoke, role: 'viewer', mutates: true,
|
|
1104
|
-
summary: 'Revoke one of your sessions or
|
|
1206
|
+
summary: 'Revoke one of your sessions, CLI tokens or access keys', args: [{ name: 'session-id' }], options: {},
|
|
1105
1207
|
examples: ['sentinelctl sessions revoke <session-id>'], output: 'Confirmation message.',
|
|
1106
1208
|
},
|
|
1209
|
+
{
|
|
1210
|
+
group: 'access', name: 'create', run: accessCreate, role: 'viewer', mutates: true, mcp: false,
|
|
1211
|
+
summary: 'Create an access key for MCP clients and scripts (shown once)',
|
|
1212
|
+
description: 'The key carries your account and role, works without a browser or CLI login, lasts 30 days and gains 7 more days whenever it is used a week or more after the last extension. Up to 10 keys per person.',
|
|
1213
|
+
args: [{ name: 'name', description: 'A label to recognise the key by, 1-80 characters.' }], options: {},
|
|
1214
|
+
examples: ['sentinelctl access create "Claude Code on laptop"', 'sentinelctl access create ci -o json --select token'],
|
|
1215
|
+
output: '{id, name, createdAt, lastUsedAt, expiresAt, token, mcpUrl}. The token is never shown again.',
|
|
1216
|
+
},
|
|
1217
|
+
{
|
|
1218
|
+
group: 'access', name: 'list', run: accessList, role: 'viewer', mutates: false, mcp: false,
|
|
1219
|
+
summary: 'Your access keys', options: {},
|
|
1220
|
+
examples: ['sentinelctl access list'], output: '{keys[]: {id, name, createdAt, lastUsedAt, expiresAt}}.',
|
|
1221
|
+
},
|
|
1222
|
+
{
|
|
1223
|
+
group: 'access', name: 'revoke', run: accessRevoke, role: 'viewer', mutates: true, mcp: false,
|
|
1224
|
+
summary: 'Revoke one of your access keys now', args: [{ name: 'key-id' }], options: {},
|
|
1225
|
+
examples: ['sentinelctl access revoke <key-id>'], output: 'Confirmation message.',
|
|
1226
|
+
},
|
|
1107
1227
|
{
|
|
1108
1228
|
group: 'admin', name: 'users', run: adminUsers, role: 'admin', mutates: false,
|
|
1109
1229
|
summary: 'Users with their role, where it comes from, and session counts', options: {},
|
|
1110
1230
|
examples: ['sentinelctl admin users -o json'],
|
|
1111
|
-
output: '{users[]: {email, name, effectiveRole, roleSource, grantedRole, disabled, bootstrapAdmin, sessions{web, cli}, lastLoginAt}}.',
|
|
1231
|
+
output: '{users[]: {email, name, effectiveRole, roleSource, grantedRole, disabled, bootstrapAdmin, sessions{web, cli, access}, lastLoginAt}}.',
|
|
1112
1232
|
},
|
|
1113
1233
|
{
|
|
1114
1234
|
group: 'admin', name: 'grant', run: adminGrantCommand({}), role: 'admin', mutates: true,
|
|
@@ -1123,18 +1243,18 @@ const commands = [
|
|
|
1123
1243
|
},
|
|
1124
1244
|
{
|
|
1125
1245
|
group: 'admin', name: 'disable', run: adminGrantCommand({ role: null, disabled: true }), role: 'admin', mutates: true,
|
|
1126
|
-
summary: 'Block access and end all of the user\'s sessions
|
|
1246
|
+
summary: 'Block access and end all of the user\'s sessions, CLI tokens and access keys now', args: [{ name: 'email' }], options: {},
|
|
1127
1247
|
examples: ['sentinelctl admin disable kim@intflow.ai'], output: 'The updated user row. Undo with admin reset.',
|
|
1128
1248
|
},
|
|
1129
1249
|
{
|
|
1130
1250
|
group: 'admin', name: 'sessions', run: adminSessions, role: 'admin', mutates: false,
|
|
1131
|
-
summary: 'All web sessions and
|
|
1132
|
-
options: { kind: { type: 'string', choices: ['web', 'cli'], description: 'Filter by kind.' } },
|
|
1251
|
+
summary: 'All web sessions, CLI tokens and access keys',
|
|
1252
|
+
options: { kind: { type: 'string', choices: ['web', 'cli', 'access'], description: 'Filter by kind.' } },
|
|
1133
1253
|
examples: ['sentinelctl admin sessions --kind cli'], output: '{sessions[]}.',
|
|
1134
1254
|
},
|
|
1135
1255
|
{
|
|
1136
1256
|
group: 'admin', name: 'revoke', run: adminRevokeSession, role: 'admin', mutates: true,
|
|
1137
|
-
summary: 'Revoke anyone\'s session or
|
|
1257
|
+
summary: 'Revoke anyone\'s session, CLI token or access key', args: [{ name: 'session-id' }], options: {},
|
|
1138
1258
|
examples: ['sentinelctl admin revoke <session-id>'], output: 'Confirmation message.',
|
|
1139
1259
|
},
|
|
1140
1260
|
{
|
|
@@ -1171,12 +1291,13 @@ const commands = [
|
|
|
1171
1291
|
|
|
1172
1292
|
export const catalog = commands;
|
|
1173
1293
|
export const groups = {
|
|
1174
|
-
fleet: '
|
|
1175
|
-
logs: '
|
|
1176
|
-
metrics: '
|
|
1177
|
-
devices: 'Device list, details,
|
|
1294
|
+
fleet: 'Fleet briefing',
|
|
1295
|
+
logs: 'Log counts, groups, patterns and raw lines',
|
|
1296
|
+
metrics: 'Fleet-wide metric rankings',
|
|
1297
|
+
devices: 'Device list, details, reception history, metric-log correlation',
|
|
1178
1298
|
metadata: 'Device metadata: read, edit (editor), import/export (admin)',
|
|
1179
1299
|
sessions: 'Your sessions and CLI tokens',
|
|
1300
|
+
access: 'Access keys for MCP clients and scripts',
|
|
1180
1301
|
admin: 'Roles, all sessions, audit clean-up, capacity (admin)',
|
|
1181
1302
|
};
|
|
1182
1303
|
|
package/src/main.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
2
4
|
import { closest, parseArguments, UsageError } from './args.mjs';
|
|
3
5
|
import { ApiError, createClient } from './client.mjs';
|
|
4
6
|
import { catalog, commandPath, findCommand, groups, outputChoices, roleLabels, usageLine } from './commands.mjs';
|
|
@@ -7,14 +9,23 @@ import { renderKeyValues } from './format.mjs';
|
|
|
7
9
|
import { browserLogin, openBrowser } from './login.mjs';
|
|
8
10
|
|
|
9
11
|
const version = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
12
|
+
const userAgent = `sentinelctl/${version} node/${process.versions.node}`;
|
|
13
|
+
const updateCommand = 'npm install -g sentinelctl@latest';
|
|
14
|
+
|
|
15
|
+
function newer(latest, current) {
|
|
16
|
+
const a = latest.split('.').map(Number);
|
|
17
|
+
const b = current.split('.').map(Number);
|
|
18
|
+
for (let index = 0; index < 3; index += 1) if (a[index] !== b[index]) return a[index] > b[index];
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
10
21
|
const roleRank = { viewer: 0, editor: 1, admin: 2 };
|
|
11
|
-
const exitCodes = { 0: 'success', 1: 'server or network error', 2: 'usage error (fix the arguments)', 3: 'not logged in
|
|
22
|
+
const exitCodes = { 0: 'success', 1: 'server or network error', 2: 'usage error (fix the arguments)', 3: 'not logged in, insufficient role or CLI too old (retrying will not help)' };
|
|
12
23
|
const globalDefinitions = {
|
|
13
24
|
server: { type: 'string', placeholder: 'url', description: 'Console URL (default https://monitor.intflow.dev; also SENTINEL_URL).' },
|
|
14
25
|
profile: { type: 'string', placeholder: 'name', description: 'Saved login profile (default "default").' },
|
|
15
26
|
output: { alias: 'o', type: 'string', choices: outputChoices, description: 'Output format. Use json or ndjson from agents and scripts.' },
|
|
16
27
|
json: { type: 'boolean', description: 'Same as -o json.' },
|
|
17
|
-
select: { type: 'string', placeholder: 'fields', description: 'json/ndjson: keep only these
|
|
28
|
+
select: { type: 'string', placeholder: 'fields', description: 'json/ndjson: keep only these fields of each item, e.g. agentId,status,metadata.role.' },
|
|
18
29
|
quiet: { type: 'boolean', description: 'Suppress summaries and hints on stderr (errors are still printed).' },
|
|
19
30
|
help: { alias: 'h', type: 'boolean', description: 'Show help.' },
|
|
20
31
|
version: { alias: 'V', type: 'boolean', description: 'Show the version.' },
|
|
@@ -119,84 +130,57 @@ function overviewHelp() {
|
|
|
119
130
|
return lines.join('\n');
|
|
120
131
|
}
|
|
121
132
|
|
|
122
|
-
const agentGuide = `
|
|
123
|
-
|
|
124
|
-
SETUP
|
|
125
|
-
- A human logs in once (\`sentinelctl login\`, approve in the browser; 30 days). Later commands are
|
|
126
|
-
non-interactive. Elsewhere pass SENTINEL_TOKEN and SENTINEL_URL.
|
|
127
|
-
- Use -o json or -o ndjson. stdout is data only; notes, hints and errors go to stderr (--quiet drops
|
|
128
|
-
notes and hints). A json/ndjson error is one stderr line {"error":{status,code,message,hint,exitCode}}.
|
|
129
|
-
- Exit codes: 0 ok · 1 server/network (retry later) · 2 usage (fix the arguments) · 3 login/role (do
|
|
130
|
-
not retry). \`sentinelctl commands <group> --json\` describes options and output fields.
|
|
131
|
-
|
|
132
|
-
HOW TO INVESTIGATE: broad to narrow, count before you read
|
|
133
|
-
1. Overview fleet summary -o json
|
|
134
|
-
status, attention reasons, busiest devices, trends (disk full soon, temperature
|
|
135
|
-
rises, unusual reboots), error levels, top/rising/falling/new error patterns.
|
|
136
|
-
2. What and where logs stats -l error -r 24h --by message --compare -o json (patterns, change)
|
|
137
|
-
logs groups -l error -r 24h -o json (every device x source x pattern with
|
|
138
|
-
count, first/last time, latest line)
|
|
139
|
-
3. When logs stats -p "<pattern>" --by agent --timeline -r 7d -o json
|
|
140
|
-
logs histogram -a <id> -r 7d -o json
|
|
141
|
-
4. Read a few lines logs search -p "<pattern>" -a <id> -r 24h -n 50 -o json
|
|
142
|
-
logs context -a <id> -s <source> -t <timestamp> (lines around one log)
|
|
143
|
-
5. Device state devices overview <id> -r 7d -o json · devices show <id> --series cpu,memory -o json
|
|
144
|
-
6. Fleet metrics metrics top memory -r 7d · metrics top disk --agg last --above 85
|
|
145
|
-
metrics top diskDaysLeft --below 14 · metrics top cpu --agg p95 --compare
|
|
146
|
-
metrics top reboots -r 7d (most devices reboot daily; compare with p50)
|
|
133
|
+
const agentGuide = `sentinelctl for AI agents
|
|
147
134
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
- Narrow before widening: device (-a), source (-s), service (--service), severity (-l), pattern (-p).
|
|
158
|
-
Start with 1h-24h; widen to 7d or 30d only when you need history.
|
|
159
|
-
- Fleet-wide windows over 7 days need a narrowing filter (-a, -s, --service, -p or -q with
|
|
160
|
-
--case-sensitive); otherwise the server answers 422 log_query_too_broad.
|
|
161
|
-
Single-device, single-service and single-pattern queries can use the whole retention period
|
|
162
|
-
(31 days by default).
|
|
163
|
-
- Windows over one day are aggregated per day and finished days are cached: repeating a long query
|
|
164
|
-
is cheap, and the CLI continues automatically if the server needs several requests. A partial
|
|
165
|
-
result says so in complete/coverage.
|
|
166
|
-
- To watch for new logs, poll with --since <nextSince from the previous run>, not --follow.
|
|
167
|
-
- --dedupe folds lines repeated within the same second (the agent writes some messages twice).
|
|
168
|
-
- Levels: emergency/critical/error include more severe levels; warning, info and debug are exact.
|
|
169
|
-
- Applications are found by source (-s: systemd unit, container) on one device, or by the service
|
|
170
|
-
label (--service, --env) across devices when the collector sets it; logs stats --by service ranks them.
|
|
135
|
+
Setup A human runs \`sentinelctl login\` once (30 days), or set SENTINEL_URL and SENTINEL_TOKEN
|
|
136
|
+
(an access key from \`sentinelctl access create <name>\` works and renews itself while used).
|
|
137
|
+
MCP The same commands are remote MCP tools at <server>/api/mcp/ with the header
|
|
138
|
+
Authorization: Bearer <access key>. Nothing to install; the server updates the tools.
|
|
139
|
+
Output Use -o json. stdout is data; notes, hints and errors go to stderr (--quiet drops notes).
|
|
140
|
+
Errors One stderr line {"error":{status,code,message,hint,exitCode}}; messages are Korean, hints English.
|
|
141
|
+
Exit 0 ok · 1 server/network (retry later) · 2 usage (fix arguments) · 3 login/role/too old (stop).
|
|
142
|
+
Updates A stderr {"notice":{"type":"update_available",…}} line means a newer CLI exists; tell the user.
|
|
143
|
+
Help sentinelctl <command> --help · sentinelctl commands <group> --json
|
|
171
144
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
145
|
+
Workflow: broad to narrow, count before reading
|
|
146
|
+
1. fleet summary status, attention, trends, error patterns
|
|
147
|
+
2. logs stats -l error -r 24h --by message --compare which patterns, what changed
|
|
148
|
+
logs groups -l error -r 24h device x source x pattern, latest line
|
|
149
|
+
3. logs stats -p "<pattern>" --by agent --timeline who and since when
|
|
150
|
+
devices correlate <id> --peak cpu metrics and logs around a spike
|
|
151
|
+
4. logs search -p "<pattern>" -a <id> -n 50 a few raw lines (logs context for neighbors)
|
|
152
|
+
Metrics: metrics top <metric>, e.g. memory -r 7d · disk --agg last · diskDaysLeft · reboots
|
|
176
153
|
|
|
177
|
-
|
|
178
|
-
-
|
|
179
|
-
|
|
154
|
+
Rules
|
|
155
|
+
- Never count or summarize by downloading: logs search stops at 10,000 lines (minutes of this
|
|
156
|
+
fleet); logs stats and logs groups count the whole window.
|
|
157
|
+
- Pass patterns to -p exactly as printed (<N> = number). -q is a case-insensitive word match.
|
|
158
|
+
- Narrow first (-a, -s, --service, -l, -p) and start with 1h-24h. Fleet-wide windows over 7 days
|
|
159
|
+
need one of -a, -s, --service, -p or --case-sensitive (else 422 log_query_too_broad); narrowed
|
|
160
|
+
queries reach 31 days. Long aggregations are cached per day and continue automatically.
|
|
161
|
+
- Run commands one at a time: per user 2 log queries at once and 60s of log time per minute
|
|
162
|
+
(429 is retried automatically). Poll with --since <nextSince>, never --follow.
|
|
163
|
+
- Keep output small: --select a,b.c · devices show --series none.
|
|
164
|
+
- Commands that change data (metadata, admin): --dry-run first. Viewer tokens are read-only.`;
|
|
180
165
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
- Server error messages are Korean (shared with the web console); hints are English.`;
|
|
166
|
+
function compact(record) {
|
|
167
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && value !== null && !(Array.isArray(value) && !value.length)));
|
|
168
|
+
}
|
|
185
169
|
|
|
186
170
|
function commandsCatalog(selected = null) {
|
|
187
171
|
return {
|
|
188
172
|
version,
|
|
189
|
-
globalOptions: globalDefinitions,
|
|
173
|
+
globalOptions: Object.fromEntries(Object.entries(globalDefinitions).map(([name, spec]) => [name, compact(spec)])),
|
|
190
174
|
exitCodes,
|
|
191
175
|
commands: [
|
|
192
|
-
...(selected ? [] : Object.entries(specialCommands).map(([name, command]) => ({ command: name, usage: command.usage, summary: command.summary,
|
|
193
|
-
...(selected ?? catalog).map((command) => ({
|
|
194
|
-
command: commandPath(command), usage: usageLine(command), summary: command.summary, description: command.description
|
|
195
|
-
role: command.role, roleNote: command.roleNote
|
|
196
|
-
options: Object.fromEntries(Object.entries(command.options).map(([name, spec]) => [name, {
|
|
197
|
-
alias: spec.alias
|
|
198
|
-
multiple:
|
|
199
|
-
}])),
|
|
176
|
+
...(selected ? [] : Object.entries(specialCommands).map(([name, command]) => ({ command: name, usage: command.usage, summary: command.summary, mutates: name === 'logout' }))),
|
|
177
|
+
...(selected ?? catalog).map((command) => compact({
|
|
178
|
+
command: commandPath(command), usage: usageLine(command), summary: command.summary, description: command.description,
|
|
179
|
+
role: command.role, roleNote: command.roleNote, mutates: command.mutates, args: command.args,
|
|
180
|
+
options: Object.fromEntries(Object.entries(command.options).map(([name, spec]) => [name, compact({
|
|
181
|
+
alias: spec.alias, type: spec.type, choices: spec.choices, default: spec.default,
|
|
182
|
+
multiple: spec.multiple || undefined, description: spec.description,
|
|
183
|
+
})])),
|
|
200
184
|
examples: command.examples, output: command.output,
|
|
201
185
|
})),
|
|
202
186
|
],
|
|
@@ -205,7 +189,7 @@ function commandsCatalog(selected = null) {
|
|
|
205
189
|
|
|
206
190
|
async function login(context, argv) {
|
|
207
191
|
const { options } = parseArguments(argv, { 'no-browser': { type: 'boolean' }, name: { type: 'string' } });
|
|
208
|
-
const client = createClient({ server: context.connection.server, fetch: context.fetch });
|
|
192
|
+
const client = createClient({ server: context.connection.server, fetch: context.fetch, userAgent });
|
|
209
193
|
const result = await browserLogin(client, {
|
|
210
194
|
clientName: options.name,
|
|
211
195
|
launchBrowser: !options['no-browser'],
|
|
@@ -240,6 +224,21 @@ async function logout(context) {
|
|
|
240
224
|
context.out(removed ? 'Logged out.' : 'No saved login to remove.');
|
|
241
225
|
}
|
|
242
226
|
|
|
227
|
+
async function noticeUpdate(context, environment) {
|
|
228
|
+
const latest = context?.versions?.latest;
|
|
229
|
+
if (!latest || !newer(latest, version) || environment.SENTINELCTL_NO_UPDATE_NOTICE) return;
|
|
230
|
+
const path = join(dirname(context.connection.path), 'update-notice.json');
|
|
231
|
+
let last = {};
|
|
232
|
+
try { last = JSON.parse(await readFile(path, 'utf8')); } catch {}
|
|
233
|
+
if (last.latest === latest && Date.now() - (last.at ?? 0) < 86_400_000) return;
|
|
234
|
+
const message = `sentinelctl ${latest} is available (you have ${version}). Update: ${updateCommand}`;
|
|
235
|
+
context.err(context.global.output === 'table' ? `notice: ${message}` : JSON.stringify({ notice: { type: 'update_available', current: version, latest, command: updateCommand } }));
|
|
236
|
+
try {
|
|
237
|
+
await mkdir(dirname(path), { recursive: true });
|
|
238
|
+
await writeFile(path, JSON.stringify({ latest, at: Date.now() }), { mode: 0o600 });
|
|
239
|
+
} catch {}
|
|
240
|
+
}
|
|
241
|
+
|
|
243
242
|
async function rememberRole(context, role) {
|
|
244
243
|
const saved = context.connection.profile;
|
|
245
244
|
if (!saved || context.connection.fromEnvironment || saved.role === role) return;
|
|
@@ -254,13 +253,14 @@ async function whoami(context) {
|
|
|
254
253
|
const identity = await context.client.get('/api/session');
|
|
255
254
|
await rememberRole(context, identity.role);
|
|
256
255
|
if (context.global.output === 'json' || context.global.output === 'ndjson') {
|
|
257
|
-
context.out(JSON.stringify({ server: context.connection.server, ...identity, tokenExpiresAt: context.connection.profile?.expiresAt ?? null }));
|
|
256
|
+
context.out(JSON.stringify({ server: context.connection.server, ...identity, tokenExpiresAt: context.connection.profile?.expiresAt ?? null, cli: { version, latest: context.versions?.latest ?? null } }));
|
|
258
257
|
return;
|
|
259
258
|
}
|
|
260
259
|
context.out(renderKeyValues([
|
|
261
260
|
['Server', context.connection.server], ['User', identity.user], ['Name', identity.name],
|
|
262
261
|
['Role', roleLabels[identity.role] ?? identity.role], ['Token ID', identity.sessionId],
|
|
263
262
|
['Token expires', context.connection.profile?.expiresAt],
|
|
263
|
+
['CLI', `${version}${context.versions?.latest ? ` (latest ${context.versions.latest})` : ''}`],
|
|
264
264
|
]));
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -299,6 +299,7 @@ function apiHint(error, context, command) {
|
|
|
299
299
|
? 'Check the agent ID with `sentinelctl devices lookup <part of the name>`.' : 'Not found; check the ID.';
|
|
300
300
|
}
|
|
301
301
|
if (error.status === 409) return 'Someone saved a change first. Run the command again to apply on top of the latest revision.';
|
|
302
|
+
if (error.code === 'cli_upgrade_required') return `Update the CLI: ${updateCommand} (or @intflow/sentinelctl@latest), then rerun.`;
|
|
302
303
|
if (error.code === 'log_query_too_broad') {
|
|
303
304
|
return 'Narrow it: add -a <agent-id>, -s <source>, --service <name>, -p "<pattern>" (from `logs stats --by message`) or --case-sensitive with -q, or use a window of 7 days or less.';
|
|
304
305
|
}
|
|
@@ -412,7 +413,7 @@ export async function main(argv, {
|
|
|
412
413
|
select: global.select ? global.select.split(',').map((field) => field.trim()).filter(Boolean) : null,
|
|
413
414
|
hint: (text) => { if (!global.quiet) err(`hint: ${text}`); },
|
|
414
415
|
note: (text) => { if (!global.quiet && global.output === 'table') err(text); },
|
|
415
|
-
client: createClient({ server: connection.server, token: connection.token, fetch, sleep }),
|
|
416
|
+
client: createClient({ server: connection.server, token: connection.token, fetch, sleep, userAgent, onVersions: (versions) => { context.versions = versions; } }),
|
|
416
417
|
};
|
|
417
418
|
if (name === 'login') { await login(context, commandArgv); return 0; }
|
|
418
419
|
if (name === 'logout') { await logout(context); return 0; }
|
|
@@ -438,9 +439,11 @@ export async function main(argv, {
|
|
|
438
439
|
`Ask an admin to run \`sentinelctl admin grant <your-email> --role ${error.required}\`. Nothing was sent to the server.`, 3);
|
|
439
440
|
}
|
|
440
441
|
if (error instanceof ApiError) {
|
|
441
|
-
const exitCode = error.status === 401 || error.status === 403 || error.code === 'not_logged_in' ? 3 : 1;
|
|
442
|
+
const exitCode = error.status === 401 || error.status === 403 || error.status === 426 || error.code === 'not_logged_in' ? 3 : 1;
|
|
442
443
|
return report(error, apiHint(error, context ?? { connection: {} }, command), exitCode);
|
|
443
444
|
}
|
|
444
445
|
return report(error, null, 1);
|
|
446
|
+
} finally {
|
|
447
|
+
if (context) await noticeUpdate(context, environment);
|
|
445
448
|
}
|
|
446
449
|
}
|