@intflow/sentinelctl 0.7.1 → 0.9.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 +48 -8
- package/package.json +1 -1
- package/src/commands.mjs +454 -13
- package/src/main.mjs +19 -2
package/README.md
CHANGED
|
@@ -36,11 +36,13 @@ Credentials live in `~/.config/sentinelctl/credentials.json` (Linux/macOS) or `%
|
|
|
36
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
37
|
|
|
38
38
|
```bash
|
|
39
|
-
sentinelctl access create "work laptop"
|
|
40
|
-
sentinelctl access
|
|
39
|
+
sentinelctl access create "work laptop" # read key, printed once
|
|
40
|
+
sentinelctl access create "metadata bot" --access full # may also change data
|
|
41
|
+
sentinelctl access list # shows the ACCESS level
|
|
41
42
|
sentinelctl access revoke <key-id>
|
|
42
43
|
```
|
|
43
44
|
|
|
45
|
+
- Every key has one level, chosen when it is created and never changed: `read` (the default) runs only commands that do not change data; `full` runs everything your role allows. With a read key, MCP lists only read-only tools and the server answers a request that changes data with 403 `read_only_key` (exit code 3). For another level, create a new key.
|
|
44
46
|
- 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
47
|
- Up to 10 keys per person. Keys are created and revoked only from a web or CLI login, never with another key.
|
|
46
48
|
- The key stops working when you revoke it or an admin disables your account. A role change applies on the next request.
|
|
@@ -54,7 +56,7 @@ The console serves every command of this CLI as a remote MCP tool at `/api/mcp/`
|
|
|
54
56
|
{ "mcpServers": { "sentinel": { "type": "http", "url": "https://monitor.intflow.dev/api/mcp/", "headers": { "Authorization": "Bearer sentinel_..." } } } }
|
|
55
57
|
```
|
|
56
58
|
|
|
57
|
-
Clients that register servers by command take the same two values, for example `claude mcp add --transport http sentinel https://monitor.intflow.dev/api/mcp/ --header "Authorization: Bearer sentinel_..."`. Tools are named `sentinel_<group>_<command>` (for example `sentinel_logs_stats`) and take the same options; the tool list contains only what your role
|
|
59
|
+
Clients that register servers by command take the same two values, for example `claude mcp add --transport http sentinel https://monitor.intflow.dev/api/mcp/ --header "Authorization: Bearer sentinel_..."`. Tools are named `sentinel_<group>_<command>` (for example `sentinel_logs_stats`) and take the same options; the tool list contains only what your role and the key level allow. The same key also works as `SENTINEL_TOKEN` for this CLI.
|
|
58
60
|
|
|
59
61
|
## Getting help
|
|
60
62
|
|
|
@@ -148,6 +150,42 @@ sentinelctl admin operations -r 7d
|
|
|
148
150
|
|
|
149
151
|
Any other endpoint: `sentinelctl api "/api/devices?status=offline"`.
|
|
150
152
|
|
|
153
|
+
## Event sources and the event specification
|
|
154
|
+
|
|
155
|
+
Monitors, applications and infrastructure that send `intflow.event.v1` events are registered as sources. Reading is open to every role; changes need `admin` (and a `full` key when you use an access key).
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
sentinelctl events schema -o json # JSON Schema, reason codes and example events
|
|
159
|
+
sentinelctl sources list # stage, expected reporting and key state per source
|
|
160
|
+
sentinelctl sources show nas-super-monitor -o json # key expiry state, never the key itself
|
|
161
|
+
sentinelctl sources register nas-super-monitor --nature monitor --name "NAS SUPER" --category incident \
|
|
162
|
+
--subject nas:nas-super --every 60 --legacy-room mon --critical availability_lost
|
|
163
|
+
sentinelctl sources update app-backup --cron "1 3 * * *" --grace 3600
|
|
164
|
+
sentinelctl sources update db-monitor --clear runbook
|
|
165
|
+
sentinelctl sources stage nas-super-monitor shadow --reason "parallel run starts"
|
|
166
|
+
sentinelctl sources retire edgefarm-efc-stale-mail --reason "merged"
|
|
167
|
+
sentinelctl sources keys issue nas-super-monitor # sfauto_ key, events:write, 365 days, shown once
|
|
168
|
+
sentinelctl sources keys issue nas-super-monitor --replace
|
|
169
|
+
sentinelctl sources keys revoke nas-super-monitor
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
- A new source starts at stage `store`. `sources stage` moves one step at a time along `store → shadow → live → cut_over`, or one step back.
|
|
173
|
+
- `--every` (seconds) or `--cron` with `--grace` (five cron fields in KST, seconds of grace) set the expected reporting. `--critical` replaces the list of critical checks.
|
|
174
|
+
- One valid write key per source. It writes events for that source only, expires after 365 days and shows `expiring` in `sources list` and `sources show` from 30 days before. `sources retire` revokes it at once.
|
|
175
|
+
- `sources keys issue` is not offered as an MCP tool so that a key is never shown inside an AI conversation; use the CLI.
|
|
176
|
+
|
|
177
|
+
Received events (server v1.15.0 or newer, with event ingest switched on) can be searched and checked per source:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
sentinelctl events search --source nas-super-monitor --range 7d # newest received first, default 24h, up to 200
|
|
181
|
+
sentinelctl events search --kind incident --state firing --severity critical -o json
|
|
182
|
+
sentinelctl events search --subject nas-super --check availability_lost --from 2026-11-01T00:00:00+09:00 --to 2026-11-02T00:00:00+09:00
|
|
183
|
+
sentinelctl events freshness # age of the last accepted event per source and kind
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
- Search covers the events tenant only and stays inside the VictoriaLogs retention (about 3 months); a wider window is refused with `range_beyond_retention`. Time filters use the time Sentinel received the event.
|
|
187
|
+
- Each result is `{receivedAt, event}` with the event exactly as sent; select fields with `--select receivedAt,event.summary`.
|
|
188
|
+
|
|
151
189
|
## Updates
|
|
152
190
|
|
|
153
191
|
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.
|
|
@@ -161,10 +199,12 @@ The server tells the CLI the latest version; when a newer one exists the CLI pri
|
|
|
161
199
|
|
|
162
200
|
## Publishing
|
|
163
201
|
|
|
164
|
-
|
|
202
|
+
Keep both package versions, the alias dependency and `config/dashboard.json`'s `cliLatestVersion` equal; `node scripts/check-cli-release.mjs` checks them.
|
|
203
|
+
|
|
204
|
+
1. Run `gh workflow run publish-cli.yml --repo yeon3724/intflow-sentinel --ref main -f publish=false`. The self-hosted runner checks versions, tests and both pack contents without publishing.
|
|
205
|
+
2. From that clean, verified commit, run `npm pack --pack-destination <absolute-output-directory>` in `cli/` and `cli/unscoped/`. Keep the commit and tarball checksums with the artifacts. A maintainer signs in with `npm login --auth-type=web` and publishes the scoped tarball with `npm publish <tarball> --access public`, completing npm's 2FA approval. Confirm its exact version with `npm view @intflow/sentinelctl@0.9.0 version`, then publish and confirm the alias tarball the same way.
|
|
206
|
+
3. After both exact versions are public, create the immutable annotated tag on that verified commit: `git tag -a cli-v0.9.0 <verified-commit> -m 'Sentinel CLI 0.9.0'`, then `git push origin cli-v0.9.0`.
|
|
165
207
|
|
|
166
|
-
|
|
167
|
-
2. Commit, then push a tag: `git tag cli-v0.7.1 && git push origin cli-v0.7.1`.
|
|
168
|
-
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.
|
|
208
|
+
A tag always runs the self-hosted checks. If both exact package versions are public, the hosted publisher is skipped. A missing version or uncertain registry lookup keeps the existing trusted-publishing path: scoped package, registry confirmation, then alias; versions already present are skipped. This path needs a GitHub-hosted runner. For each package, npm Settings → Trusted Publisher must use `yeon3724`, repository `intflow-sentinel`, workflow `publish-cli.yml`, environment `npm`; verify the settings after a repository rename.
|
|
169
209
|
|
|
170
|
-
|
|
210
|
+
Updating the NAS Compose `DASHBOARD_CLI_LATEST_VERSION` pin is a separate deployment step, after both packages are public.
|
package/package.json
CHANGED
package/src/commands.mjs
CHANGED
|
@@ -57,7 +57,7 @@ function logCriteria(options, positionals) {
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
const listKeys = ['devices', 'logs', 'groups', 'buckets', 'sources', 'sessions', 'users', 'history', 'results', 'attention'];
|
|
60
|
+
const listKeys = ['devices', 'logs', 'groups', 'buckets', 'sources', 'sessions', 'users', 'history', 'results', 'attention', 'events'];
|
|
61
61
|
|
|
62
62
|
function pick(item, paths) {
|
|
63
63
|
if (!item || typeof item !== 'object') return item;
|
|
@@ -602,7 +602,8 @@ async function health(context) {
|
|
|
602
602
|
const body = await context.client.get('/api/health');
|
|
603
603
|
emit(context, body, () => [
|
|
604
604
|
renderKeyValues([['Overall', body.status], ['Version', `${body.application?.version} (${body.application?.commit})`],
|
|
605
|
-
['Observer', body.observer?.status ?? body.observer?.state]
|
|
605
|
+
['Observer', body.observer?.status ?? body.observer?.state],
|
|
606
|
+
['Events', body.events ? `ingest ${body.events.ingest}, ${body.events.status}${body.events.settings?.length ? ` (${body.events.settings.join(', ')})` : ''}${body.events.lastFailureCode && body.events.status === 'error' ? ` (${body.events.lastFailureCode})` : ''}` : undefined]]),
|
|
606
607
|
'',
|
|
607
608
|
renderTable(Object.entries(body.components ?? {}), [
|
|
608
609
|
{ header: 'COMPONENT', value: ([name]) => name },
|
|
@@ -612,6 +613,9 @@ async function health(context) {
|
|
|
612
613
|
], { width: context.width }),
|
|
613
614
|
].join('\n'));
|
|
614
615
|
if (body.status !== 'ok') context.hint('Some backends are unhealthy; results may be stale or empty.');
|
|
616
|
+
if (body.events?.status === 'misconfigured') {
|
|
617
|
+
context.hint(`Event ingest is forced off by invalid settings${body.events.settings?.length ? `: ${body.events.settings.join(', ')}` : ''}. Device monitoring is not affected.`);
|
|
618
|
+
}
|
|
615
619
|
}
|
|
616
620
|
|
|
617
621
|
async function metadataGet(context, { positionals }) {
|
|
@@ -785,6 +789,7 @@ async function sessionsRevoke(context, { positionals }) {
|
|
|
785
789
|
const accessKeyColumns = [
|
|
786
790
|
{ header: 'ID', value: (key) => key.id },
|
|
787
791
|
{ header: 'NAME', value: (key) => key.name, max: 32 },
|
|
792
|
+
{ header: 'ACCESS', value: (key) => key.access ?? '-' },
|
|
788
793
|
{ header: 'CREATED', value: (key) => localTime(key.createdAt) },
|
|
789
794
|
{ header: 'LAST USED', value: (key) => (key.lastUsedAt ? localTime(key.lastUsedAt) : 'never') },
|
|
790
795
|
{ header: 'EXPIRES', value: (key) => localTime(key.expiresAt) },
|
|
@@ -797,13 +802,13 @@ async function accessList(context) {
|
|
|
797
802
|
: 'No access keys. Create one with `sentinelctl access create <name>`.'));
|
|
798
803
|
}
|
|
799
804
|
|
|
800
|
-
async function accessCreate(context, { positionals }) {
|
|
805
|
+
async function accessCreate(context, { options, positionals }) {
|
|
801
806
|
const name = positionals.join(' ').trim();
|
|
802
807
|
if (!name) throw new UsageError('A key name is required.', { hint: 'Example: sentinelctl access create "work laptop"' });
|
|
803
|
-
const key = await context.client.post('/api/access', { name });
|
|
808
|
+
const key = await context.client.post('/api/access', { name, access: options.access });
|
|
804
809
|
const mcpUrl = new URL('/api/mcp/', context.client.server).href;
|
|
805
810
|
emit(context, { ...key, mcpUrl }, () => [
|
|
806
|
-
renderKeyValues([['Name', key.name], ['ID', key.id], ['Expires', localTime(key.expiresAt)], ['MCP URL', mcpUrl]]),
|
|
811
|
+
renderKeyValues([['Name', key.name], ['ID', key.id], ['Access', key.access], ['Expires', localTime(key.expiresAt)], ['MCP URL', mcpUrl]]),
|
|
807
812
|
'',
|
|
808
813
|
key.token,
|
|
809
814
|
].join('\n'));
|
|
@@ -901,6 +906,289 @@ async function rawApi(context, { options, positionals }) {
|
|
|
901
906
|
context.out(JSON.stringify(project(result.body, context.select), null, 2));
|
|
902
907
|
}
|
|
903
908
|
|
|
909
|
+
const sourceNatures = ['monitor', 'application', 'infrastructure'];
|
|
910
|
+
const sourceCategories = ['incident', 'report', 'both'];
|
|
911
|
+
const sourceStages = ['store', 'shadow', 'live', 'cut_over'];
|
|
912
|
+
const legacyRooms = ['svc', 'db', 'mon', 'efc', 'haenuri', 'proto'];
|
|
913
|
+
const sourceTextFields = { nature: 'nature', name: 'name', category: 'category', subject: 'subjectRef', owner: 'ownerRef', 'legacy-room': 'legacyRoom', runbook: 'runbook' };
|
|
914
|
+
const sourceClearFields = { subject: 'subjectRef', owner: 'ownerRef', expected: 'expected', 'legacy-room': 'legacyRoom', runbook: 'runbook', critical: 'criticalChecks' };
|
|
915
|
+
const sourceFieldOptions = {
|
|
916
|
+
nature: { type: 'string', choices: sourceNatures, description: 'What kind of sender this is.' },
|
|
917
|
+
name: { type: 'string', placeholder: 'text', description: 'Display name, 1-120 characters (Korean is fine).' },
|
|
918
|
+
category: { type: 'string', choices: sourceCategories, description: 'incident, report or both.' },
|
|
919
|
+
subject: { type: 'string', placeholder: 'kind:id', description: 'What it watches, e.g. nas:nas-super (kind as in event subject.kind).' },
|
|
920
|
+
owner: { type: 'string', placeholder: 'role', description: 'Owner role reference from the INFRA portal; never a person.' },
|
|
921
|
+
every: { type: 'integer', placeholder: 'seconds', description: 'Expected reporting interval, 10-86400 seconds.' },
|
|
922
|
+
cron: { type: 'string', placeholder: 'cron', description: 'Expected schedule as five cron fields in KST, with --grace.' },
|
|
923
|
+
grace: { type: 'integer', placeholder: 'seconds', description: 'Allowed delay after each --cron run, 60-86400 seconds.' },
|
|
924
|
+
'legacy-room': { type: 'string', choices: legacyRooms, description: 'Current Slack room code until cut-over.' },
|
|
925
|
+
runbook: { type: 'string', placeholder: 'url', description: 'Runbook URL (http or https).' },
|
|
926
|
+
critical: { type: 'string', multiple: true, placeholder: 'check', description: 'Critical check name; the given list replaces the old one.' },
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
function requireSourceId(positionals) {
|
|
930
|
+
if (!positionals[0]) throw new UsageError('A source ID is required.', { hint: 'List them with `sentinelctl sources list`.' });
|
|
931
|
+
return positionals[0];
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function sourcePath(id, suffix = '') {
|
|
935
|
+
return `/api/sources/${encodeURIComponent(id)}${suffix}`;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
function sourceBody(options) {
|
|
939
|
+
const body = {};
|
|
940
|
+
for (const [option, field] of Object.entries(sourceTextFields)) if (options[option] !== undefined) body[field] = options[option];
|
|
941
|
+
if (options.critical !== undefined) body.criticalChecks = options.critical;
|
|
942
|
+
if (options.every !== undefined && (options.cron !== undefined || options.grace !== undefined)) {
|
|
943
|
+
throw new UsageError('Give either --every or --cron with --grace, not both.');
|
|
944
|
+
}
|
|
945
|
+
if ((options.cron === undefined) !== (options.grace === undefined)) throw new UsageError('--cron and --grace go together.');
|
|
946
|
+
if (options.every !== undefined) body.expected = { everySeconds: options.every };
|
|
947
|
+
if (options.cron !== undefined) body.expected = { cron: options.cron, graceSeconds: options.grace };
|
|
948
|
+
for (const option of options.clear ?? []) {
|
|
949
|
+
if (body[sourceClearFields[option]] !== undefined) throw new UsageError(`--clear ${option} cannot be combined with a new value for it.`);
|
|
950
|
+
body[sourceClearFields[option]] = option === 'critical' ? [] : null;
|
|
951
|
+
}
|
|
952
|
+
return body;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
function expectedText(expected) {
|
|
956
|
+
if (!expected) return '-';
|
|
957
|
+
return expected.everySeconds !== undefined ? `every ${expected.everySeconds}s` : `${expected.cron} +${expected.graceSeconds}s`;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
function keyText(key) {
|
|
961
|
+
if (!key || key.state === 'none') return 'none';
|
|
962
|
+
return key.state === 'active' || key.state === 'expiring' ? `${key.state} (${key.daysLeft}d left)` : key.state;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
const sourceColumns = [
|
|
966
|
+
{ header: 'ID', value: (source) => source.id, max: 32 },
|
|
967
|
+
{ header: 'NATURE', value: (source) => source.nature },
|
|
968
|
+
{ header: 'STAGE', value: (source) => (source.retired ? 'retired' : source.stage) },
|
|
969
|
+
{ header: 'CATEGORY', value: (source) => source.category },
|
|
970
|
+
{ header: 'ROOM', value: (source) => source.legacyRoom ?? '-' },
|
|
971
|
+
{ header: 'EXPECTED', value: (source) => expectedText(source.expected), max: 28 },
|
|
972
|
+
{ header: 'KEY', value: (source) => keyText(source.key) },
|
|
973
|
+
{ header: 'NAME', value: (source) => source.name },
|
|
974
|
+
];
|
|
975
|
+
|
|
976
|
+
function sourceDetails(source) {
|
|
977
|
+
return renderKeyValues([
|
|
978
|
+
['ID', source.id], ['Name', source.name], ['Nature', source.nature], ['Category', source.category],
|
|
979
|
+
['Stage', `${source.retired ? 'retired, was ' : ''}${source.stage} (since ${localTime(source.stageChangedAt)})`],
|
|
980
|
+
['Subject', source.subjectRef], ['Owner', source.ownerRef], ['Expected', expectedText(source.expected)],
|
|
981
|
+
['Legacy room', source.legacyRoom], ['Runbook', source.runbook], ['Critical checks', source.criticalChecks.join(', ')],
|
|
982
|
+
['Key', `${keyText(source.key)}${source.key?.expiresAt ? `, expires ${localTime(source.key.expiresAt)}` : ''}`],
|
|
983
|
+
['Revision', source.revision], ['Updated', source.updatedAt],
|
|
984
|
+
...(source.portal ? portalSourceRows(source.portal) : []),
|
|
985
|
+
]);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
function routeText(route) {
|
|
989
|
+
if (!route) return '-';
|
|
990
|
+
return `${route.id} (${route.critical ? 'critical' : route.defaultDecision}, owner ${route.ownerRole}${route.sms ? `, SMS ${route.smsRoles.join('+')}` : ''})`;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
function portalSourceRows(portal) {
|
|
994
|
+
return [
|
|
995
|
+
['Portal copy', localTime(portal.copiedAt)], ['Portal asset', portal.asset ? `${portal.asset.ref} (${portal.asset.kind ?? '-'})` : '-'],
|
|
996
|
+
['Portal owner', portal.owner ? `${portal.owner.role} ${portal.owner.label}` : '-'], ['Portal route', routeText(portal.route)],
|
|
997
|
+
...portal.critical.map((item) => [`Route ${item.check}`, routeText(item.route)]),
|
|
998
|
+
...(portal.mismatches.length ? [['Mismatches', portal.mismatches.map((item) => `${item.kind} ${item.check ?? ''}`.trim()).join(', ')]] : []),
|
|
999
|
+
];
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function statusText(part) {
|
|
1003
|
+
return `${part.status}${part.reasons ? ` (${part.reasons.join(', ')})` : ''}`;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
async function portalStatus(context) {
|
|
1007
|
+
const body = await context.client.get('/api/portal');
|
|
1008
|
+
const mismatches = body.comparison?.mismatches ?? [];
|
|
1009
|
+
emit(context, body, () => [
|
|
1010
|
+
renderKeyValues([
|
|
1011
|
+
['Copy', statusText(body.sync)], ['Copied', localTime(body.sync.copiedAt)], ['Checked', localTime(body.sync.checkedAt)],
|
|
1012
|
+
['Assets', body.sync.assets ?? '-'], ['Routes', body.sync.routes ?? '-'], ['Portal SMS switch', body.sync.smsSending ?? '-'],
|
|
1013
|
+
]),
|
|
1014
|
+
...(mismatches.length ? ['', 'Critical checks vs portal routes:', renderTable(mismatches, [
|
|
1015
|
+
{ header: 'KIND', value: (item) => item.kind }, { header: 'SOURCE', value: (item) => item.source ?? '-' },
|
|
1016
|
+
{ header: 'CHECK', value: (item) => item.check ?? '-' }, { header: 'ROUTE', value: (item) => item.route ?? '-' },
|
|
1017
|
+
], { width: context.width })] : []),
|
|
1018
|
+
].join('\n'));
|
|
1019
|
+
if (body.sync.state === 'off') context.hint('The portal copy is off on this server (PORTAL_SYNC_ENABLED).');
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
async function portalSync(context, { options }) {
|
|
1023
|
+
if (!options.now) throw new UsageError('Add --now to fetch the portal copy immediately.', { hint: 'The copy is otherwise refreshed every 5 minutes.' });
|
|
1024
|
+
const body = await context.client.post('/api/portal/sync', {});
|
|
1025
|
+
emit(context, body, () => renderKeyValues([
|
|
1026
|
+
['Copy', statusText(body.sync)], ['Copied', localTime(body.sync.copiedAt)], ['Checked', localTime(body.sync.checkedAt)],
|
|
1027
|
+
['Assets', body.sync.assets ?? '-'], ['Routes', body.sync.routes ?? '-'],
|
|
1028
|
+
]));
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
async function assetsShow(context, { positionals }) {
|
|
1032
|
+
if (!positionals[0]) throw new UsageError('An asset name is required.', { hint: 'Find it in `sentinelctl sources show <id>` (Portal asset).' });
|
|
1033
|
+
const body = await context.client.get(`/api/assets/${encodeURIComponent(positionals[0])}`);
|
|
1034
|
+
emit(context, body, () => renderKeyValues([
|
|
1035
|
+
['Asset', body.ref], ['Kind', body.kind], ['Category', body.category], ['Group', body.group], ['Purpose', body.purpose], ['Parent', body.parent],
|
|
1036
|
+
['Children', body.children.join(', ') || '-'], ['Addresses', body.addresses.map((address) => `${address.kind} ${address.value}`).join(', ') || '-'],
|
|
1037
|
+
['Sources', body.sources.map((source) => source.id).join(', ') || '-'], ['Portal copy', localTime(body.copiedAt)],
|
|
1038
|
+
]));
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
async function sourcesList(context, { options }) {
|
|
1042
|
+
const body = await context.client.get('/api/sources', { nature: options.nature, stage: options.stage, category: options.category, all: options.all ? 1 : undefined });
|
|
1043
|
+
emit(context, context.global.output === 'ndjson' ? body.sources : body, () => (body.sources.length
|
|
1044
|
+
? renderTable(body.sources, sourceColumns, { width: context.width })
|
|
1045
|
+
: 'No sources registered.'));
|
|
1046
|
+
const expiring = body.sources.filter((source) => ['expiring', 'expired'].includes(source.key?.state)).length;
|
|
1047
|
+
if (expiring) context.hint(`${expiring} source key(s) expire within 30 days or have expired; issue a new one with \`sentinelctl sources keys issue <id> --replace\`.`);
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
async function sourcesShow(context, { positionals }) {
|
|
1051
|
+
const body = await context.client.get(sourcePath(requireSourceId(positionals)));
|
|
1052
|
+
emit(context, body, () => sourceDetails(body));
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
async function sourcesRegister(context, { options, positionals }) {
|
|
1056
|
+
const id = requireSourceId(positionals);
|
|
1057
|
+
for (const option of ['nature', 'name', 'category']) {
|
|
1058
|
+
if (options[option] === undefined) throw new UsageError(`--${option} is required.`, { hint: 'Example: sentinelctl sources register nas-super-monitor --nature monitor --name "NAS SUPER" --category incident --every 60' });
|
|
1059
|
+
}
|
|
1060
|
+
const body = await context.client.post('/api/sources', { id, ...sourceBody(options) });
|
|
1061
|
+
emit(context, body, () => `Registered ${body.id} at stage ${body.stage}.`);
|
|
1062
|
+
context.hint(`Issue its write key with \`sentinelctl sources keys issue ${body.id}\`.`);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
async function sourcesUpdate(context, { options, positionals }) {
|
|
1066
|
+
const id = requireSourceId(positionals);
|
|
1067
|
+
const changes = sourceBody(options);
|
|
1068
|
+
if (!Object.keys(changes).length) throw new UsageError('Nothing to change. Give at least one field option.', { hint: 'All fields: sentinelctl sources update --help' });
|
|
1069
|
+
const current = await context.client.get(sourcePath(id));
|
|
1070
|
+
const body = await context.client.patch(sourcePath(id), { revision: current.revision, ...changes });
|
|
1071
|
+
emit(context, body, () => `Saved ${body.id} as revision ${body.revision}.`);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
async function sourcesStage(context, { options, positionals }) {
|
|
1075
|
+
const id = requireSourceId(positionals);
|
|
1076
|
+
const stage = positionals[1];
|
|
1077
|
+
if (!sourceStages.includes(stage)) throw new UsageError(`The stage must be one of ${sourceStages.join(', ')}.`, { hint: 'Stages move one step at a time: store → shadow → live → cut_over.' });
|
|
1078
|
+
const current = await context.client.get(sourcePath(id));
|
|
1079
|
+
const body = await context.client.post(sourcePath(id, '/stage'), { stage, revision: current.revision, ...(options.reason ? { reason: options.reason } : {}) });
|
|
1080
|
+
emit(context, body, () => `${body.id}: ${current.stage} → ${body.stage}.`);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
async function sourcesRetire(context, { options, positionals }) {
|
|
1084
|
+
const id = requireSourceId(positionals);
|
|
1085
|
+
if (!options.reason) throw new UsageError('--reason is required.');
|
|
1086
|
+
const current = await context.client.get(sourcePath(id));
|
|
1087
|
+
const body = await context.client.post(sourcePath(id, '/retire'), { revision: current.revision, reason: options.reason });
|
|
1088
|
+
emit(context, body, () => `Retired ${body.id}; its write key, if any, is revoked.`);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
async function sourcesKeysIssue(context, { options, positionals }) {
|
|
1092
|
+
const id = requireSourceId(positionals);
|
|
1093
|
+
const body = await context.client.post(sourcePath(id, '/key'), { replace: Boolean(options.replace) });
|
|
1094
|
+
emit(context, body, () => [
|
|
1095
|
+
renderKeyValues([['Source', body.sourceId], ['Key ID', body.key.id], ['Scope', body.key.scope], ['Expires', localTime(body.key.expiresAt)]]),
|
|
1096
|
+
'',
|
|
1097
|
+
body.token,
|
|
1098
|
+
].join('\n'));
|
|
1099
|
+
context.hint('Shown once; put it in the source\'s key file now. It writes events for this source only and expires in 365 days.');
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
async function sourcesKeysRevoke(context, { positionals }) {
|
|
1103
|
+
const id = requireSourceId(positionals);
|
|
1104
|
+
const body = (await context.client.request('DELETE', sourcePath(id, '/key'))).body;
|
|
1105
|
+
emit(context, body, () => `Revoked the write key ${body.key.id} of ${body.sourceId}.`);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
async function eventsSchema(context) {
|
|
1109
|
+
const body = await context.client.get('/api/events/v1/schema');
|
|
1110
|
+
emit(context, body, () => JSON.stringify(body, null, 2));
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
const eventKinds = ['incident', 'report', 'heartbeat', 'change'];
|
|
1114
|
+
const eventSeverities = ['critical', 'warning', 'info'];
|
|
1115
|
+
const eventStates = ['firing', 'resolved'];
|
|
1116
|
+
const eventRanges = ['15m', '1h', '6h', '24h', '7d', '30d', '90d'];
|
|
1117
|
+
const eventLimit = 200;
|
|
1118
|
+
|
|
1119
|
+
const eventColumns = [
|
|
1120
|
+
{ header: 'RECEIVED', value: (item) => localTime(item.receivedAt), max: 19 },
|
|
1121
|
+
{ header: 'KIND', value: (item) => item.event.kind, max: 9 },
|
|
1122
|
+
{ header: 'SEVERITY', value: (item) => item.event.severity, max: 8 },
|
|
1123
|
+
{ header: 'SOURCE', value: (item) => item.event.source?.id, max: 28 },
|
|
1124
|
+
{ header: 'SUBJECT', value: (item) => item.event.subject?.id ?? '-', max: 24 },
|
|
1125
|
+
{ header: 'STATE', value: (item) => item.event.state ?? '-', max: 8 },
|
|
1126
|
+
{ header: 'SUMMARY', value: (item) => `${item.event.test ? '[test] ' : ''}${item.event.summary}` },
|
|
1127
|
+
];
|
|
1128
|
+
|
|
1129
|
+
const freshnessColumns = [
|
|
1130
|
+
{ header: 'SOURCE', value: (source) => source.id, max: 32 },
|
|
1131
|
+
{ header: 'STAGE', value: (source) => source.stage },
|
|
1132
|
+
{ header: 'EXPECTED', value: (source) => expectedText(source.expected), max: 28 },
|
|
1133
|
+
{ header: 'LAST', value: (source) => source.last?.kind ?? '-' },
|
|
1134
|
+
{ header: 'AGE', value: (source) => (source.last ? ageText(source.last.ageSeconds) : 'never') },
|
|
1135
|
+
{ header: 'RECEIVED', value: (source) => localTime(source.last?.receivedAt) },
|
|
1136
|
+
];
|
|
1137
|
+
|
|
1138
|
+
async function eventsSearch(context, { options }) {
|
|
1139
|
+
if ((options.from && !options.to) || (!options.from && options.to)) {
|
|
1140
|
+
throw new UsageError('--from and --to must be given together.', { hint: 'For a recent window use --range, e.g. --range 24h.' });
|
|
1141
|
+
}
|
|
1142
|
+
if (options.from && options.range) throw new UsageError('--range cannot be combined with --from/--to.');
|
|
1143
|
+
for (const [name, value] of [['from', options.from], ['to', options.to]]) {
|
|
1144
|
+
if (value && !Number.isFinite(Date.parse(value))) {
|
|
1145
|
+
throw new UsageError(`Cannot parse --${name}: ${value}`, { hint: 'Use ISO 8601 with a zone, e.g. 2026-11-13T09:00:00+09:00.' });
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (options.limit !== undefined && (options.limit < 1 || options.limit > eventLimit)) throw new UsageError(`--limit must be between 1 and ${eventLimit}.`);
|
|
1149
|
+
const body = await context.client.get('/api/events/v1/search', {
|
|
1150
|
+
source: options.source, kind: options.kind, subject: options.subject, check: options.check, state: options.state, severity: options.severity,
|
|
1151
|
+
range: options.range,
|
|
1152
|
+
from: options.from ? new Date(options.from).toISOString() : undefined,
|
|
1153
|
+
to: options.to ? new Date(options.to).toISOString() : undefined,
|
|
1154
|
+
limit: options.limit,
|
|
1155
|
+
});
|
|
1156
|
+
emit(context, context.global.output === 'ndjson' ? body.events : body, () => (body.events.length
|
|
1157
|
+
? renderTable(body.events, eventColumns, { width: context.width, wide: options.wide })
|
|
1158
|
+
: 'No events matched.'));
|
|
1159
|
+
if (body.events.length) context.note(`${body.count} events · ${localTime(body.window.start)} → ${localTime(body.window.end)}`);
|
|
1160
|
+
if (body.hasMore) context.hint(`More events match. Narrow the filters or raise --limit (up to ${eventLimit}).`);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
async function eventsFreshness(context) {
|
|
1164
|
+
const body = await context.client.get('/api/events/v1/freshness');
|
|
1165
|
+
emit(context, context.global.output === 'ndjson' ? body.sources : body, () => (body.sources.length
|
|
1166
|
+
? renderTable(body.sources, freshnessColumns, { width: context.width })
|
|
1167
|
+
: 'No sources registered.'));
|
|
1168
|
+
if (!body.ingest.enabled) context.hint('Event ingest is off on this server; sources keep their events in the spool until it is turned on.');
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
const changeColumns = [
|
|
1172
|
+
{ header: 'RECEIVED', value: (item) => localTime(item.receivedAt), max: 19 },
|
|
1173
|
+
{ header: 'SOURCE', value: (item) => item.event.source?.id, max: 28 },
|
|
1174
|
+
{ header: 'SUBJECT', value: (item) => item.event.subject?.id ?? '', max: 24 },
|
|
1175
|
+
{ header: 'TYPE', value: (item) => item.event.change?.type ?? '', max: 12 },
|
|
1176
|
+
{ header: 'RESULT', value: (item) => item.event.change?.result ?? '', max: 10 },
|
|
1177
|
+
{ header: 'SUMMARY', value: (item) => item.event.summary },
|
|
1178
|
+
];
|
|
1179
|
+
|
|
1180
|
+
async function changesRecent(context, { options }) {
|
|
1181
|
+
if (options.limit !== undefined && (options.limit < 1 || options.limit > eventLimit)) throw new UsageError(`--limit must be between 1 and ${eventLimit}.`);
|
|
1182
|
+
const body = await context.client.get('/api/changes/recent', {
|
|
1183
|
+
source: options.source, subject: options.subject, agent: options.agent, range: options.range, limit: options.limit,
|
|
1184
|
+
});
|
|
1185
|
+
emit(context, body, () => [
|
|
1186
|
+
body.events.length ? renderTable(body.events, changeColumns, { width: context.width, wide: options.wide }) : 'No change events matched.',
|
|
1187
|
+
...(body.metadata ? ['', `Metadata history of ${body.metadata.agentId}: ${body.metadata.history.length} entries (-o json shows them).`] : []),
|
|
1188
|
+
].join('\n'));
|
|
1189
|
+
if (body.hasMore) context.hint(`More change events match. Narrow the filters or raise --limit (up to ${eventLimit}).`);
|
|
1190
|
+
}
|
|
1191
|
+
|
|
904
1192
|
const commands = [
|
|
905
1193
|
{
|
|
906
1194
|
group: 'logs', name: 'search', run: logsSearch, role: 'viewer', mutates: false,
|
|
@@ -1066,10 +1354,11 @@ const commands = [
|
|
|
1066
1354
|
{
|
|
1067
1355
|
group: 'devices', name: 'overview', run: devicesOverview, role: 'viewer', mutates: false,
|
|
1068
1356
|
summary: 'Reception state, outage counts and durations, and attention reasons for one device',
|
|
1357
|
+
description: 'The answer includes the device metadata: lifecycle (active, maintenance, retired), maintenanceUntil and maintenanceReason. A maintenance whose maintenanceUntil has passed counts as active.',
|
|
1069
1358
|
args: [{ name: 'agent-id' }],
|
|
1070
1359
|
options: { range: { alias: 'r', type: 'string', default: '24h', placeholder: 'window', description: 'History window, e.g. 24h or 7d.' } },
|
|
1071
1360
|
examples: ['sentinelctl devices overview <agent-id> -r 7d -o json'],
|
|
1072
|
-
output: '{summary{metrics, logs}: {state, outages, delays, missingMinutes, longestOutageMinutes, normalRatio}, agentId, device, products, attentionReasons[], history, related{parent, children[], expectedParent}}.',
|
|
1361
|
+
output: '{summary{metrics, logs}: {state, outages, delays, missingMinutes, longestOutageMinutes, normalRatio}, agentId, metadata{displayName, role, lifecycle, maintenanceUntil, maintenanceReason, ...}, device, products, attentionReasons[], history, related{parent, children[], expectedParent}}.',
|
|
1073
1362
|
},
|
|
1074
1363
|
{
|
|
1075
1364
|
group: 'metrics', name: 'top', run: metricsTop, role: 'viewer', mutates: false,
|
|
@@ -1209,15 +1498,18 @@ const commands = [
|
|
|
1209
1498
|
{
|
|
1210
1499
|
group: 'access', name: 'create', run: accessCreate, role: 'viewer', mutates: true, mcp: false,
|
|
1211
1500
|
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.' }],
|
|
1214
|
-
|
|
1215
|
-
|
|
1501
|
+
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. A read key runs only commands that do not change data; the level is fixed when the key is created.',
|
|
1502
|
+
args: [{ name: 'name', description: 'A label to recognise the key by, 1-80 characters.' }],
|
|
1503
|
+
options: {
|
|
1504
|
+
access: { type: 'string', choices: ['read', 'full'], default: 'read', description: 'read: only commands that do not change data; full: everything your role allows.' },
|
|
1505
|
+
},
|
|
1506
|
+
examples: ['sentinelctl access create "work laptop"', 'sentinelctl access create "metadata bot" --access full', 'sentinelctl access create ci -o json --select token'],
|
|
1507
|
+
output: '{id, name, access, createdAt, lastUsedAt, expiresAt, token, mcpUrl}. The token is never shown again.',
|
|
1216
1508
|
},
|
|
1217
1509
|
{
|
|
1218
1510
|
group: 'access', name: 'list', run: accessList, role: 'viewer', mutates: false, mcp: false,
|
|
1219
1511
|
summary: 'Your access keys', options: {},
|
|
1220
|
-
examples: ['sentinelctl access list'], output: '{keys[]: {id, name, createdAt, lastUsedAt, expiresAt}}.',
|
|
1512
|
+
examples: ['sentinelctl access list'], output: '{keys[]: {id, name, access, createdAt, lastUsedAt, expiresAt}}.',
|
|
1221
1513
|
},
|
|
1222
1514
|
{
|
|
1223
1515
|
group: 'access', name: 'revoke', run: accessRevoke, role: 'viewer', mutates: true, mcp: false,
|
|
@@ -1258,7 +1550,7 @@ const commands = [
|
|
|
1258
1550
|
examples: ['sentinelctl admin revoke <session-id>'], output: 'Confirmation message.',
|
|
1259
1551
|
},
|
|
1260
1552
|
{
|
|
1261
|
-
group: 'admin', name: 'audit', run: adminAudit, role: 'admin', mutates:
|
|
1553
|
+
group: 'admin', name: 'audit', run: adminAudit, role: 'admin', mutates: true,
|
|
1262
1554
|
summary: 'Metadata audit clean-up records; run the clean-up now',
|
|
1263
1555
|
options: {
|
|
1264
1556
|
cleanup: { type: 'boolean', description: 'Apply the retention policy now (default 365 days / 64 MiB).' },
|
|
@@ -1278,7 +1570,7 @@ const commands = [
|
|
|
1278
1570
|
examples: ['sentinelctl health -o json'], output: '{status, application, components{metrics, logs, metadata}: {status, latencyMs}}.',
|
|
1279
1571
|
},
|
|
1280
1572
|
{
|
|
1281
|
-
group: null, name: 'api', run: rawApi, role: 'viewer', mutates:
|
|
1573
|
+
group: null, name: 'api', run: rawApi, role: 'viewer', mutates: true,
|
|
1282
1574
|
summary: 'Call a console API directly (JSON output; the server enforces roles)',
|
|
1283
1575
|
args: [{ name: 'path', description: 'Starts with /api/.' }],
|
|
1284
1576
|
options: {
|
|
@@ -1287,6 +1579,150 @@ const commands = [
|
|
|
1287
1579
|
},
|
|
1288
1580
|
examples: ['sentinelctl api "/api/devices?status=offline&pageSize=5"'], output: 'The server response JSON as is.',
|
|
1289
1581
|
},
|
|
1582
|
+
{
|
|
1583
|
+
group: 'sources', name: 'list', run: sourcesList, role: 'viewer', mutates: false,
|
|
1584
|
+
summary: 'Registered event sources with stage, expected reporting and key state',
|
|
1585
|
+
options: {
|
|
1586
|
+
nature: { type: 'string', choices: sourceNatures, description: 'Only this nature.' },
|
|
1587
|
+
stage: { type: 'string', choices: sourceStages, description: 'Only this stage.' },
|
|
1588
|
+
category: { type: 'string', choices: sourceCategories, description: 'Only this category.' },
|
|
1589
|
+
all: { type: 'boolean', description: 'Include retired sources.' },
|
|
1590
|
+
},
|
|
1591
|
+
examples: ['sentinelctl sources list', 'sentinelctl sources list --stage live -o json'],
|
|
1592
|
+
output: '{sources[]: {id, nature, name, subjectRef, ownerRef, expected, category, legacyRoom, stage, runbook, criticalChecks, retired, revision, key{state, expiresAt, daysLeft}}}.',
|
|
1593
|
+
},
|
|
1594
|
+
{
|
|
1595
|
+
group: 'sources', name: 'show', run: sourcesShow, role: 'viewer', mutates: false,
|
|
1596
|
+
summary: 'One event source: owner, runbook, expected reporting, stage and key expiry',
|
|
1597
|
+
description: 'Key state is none, active, expiring (30 days or less left), expired or revoked; key material is never shown.',
|
|
1598
|
+
args: [{ name: 'source-id' }], options: {},
|
|
1599
|
+
examples: ['sentinelctl sources show nas-super-monitor -o json'],
|
|
1600
|
+
output: '{id, nature, name, subjectRef, ownerRef, expected{everySeconds | cron, graceSeconds}, category, legacyRoom, stage, stageChangedAt, runbook, criticalChecks[], retired, retiredAt, revision, createdAt, updatedAt, key{id, state, scope, createdAt, expiresAt, daysLeft, revokedAt}, portal?{copiedAt, asset, owner, route, critical[]: {check, route}, mismatches[]} (only while the portal copy is on)}.',
|
|
1601
|
+
},
|
|
1602
|
+
{
|
|
1603
|
+
group: 'sources', name: 'register', run: sourcesRegister, role: 'admin', mutates: true,
|
|
1604
|
+
summary: 'Register an event source at stage store',
|
|
1605
|
+
args: [{ name: 'source-id', description: 'Lowercase letters, digits and hyphens, 2-64 characters; used as source.id in events.' }],
|
|
1606
|
+
options: sourceFieldOptions,
|
|
1607
|
+
examples: ['sentinelctl sources register nas-super-monitor --nature monitor --name "NAS SUPER" --category incident --subject nas:nas-super --every 60 --legacy-room mon --critical availability_lost'],
|
|
1608
|
+
output: 'The registered source (same shape as sources show).',
|
|
1609
|
+
},
|
|
1610
|
+
{
|
|
1611
|
+
group: 'sources', name: 'update', run: sourcesUpdate, role: 'admin', mutates: true,
|
|
1612
|
+
summary: 'Change registry fields of an event source (reads the latest revision first)',
|
|
1613
|
+
args: [{ name: 'source-id' }],
|
|
1614
|
+
options: { ...sourceFieldOptions, clear: { type: 'string', multiple: true, choices: Object.keys(sourceClearFields), description: 'Clear a field.' } },
|
|
1615
|
+
examples: ['sentinelctl sources update db-monitor --owner role:db-operators --runbook https://runbook.example/db', 'sentinelctl sources update app-backup --cron "1 3 * * *" --grace 3600'],
|
|
1616
|
+
output: 'The saved source (same shape as sources show).',
|
|
1617
|
+
},
|
|
1618
|
+
{
|
|
1619
|
+
group: 'sources', name: 'stage', run: sourcesStage, role: 'admin', mutates: true,
|
|
1620
|
+
summary: 'Move a source one step: store → shadow → live → cut_over, or one step back',
|
|
1621
|
+
args: [{ name: 'source-id' }, { name: 'stage', description: 'store, shadow, live or cut_over.' }],
|
|
1622
|
+
options: { reason: { type: 'string', placeholder: 'text', description: 'Why, kept in the audit record (max 200 chars).' } },
|
|
1623
|
+
examples: ['sentinelctl sources stage nas-super-monitor shadow --reason "parallel run starts"'],
|
|
1624
|
+
output: 'The saved source (same shape as sources show).',
|
|
1625
|
+
},
|
|
1626
|
+
{
|
|
1627
|
+
group: 'sources', name: 'retire', run: sourcesRetire, role: 'admin', mutates: true,
|
|
1628
|
+
summary: 'Retire an event source and revoke its write key',
|
|
1629
|
+
args: [{ name: 'source-id' }],
|
|
1630
|
+
options: { reason: { type: 'string', placeholder: 'text', description: 'Why (required, max 200 chars).' } },
|
|
1631
|
+
examples: ['sentinelctl sources retire edgefarm-efc-stale-mail --reason "merged into edgefarm-device-monitor"'],
|
|
1632
|
+
output: 'The retired source (same shape as sources show).',
|
|
1633
|
+
},
|
|
1634
|
+
{
|
|
1635
|
+
group: 'sources', name: 'keys issue', run: sourcesKeysIssue, role: 'admin', mutates: true, mcp: false,
|
|
1636
|
+
summary: 'Issue the write key of a source (events:write, 365 days, shown once)',
|
|
1637
|
+
description: 'One valid key per source. With --replace the current key is revoked at once and a new one is issued.',
|
|
1638
|
+
args: [{ name: 'source-id' }],
|
|
1639
|
+
options: { replace: { type: 'boolean', description: 'Revoke the current valid key and issue a new one.' } },
|
|
1640
|
+
examples: ['sentinelctl sources keys issue nas-super-monitor', 'sentinelctl sources keys issue nas-super-monitor --replace -o json --select token'],
|
|
1641
|
+
output: '{sourceId, key{id, state, scope, createdAt, expiresAt, daysLeft}, token}. The token is never shown again.',
|
|
1642
|
+
},
|
|
1643
|
+
{
|
|
1644
|
+
group: 'sources', name: 'keys revoke', run: sourcesKeysRevoke, role: 'admin', mutates: true,
|
|
1645
|
+
summary: 'Revoke the write key of a source now',
|
|
1646
|
+
args: [{ name: 'source-id' }], options: {},
|
|
1647
|
+
examples: ['sentinelctl sources keys revoke nas-super-monitor'],
|
|
1648
|
+
output: '{sourceId, key{id, state: revoked, revokedAt}}.',
|
|
1649
|
+
},
|
|
1650
|
+
{
|
|
1651
|
+
group: 'events', name: 'schema', run: eventsSchema, role: 'viewer', mutates: false,
|
|
1652
|
+
summary: 'The intflow.event.v1 specification: JSON Schema, reason codes and example events',
|
|
1653
|
+
options: {},
|
|
1654
|
+
examples: ['sentinelctl events schema -o json --select reasonCodes', 'sentinelctl events schema -o json'],
|
|
1655
|
+
output: '{name, maxBytes, reasonCodes[], schema (JSON Schema 2020-12), examples[]}.',
|
|
1656
|
+
},
|
|
1657
|
+
{
|
|
1658
|
+
group: 'events', name: 'search', run: eventsSearch, role: 'viewer', mutates: false,
|
|
1659
|
+
summary: 'Raw monitoring events (incident, report, heartbeat, change), newest received first',
|
|
1660
|
+
description: 'Searches the events tenant only, within the VictoriaLogs retention (about 3 months). Time filters use the time Sentinel received the event. An event_id stored twice shows once.',
|
|
1661
|
+
options: {
|
|
1662
|
+
source: { type: 'string', placeholder: 'source-id', description: 'Registry source ID (see sources list).' },
|
|
1663
|
+
kind: { type: 'string', choices: eventKinds, description: 'Event kind.' },
|
|
1664
|
+
subject: { type: 'string', placeholder: 'id', description: 'subject.id, e.g. nas-super.' },
|
|
1665
|
+
check: { type: 'string', placeholder: 'name', description: 'Incident check name, e.g. availability_lost.' },
|
|
1666
|
+
state: { type: 'string', choices: eventStates, description: 'Incident state.' },
|
|
1667
|
+
severity: { type: 'string', choices: eventSeverities, description: 'Severity reported by the source.' },
|
|
1668
|
+
range: { type: 'string', choices: eventRanges, description: 'Relative window by receive time (default 24h).' },
|
|
1669
|
+
from: { type: 'string', placeholder: 'ISO', description: 'Start, e.g. 2026-11-13T09:00:00+09:00 (with --to).' },
|
|
1670
|
+
to: { type: 'string', placeholder: 'ISO', description: 'End.' },
|
|
1671
|
+
limit: { alias: 'n', type: 'integer', placeholder: 'N', description: `Events to return (1-${eventLimit}, default 50).` },
|
|
1672
|
+
wide: { alias: 'w', type: 'boolean', description: 'Do not truncate.' },
|
|
1673
|
+
},
|
|
1674
|
+
examples: [
|
|
1675
|
+
'sentinelctl events search --source nas-super-monitor --range 7d',
|
|
1676
|
+
'sentinelctl events search --kind incident --state firing --severity critical -o json',
|
|
1677
|
+
'sentinelctl events search --subject nas-super --check availability_lost --range 30d -o json --select receivedAt,event.summary',
|
|
1678
|
+
],
|
|
1679
|
+
output: '{criteria, window{start, end}, retentionDays, count, hasMore, events[]: {receivedAt, event (as sent, intflow.event.v1)}}.',
|
|
1680
|
+
},
|
|
1681
|
+
{
|
|
1682
|
+
group: 'events', name: 'freshness', run: eventsFreshness, role: 'viewer', mutates: false,
|
|
1683
|
+
summary: 'Per source: age of the last accepted event and the expected reporting interval',
|
|
1684
|
+
description: 'Ages count from the time Sentinel accepted the event. Retired sources are left out.',
|
|
1685
|
+
options: {},
|
|
1686
|
+
examples: ['sentinelctl events freshness', 'sentinelctl events freshness -o json --select id,expected,last'],
|
|
1687
|
+
output: '{generatedAt, ingest{enabled}, sources[]: {id, nature, name, category, stage, expected, last{kind, eventId, observedAt, receivedAt, ageSeconds} | null, kinds{<kind>: {eventId, observedAt, receivedAt, ageSeconds}}}}.',
|
|
1688
|
+
},
|
|
1689
|
+
{
|
|
1690
|
+
group: 'changes', name: 'recent', run: changesRecent, role: 'viewer', mutates: false,
|
|
1691
|
+
summary: 'Change events (deploys, settings, approvals) by source or subject, newest first, and the metadata history of one device',
|
|
1692
|
+
description: 'Change events come from the events tenant within its retention (about 3 months). With --agent the existing metadata history of that device is added.',
|
|
1693
|
+
options: {
|
|
1694
|
+
source: { type: 'string', placeholder: 'source-id', description: 'Registry source ID.' },
|
|
1695
|
+
subject: { type: 'string', placeholder: 'id', description: 'subject.id of the change.' },
|
|
1696
|
+
agent: { type: 'string', placeholder: 'agent-id', description: 'Also return the metadata history of this device.' },
|
|
1697
|
+
range: { type: 'string', choices: eventRanges, description: 'Relative window by receive time (default 7d).' },
|
|
1698
|
+
limit: { alias: 'n', type: 'integer', placeholder: 'N', description: `Events to return (1-${eventLimit}, default 50).` },
|
|
1699
|
+
wide: { alias: 'w', type: 'boolean', description: 'Do not truncate.' },
|
|
1700
|
+
},
|
|
1701
|
+
examples: ['sentinelctl changes recent --subject nas-super', 'sentinelctl changes recent --source app-deploy --range 30d -o json'],
|
|
1702
|
+
output: '{criteria, window{start, end}, retentionDays, count, hasMore, events[]: {receivedAt, event}, metadata{agentId, history[]} | null}.',
|
|
1703
|
+
},
|
|
1704
|
+
{
|
|
1705
|
+
group: 'portal', name: 'status', run: portalStatus, role: 'viewer', mutates: false,
|
|
1706
|
+
summary: 'Portal copy (assets, owners, recipient roles, routes, SMS switch) and critical check mismatches',
|
|
1707
|
+
description: 'The copy is pulled from the INFRA portal every 5 minutes; a failed pull keeps the last copy and shows the reason. Mismatches compare every registered critical check with the portal route that wins for it, and every critical portal route with the registered owners of its check.',
|
|
1708
|
+
options: {},
|
|
1709
|
+
examples: ['sentinelctl portal status', 'sentinelctl portal status -o json'],
|
|
1710
|
+
output: '{sync{state, status: off|misconfigured|waiting|ok|stale|error, reasons?, copiedAt, checkedAt, ageSeconds, assets, routes, smsSending, mismatches}, comparison{mismatches[]: {kind: not_critical_in_portal|no_registered_owner|unknown_source, source, check, route}} | null}.',
|
|
1711
|
+
},
|
|
1712
|
+
{
|
|
1713
|
+
group: 'portal', name: 'sync', run: portalSync, role: 'admin', mutates: true,
|
|
1714
|
+
summary: 'Fetch the portal copy now instead of waiting for the 5-minute pull',
|
|
1715
|
+
options: { now: { type: 'boolean', description: 'Fetch now (required).' } },
|
|
1716
|
+
examples: ['sentinelctl portal sync --now'],
|
|
1717
|
+
output: '{sync} (same shape as portal status sync, with admin fields).',
|
|
1718
|
+
},
|
|
1719
|
+
{
|
|
1720
|
+
group: 'assets', name: 'show', run: assetsShow, role: 'viewer', mutates: false,
|
|
1721
|
+
summary: 'One asset of the portal copy: kind, category, parent, children, addresses and the sources that watch it',
|
|
1722
|
+
args: [{ name: 'asset-ref', description: 'Asset name in the portal, e.g. the id part of a source subject.' }], options: {},
|
|
1723
|
+
examples: ['sentinelctl assets show nas-super -o json'],
|
|
1724
|
+
output: '{ref, kind, category, group, purpose, parent, addresses[]: {kind, value}, children[], sources[]: {id, name, stage, retired}, copiedAt}.',
|
|
1725
|
+
},
|
|
1290
1726
|
];
|
|
1291
1727
|
|
|
1292
1728
|
export const catalog = commands;
|
|
@@ -1299,6 +1735,11 @@ export const groups = {
|
|
|
1299
1735
|
sessions: 'Your sessions and CLI tokens',
|
|
1300
1736
|
access: 'Access keys for MCP clients and scripts',
|
|
1301
1737
|
admin: 'Roles, all sessions, audit clean-up, capacity (admin)',
|
|
1738
|
+
sources: 'Event sources: registry, stages and write keys (changes: admin)',
|
|
1739
|
+
events: 'Monitoring events: specification, search and per-source freshness',
|
|
1740
|
+
changes: 'Change events and device metadata history',
|
|
1741
|
+
portal: 'INFRA portal copy and route comparison (sync: admin)',
|
|
1742
|
+
assets: 'Assets of the INFRA portal copy',
|
|
1302
1743
|
};
|
|
1303
1744
|
|
|
1304
1745
|
export function findCommand(group, name) {
|
package/src/main.mjs
CHANGED
|
@@ -290,6 +290,9 @@ function apiHint(error, context, command) {
|
|
|
290
290
|
? 'SENTINEL_TOKEN has expired or was revoked; supply a new token.'
|
|
291
291
|
: 'The CLI token has expired or was revoked. Run `sentinelctl login` again.';
|
|
292
292
|
}
|
|
293
|
+
if (error.code === 'read_only_key') {
|
|
294
|
+
return 'This access key is read-only. For commands that change data, create a key with `sentinelctl access create <name> --access full` or on the web CLI · MCP page.';
|
|
295
|
+
}
|
|
293
296
|
if (error.status === 403) {
|
|
294
297
|
const required = command ? roleOf(command, context.options ?? {}) : null;
|
|
295
298
|
return `Insufficient role${required && required !== 'viewer' ? ` (requires ${required})` : ''}. Ask an admin to run \`sentinelctl admin grant <your-email> --role <role>\`; check yours with \`sentinelctl whoami\`.`;
|
|
@@ -298,6 +301,13 @@ function apiHint(error, context, command) {
|
|
|
298
301
|
return command?.group === 'devices' || command?.group === 'metadata'
|
|
299
302
|
? 'Check the agent ID with `sentinelctl devices lookup <part of the name>`.' : 'Not found; check the ID.';
|
|
300
303
|
}
|
|
304
|
+
if (error.code === 'source_key_exists') return 'The source already has a valid write key. Add --replace to revoke it and issue a new one.';
|
|
305
|
+
if (error.code === 'source_exists') return 'A source with this ID is already registered; change it with `sentinelctl sources update`.';
|
|
306
|
+
if (error.code === 'source_retired') return 'A retired source is final; register a new source ID instead.';
|
|
307
|
+
if (error.code === 'stage_step') return 'Stages move one step at a time: store → shadow → live → cut_over (or one step back).';
|
|
308
|
+
if (error.code === 'incident_not_active') return 'The incident is already resolved; nothing to acknowledge.';
|
|
309
|
+
if (error.code === 'incident_acknowledged') return 'The incident was already acknowledged.';
|
|
310
|
+
if (error.code === 'silence_inactive') return 'That silence has already ended or been expired; see `sentinelctl silences list --all`.';
|
|
301
311
|
if (error.status === 409) return 'Someone saved a change first. Run the command again to apply on top of the latest revision.';
|
|
302
312
|
if (error.code === 'cli_upgrade_required') return `Update the CLI: ${updateCommand} (or @intflow/sentinelctl@latest), then rerun.`;
|
|
303
313
|
if (error.code === 'log_query_too_broad') {
|
|
@@ -361,7 +371,9 @@ export async function main(argv, {
|
|
|
361
371
|
else if (specialCommands[subcommand]) out(`Usage: ${specialCommands[subcommand].usage}\n\n${specialCommands[subcommand].summary}`);
|
|
362
372
|
else if (groups[subcommand] && !commandArguments[0]) out(groupHelp(subcommand));
|
|
363
373
|
else {
|
|
364
|
-
const target = groups[subcommand]
|
|
374
|
+
const target = groups[subcommand]
|
|
375
|
+
? findCommand(subcommand, commandArguments[0]) ?? findCommand(subcommand, commandArguments.slice(0, 2).join(' '))
|
|
376
|
+
: findCommand(null, subcommand);
|
|
365
377
|
if (!target) {
|
|
366
378
|
throw unknownCommandError([subcommand, commandArguments[0]].filter(Boolean).join(' '),
|
|
367
379
|
[...Object.keys(groups), ...Object.keys(specialCommands), ...catalog.filter((item) => !item.group).map((item) => item.name), 'agents'], 'help ');
|
|
@@ -386,8 +398,13 @@ export async function main(argv, {
|
|
|
386
398
|
return 0;
|
|
387
399
|
}
|
|
388
400
|
|
|
401
|
+
let consumed = 0;
|
|
389
402
|
if (groups[name]) {
|
|
390
403
|
command = findCommand(name, subcommand);
|
|
404
|
+
if (!command && subcommand && commandArguments.length) {
|
|
405
|
+
command = findCommand(name, `${subcommand} ${commandArguments[0]}`);
|
|
406
|
+
if (command) consumed = 1;
|
|
407
|
+
}
|
|
391
408
|
if (!command) {
|
|
392
409
|
if (!subcommand || wantsHelp) {
|
|
393
410
|
out(groupHelp(name));
|
|
@@ -399,7 +416,7 @@ export async function main(argv, {
|
|
|
399
416
|
command = findCommand(null, name);
|
|
400
417
|
if (!command) throw unknownCommandError(name, [...Object.keys(groups), ...Object.keys(specialCommands), ...catalog.filter((item) => !item.group).map((item) => item.name)]);
|
|
401
418
|
}
|
|
402
|
-
const commandArgv = command?.group ? commandArguments : [subcommand, ...commandArguments].filter((item) => item !== undefined);
|
|
419
|
+
const commandArgv = command?.group ? commandArguments.slice(consumed) : [subcommand, ...commandArguments].filter((item) => item !== undefined);
|
|
403
420
|
if (command && wantsHelp) {
|
|
404
421
|
out(commandHelp(command));
|
|
405
422
|
return 0;
|