@ejouan/lxray 1.2.0 → 1.2.2

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.
Files changed (2) hide show
  1. package/README.md +367 -115
  2. package/package.json +9 -4
package/README.md CHANGED
@@ -1,182 +1,434 @@
1
1
  # @ejouan/lxray
2
2
 
3
- Node.js SDK for **LXRAY**, the X-ray for Linux servers. Run LXRAY audits from your own application
4
- (monitoring platform, management console, managed-services portal, internal tool) and get a scored
5
- report with the evidence and the fix for every finding: on one machine, as root on demand without your
6
- app being root, or over SSH across a whole fleet.
3
+ **Linux server audits from your Node.js application.** `@ejouan/lxray` is the official Node.js SDK for
4
+ [LXRAY](https://jouan.us/upstream/en/lxray/), the X-ray for Linux servers: one call reads the real state
5
+ of a machine (disks, RAID, network, firewall, services, security, logs, databases, containers,
6
+ applications) and returns a scored report with the evidence and the fix for every finding.
7
7
 
8
- - Zero dependencies. Audits run on Linux (the package installs anywhere, so you can develop on Windows or macOS). Node.js 18 or later. Python 3.6+ on the audited machine (for the analysis).
9
- - No shell is ever spawned with your values: no command injection, locally or over SSH.
10
- - Reports stay on your infrastructure: LXRAY contacts nobody.
8
+ Use it to add server health to a monitoring dashboard, a management console, a managed-services portal,
9
+ an internal admin, a CI pipeline or an alerting job: on the server your app runs on, or across a whole fleet
10
+ over SSH.
11
11
 
12
- LXRAY itself is installed from the signed repositories at https://jouan.us/upstream/packages
13
- (apt, dnf, zypper) or with `install()` (user-space copy, GPG-verified).
12
+ [![npm](https://img.shields.io/npm/v/@ejouan/lxray.svg)](https://www.npmjs.com/package/@ejouan/lxray)
13
+ ![node](https://img.shields.io/node/v/@ejouan/lxray.svg)
14
+ ![dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)
15
+
16
+ - **Zero dependencies.** Node.js 18+. Audits run on Linux; the package installs anywhere, so you can develop on Windows or macOS.
17
+ - **Safe by design.** No shell ever receives your values (no command injection, locally or over SSH). Your app never needs root.
18
+ - **Private.** LXRAY contacts nobody: reports stay on your infrastructure.
19
+ - **Everything LXRAY can do:** local, root-on-demand and scheduled audits, remote and fleet audits, raw snapshots,
20
+ every report format, thresholds, comparisons, Prometheus metrics, live progress, a ready-made HTTP endpoint.
21
+
22
+ Made by [El Mehdi Jouan](https://jouan.us). Part of [UpStream](https://jouan.us/upstream/en/), free tools for Linux operations.
23
+ **Found a bug or need help? Write to [ej@jouan.us](mailto:ej@jouan.us)** (see [Support](#11-support-and-bug-reports)).
24
+
25
+ ---
26
+
27
+ ## Contents
28
+
29
+ 1. [Install](#1-install)
30
+ 2. [Quick start](#2-quick-start)
31
+ 3. [What you get back](#3-what-you-get-back)
32
+ 4. [Root access without giving root to your app](#4-root-access-without-giving-root-to-your-app)
33
+ 5. [Scenarios in web applications](#5-scenarios-in-web-applications)
34
+ 6. [Fleets: many servers over SSH](#6-fleets-many-servers-over-ssh)
35
+ 7. [Monitoring: thresholds, history, Prometheus](#7-monitoring-thresholds-history-prometheus)
36
+ 8. [API reference](#8-api-reference)
37
+ 9. [Errors](#9-errors)
38
+ 10. [Security notes](#10-security-notes)
39
+ 11. [Support and bug reports](#11-support-and-bug-reports)
40
+
41
+ ---
42
+
43
+ ## 1. Install
14
44
 
15
45
  ```bash
16
46
  npm install @ejouan/lxray
17
47
  ```
18
48
 
19
- ## Quick start
49
+ LXRAY itself must be on the audited machine. Signed packages:
50
+
51
+ ```bash
52
+ # Debian / Ubuntu
53
+ sudo install -d -m 0755 /etc/apt/keyrings
54
+ curl -fsSL https://jouan.us/upstream/packages/jouan.gpg | sudo tee /etc/apt/keyrings/jouan.gpg >/dev/null
55
+ curl -fsSL https://jouan.us/upstream/packages/jouan.sources | sudo tee /etc/apt/sources.list.d/jouan.sources >/dev/null
56
+ sudo apt update && sudo apt install lxray
57
+
58
+ # RHEL, Oracle Linux, AlmaLinux, Rocky, Fedora
59
+ sudo curl -fsSL -o /etc/yum.repos.d/jouan.repo https://jouan.us/upstream/packages/jouan.repo
60
+ sudo dnf install lxray
61
+ ```
62
+
63
+ No root and no package manager (containers, PaaS)? Let the SDK install a user-space copy, GPG-verified:
64
+
65
+ ```js
66
+ await lxray.install(); // or: lxray.audit({ autoInstall: true })
67
+ ```
68
+
69
+ Check what the machine offers:
70
+
71
+ ```js
72
+ const lxray = require('@ejouan/lxray');
73
+ console.log(await lxray.checkEnvironment());
74
+ // { installed, lxrayVersion, pythonAvailable, isRoot, rootWrapperInstalled, spoolReadable, ... }
75
+ ```
76
+
77
+ ## 2. Quick start
20
78
 
21
79
  ```js
22
80
  const lxray = require('@ejouan/lxray');
23
81
 
24
- const { summary, html } = await lxray.audit({ profile: 'standard', formats: ['json', 'html'] });
25
- console.log(`${summary.hostname}: ${summary.score}/100 (${summary.grade}) ${summary.verdict}`);
26
- for (const f of summary.issues) console.log(`[${f.severity}] ${f.title} -> ${f.fix}`);
82
+ const { summary } = await lxray.audit({ profile: 'standard' });
83
+
84
+ console.log(`${summary.hostname}: ${summary.score}/100 (${summary.grade}) - ${summary.verdict}`);
85
+ for (const issue of summary.issues) {
86
+ console.log(`[${issue.severity}] ${issue.title}\n fix: ${issue.fix}`);
87
+ }
88
+ ```
89
+
90
+ ```
91
+ web01: 72/100 (C) - Needs attention
92
+ [critical] TLS certificate has expired
93
+ fix: Renew the certificate ...
94
+ [warning] Service is stuck in a restart loop
95
+ fix: journalctl -u <unit> -b ...
27
96
  ```
28
97
 
29
- `summary` is built from `lxray-report.json`:
98
+ TypeScript types are included (`import * as lxray from '@ejouan/lxray'`).
99
+
100
+ ## 3. What you get back
30
101
 
31
- | Field | Meaning |
102
+ `audit()` returns:
103
+
104
+ | Field | Content |
32
105
  |---|---|
33
- | `score`, `grade`, `verdict` | health score 0-100, letter A-F, sentence |
34
- | `counts` | `{ critical, warning, info, ok }` |
35
- | `issues` | findings to act on, critical first (`ok` checks left out): `id, severity, category, title, detail, fix, impact` |
106
+ | `summary` | `{ hostname, os, kernel, score, grade, verdict, counts: {critical, warning, info, ok}, issues: [...] }` (issues sorted, critical first, `ok` checks left out) |
107
+ | `report` | the full LXRAY report (`tool, version, generated, host, manifest, facts, findings`) |
108
+ | `html`, `markdown`, `text` | the other formats, when asked with `formats: ['json','html','md','txt']` |
109
+ | `partial` | `true` when LXRAY could not read everything (not root): the report lists what was not evaluated |
110
+ | `durationMs`, `warnings` | timing, and hints (e.g. the quick profile skipping a plugin you asked for) |
111
+ | `archivePath`, `outdir` | the raw `.tar.gz` snapshot and output folder, when you ask to keep them |
112
+
113
+ Each finding: `id, title, severity ('critical'|'warning'|'info'|'ok'), category, detail, evidence, fix, impact`.
36
114
 
37
- The full report is in `result.report` (`tool, version, generated, host, manifest, facts, findings`).
38
- `result.html`, `result.markdown` and `result.text` hold the other formats when requested.
115
+ Useful options:
39
116
 
40
- ## Root access: complete reports without giving root to your app
117
+ ```js
118
+ await lxray.audit({
119
+ formats: ['json', 'html', 'md', 'txt'],
120
+ profile: 'quick', // 'quick' (fast, skips packages/databases/containers) | 'standard' | 'full'
121
+ only: ['security', 'storage'], // or plugin ids: '70-security', '20-storage'; 'firewall' = network + security
122
+ exclude: ['logs'],
123
+ timeout: 20, // per-command collector timeout, seconds
124
+ redactIps: true, // mask IP addresses (secrets are always masked unless noRedact: true)
125
+ onLog: (line) => console.log(line) // LXRAY progress, live
126
+ });
127
+ ```
41
128
 
42
- Without root, LXRAY reads what the account can read and lists the checks it could not evaluate
43
- (`result.partial === true`, the report says how many). Installing an npm package can never grant root,
44
- and it should not. An administrator grants it **once**, narrowly:
129
+ ## 4. Root access without giving root to your app
130
+
131
+ Without root, LXRAY reads what your app's account can read and reports a **partial** audit. Installing an npm
132
+ package can never grant root, and it should not. An administrator grants it once, narrowly:
45
133
 
46
134
  ```bash
47
- npx lxray-setup-root <app-account> # prints the commands, runs nothing
135
+ npx lxray-setup-root <app-account> # PRINTS the commands to run as root. Runs nothing.
48
136
  ```
49
137
 
50
- | Mode | Call | What the admin installs once | Your app's rights |
138
+ It installs a small root wrapper (`lxray-audit`, accepts a profile and nothing else) and a group `lxray` shared with
139
+ your app. Then pick a mode:
140
+
141
+ | Mode | Your code | Your app's rights | Speed |
51
142
  |---|---|---|---|
52
- | Unprivileged (default) | `audit()` | nothing | its own account |
53
- | Root on demand, no sudo | `requestRootAudit({ profile })` | root wrapper + systemd path unit; app account in group `lxray` | writes a request file, reads reports |
54
- | Root every hour | `readLatest({ maxAgeMinutes: 90 })` | root wrapper + systemd timer | reads reports |
55
- | Root through sudo | `audit({ privileged: true, profile })` | root wrapper + one sudoers line for that wrapper only | may run that wrapper only |
143
+ | Unprivileged | `lxray.audit()` | its own account | 30 s to 2 min, partial |
144
+ | **Root on demand** (systemd, no sudo) | `lxray.requestRootAudit({ profile })` | writes a request file, reads reports | 30 s to 2 min, complete |
145
+ | **Root every hour** | `lxray.readLatest({ maxAgeMinutes: 90 })` | reads reports | instant, complete |
146
+ | Root through sudo | `lxray.audit({ privileged: true })` | may run that one wrapper | 30 s to 2 min, complete |
56
147
 
57
- The root wrapper (`setup/lxray-audit`, about 30 lines, read it) accepts a profile and nothing else, writes
58
- into `/var/lib/lxray/reports` (group `lxray`, no access for others) and keeps the 20 newest audits.
148
+ ## 5. Scenarios in web applications
59
149
 
60
- ## Fleets: many servers over SSH
150
+ ### 5.1 Express: a health page for the server your app runs on
61
151
 
62
152
  ```js
63
- const results = await lxray.auditFleet([
64
- { host: 'web01.example', user: 'audit', identityFile: '/etc/myapp/keys/audit' },
65
- { host: 'db01.example', user: 'audit', identityFile: '/etc/myapp/keys/audit', options: { profile: 'full' } },
66
- { local: true }
67
- ], { concurrency: 4, profile: 'standard', privileged: true, onResult: (e) => console.log(e.host, e.ok) });
68
-
69
- for (const r of results) {
70
- if (r.ok) console.log(r.host, r.result.summary.score);
71
- else console.error(r.host, r.error);
72
- }
153
+ const express = require('express');
154
+ const lxray = require('@ejouan/lxray');
155
+ const app = express();
156
+
157
+ // your own auth middleware decides who may see server diagnostics
158
+ app.get('/admin/server-health', requireAdmin, async (req, res, next) => {
159
+ try {
160
+ const { summary } = await lxray.readLatest({ maxAgeMinutes: 90 }); // instant, root report
161
+ res.json(summary);
162
+ } catch (e) { next(e); }
163
+ });
164
+
165
+ app.get('/admin/server-health/report', requireAdmin, async (req, res, next) => {
166
+ try {
167
+ const { html } = await lxray.readLatest({ formats: ['html'] });
168
+ res.set('Content-Security-Policy', "sandbox allow-scripts; default-src 'none'; style-src 'unsafe-inline'; img-src data:; script-src 'unsafe-inline'");
169
+ res.type('html').send(html); // full printable report
170
+ } catch (e) { next(e); }
171
+ });
73
172
  ```
74
173
 
75
- - Key authentication only (`BatchMode=yes`), host keys checked (`acceptNewHostKeys: true` to accept unknown hosts once).
76
- - LXRAY must be installed on each target (and the root wrapper + sudo rule for `privileged: true`).
77
- - One failing machine never fails the batch. `remoteAudit(target, options)` audits a single machine.
78
-
79
- ## HTTP endpoint (Express, Connect, node:http)
174
+ ### 5.2 The ready-made endpoint (Express, Connect, Fastify, node:http)
80
175
 
81
176
  ```js
82
177
  app.use('/internal/lxray', lxray.createAuditHandler({
83
- authorize: (req) => req.get('authorization') === `Bearer ${process.env.LXRAY_TOKEN}`, // required
178
+ authorize: (req) => req.get('authorization') === `Bearer ${process.env.LXRAY_TOKEN}`, // required
84
179
  source: 'latest', // 'audit' | 'privileged' | 'latest'
85
- auditOptions: { maxAgeMinutes: 120 },
86
- rateLimitMax: 3
180
+ rateLimitMax: 3, // per minute and client
181
+ checkRules: { maxCritical: 0, warnScore: 80 },
182
+ checkHttpStatus: true // ?format=check answers 503 when CRITICAL
87
183
  }));
88
- // GET ?format=summary | json | html | md | txt | status | archive
184
+ // GET /internal/lxray?format=summary | json | html | md | txt | metrics | check | status | archive
89
185
  ```
90
186
 
91
- `authorize` is mandatory. One audit runs at a time. The rate limit is keyed on the socket address
92
- (set `trustProxy: true` behind a proxy you control). HTML reports are served with a sandbox CSP.
93
- Raw archives (`?format=archive`) are off unless `allowArchive: true`: they contain raw system data.
187
+ Fastify:
94
188
 
95
- ## Monitoring integration
189
+ ```js
190
+ const handler = lxray.createAuditHandler({ authorize: (req) => isAdmin(req) });
191
+ fastify.get('/internal/lxray', (request, reply) => { reply.hijack(); handler(request.raw, reply.raw); });
192
+ ```
96
193
 
97
- Everything a monitoring or management tool needs, in code:
194
+ ### 5.3 Next.js (App Router) API route
98
195
 
99
196
  ```js
100
- // thresholds -> OK / WARNING / CRITICAL (exit codes 0/1/2, Nagios, Icinga, Zabbix, Centreon...)
101
- const check = lxray.evaluate(result, { minScore: 60, warnScore: 80, maxCritical: 0, ignore: ['SSH-ROOT'], partialIsWarning: true });
102
- console.log(check.message); process.exitCode = check.exitCode;
197
+ // app/api/server-health/route.js (Node.js runtime, not Edge)
198
+ export const runtime = 'nodejs';
199
+ import * as lxray from '@ejouan/lxray';
200
+ import { getSession } from '@/lib/auth';
201
+
202
+ export async function GET() {
203
+ const session = await getSession();
204
+ if (!session?.isAdmin) return new Response('Forbidden', { status: 403 });
205
+ const { summary } = await lxray.readLatest();
206
+ return Response.json(summary);
207
+ }
208
+ ```
103
209
 
104
- // tracking over time: what changed since the previous audit
105
- const diff = lxray.compare(previousResult, result);
106
- // { scoreDelta, newIssues, resolved, worse, better, persisting }
210
+ ### 5.4 NestJS service
107
211
 
108
- // Prometheus / Grafana (one audit, or an auditFleet() array as is)
109
- res.type('text/plain').send(lxray.toPrometheus(fleetResults, { labels: { env: 'prod' } }));
110
- // lxray_up, lxray_score{host,grade}, lxray_findings{host,severity}, lxray_partial, lxray_audit_duration_seconds, lxray_report_timestamp_seconds
212
+ ```ts
213
+ import { Injectable } from '@nestjs/common';
214
+ import * as lxray from '@ejouan/lxray';
111
215
 
112
- // live progress while LXRAY runs
113
- await lxray.audit({ onLog: (line) => socket.emit('lxray', line) });
216
+ @Injectable()
217
+ export class ServerHealthService {
218
+ latest() { return lxray.readLatest({ maxAgeMinutes: 90 }).then((r) => r.summary); }
219
+ audit(profile: 'quick' | 'standard' | 'full' = 'standard') { return lxray.requestRootAudit({ profile }); }
220
+ }
221
+ ```
114
222
 
115
- // keep the reports as files
116
- await lxray.saveReports(result, '/srv/audits/web01', { prefix: '2026-11-25' });
223
+ ### 5.5 "Run an audit" button with live progress (Socket.IO / SSE)
117
224
 
118
- // what LXRAY can use on this machine, and the packages to add (install: true needs root)
119
- const { missingPackages, installCommand } = await lxray.deps();
225
+ ```js
226
+ io.of('/admin').on('connection', (socket) => {
227
+ socket.on('lxray:run', async ({ profile }) => {
228
+ try {
229
+ const result = await lxray.audit({ profile, formats: ['json', 'html'], onLog: (line) => socket.emit('lxray:log', line) });
230
+ socket.emit('lxray:done', result.summary);
231
+ } catch (e) {
232
+ socket.emit('lxray:error', e.message);
233
+ }
234
+ });
235
+ });
120
236
  ```
121
237
 
122
- The HTTP handler also answers `?format=metrics` (Prometheus scrape target) and `?format=check`
123
- (`checkRules`; with `checkHttpStatus: true` a CRITICAL state answers 503 for HTTP probes).
238
+ Server-Sent Events work the same way: write each `onLog` line as `data: ...\n\n`.
124
239
 
125
- Remote machines:
240
+ ### 5.6 Keep a history in your database and show the trend
126
241
 
127
242
  ```js
128
- await lxray.remoteAudit(target, { mode: 'latest' }); // newest hourly root report, instant
129
- await lxray.remoteAudit(target, { mode: 'privileged', profile: 'full' }); // root wrapper via sudo
130
- await lxray.remoteAudit(target, { archive: true }); // + result.archive (Buffer, .tar.gz)
131
- const { savedTo } = await lxray.remoteCollect(target, { saveTo: '/srv/snapshots' });
132
- await lxray.analyze(savedTo); // analyze on the management server
243
+ // every hour (node-cron, BullMQ, your scheduler...)
244
+ const result = await lxray.readLatest();
245
+ const previous = await db.audits.findLatest(result.summary.hostname);
246
+ await db.audits.insert({
247
+ host: result.summary.hostname, score: result.summary.score, grade: result.summary.grade,
248
+ counts: result.summary.counts, report: result.report, at: new Date()
249
+ });
250
+ if (previous) {
251
+ const diff = lxray.compare(previous.report, result.report);
252
+ // diff.scoreDelta, diff.newIssues, diff.resolved, diff.worse, diff.better
253
+ if (diff.newIssues.length) await notify(`${diff.newIssues.length} new issue(s) on ${result.summary.hostname}`);
254
+ }
255
+ ```
256
+
257
+ ### 5.7 Alerts to Slack, Teams or e-mail
258
+
259
+ ```js
260
+ const result = await lxray.readLatest();
261
+ const check = lxray.evaluate(result, { minScore: 60, maxCritical: 0, ignore: ['SSH-ROOT'] });
262
+ if (check.status !== 'ok') {
263
+ await fetch(process.env.SLACK_WEBHOOK, { method: 'POST', headers: { 'Content-Type': 'application/json' },
264
+ body: JSON.stringify({ text: check.message }) });
265
+ }
133
266
  ```
134
267
 
135
- ## API
268
+ ### 5.8 Prometheus and Grafana
269
+
270
+ ```js
271
+ app.get('/metrics/lxray', requireMetricsToken, async (req, res) => {
272
+ const results = await lxray.auditFleet(servers, { mode: 'latest' });
273
+ res.type('text/plain; version=0.0.4').send(lxray.toPrometheus(results, { labels: { env: 'prod' } }));
274
+ });
275
+ ```
276
+
277
+ Metrics: `lxray_up`, `lxray_score{host,grade}`, `lxray_findings{host,severity}`, `lxray_partial`,
278
+ `lxray_audit_duration_seconds`, `lxray_report_timestamp_seconds`.
279
+
280
+ ### 5.9 Managed-services portal: one report per customer server
281
+
282
+ ```js
283
+ // customers' servers, each with its own SSH key; run nightly
284
+ const results = await lxray.auditFleet(customer.servers.map((s) => ({
285
+ host: s.host, user: 'lxray', identityFile: `/etc/portal/keys/${customer.id}`, options: { mode: 'latest' }
286
+ })), { concurrency: 8, formats: ['json', 'html'] });
287
+
288
+ for (const r of results) {
289
+ if (!r.ok) { await portal.markUnreachable(customer.id, r.host, r.error); continue; }
290
+ await portal.saveReport(customer.id, r.host, r.result.summary, r.result.html); // customers download the report
291
+ }
292
+ ```
293
+
294
+ ### 5.10 CI/CD gate: block a deployment on an unhealthy server
295
+
296
+ ```js
297
+ // scripts/check-server.js, run in your pipeline before deploying
298
+ const lxray = require('@ejouan/lxray');
299
+ const r = await lxray.remoteAudit({ host: process.env.TARGET, user: 'deploy' }, { mode: 'latest' });
300
+ const check = lxray.evaluate(r, { minScore: 70, maxCritical: 0 });
301
+ console.log(check.message);
302
+ process.exit(check.exitCode); // 0 OK, 1 WARNING, 2 CRITICAL
303
+ ```
304
+
305
+ ### 5.11 Support: collect a snapshot, analyze it elsewhere
306
+
307
+ ```js
308
+ // on the customer's server (or remotely: lxray.remoteCollect(target, { saveTo: '/srv/snapshots' }))
309
+ const { archivePath } = await lxray.collect({ profile: 'full' });
310
+ // later, on your support machine:
311
+ const result = await lxray.analyze('/srv/snapshots/lxray-web01-20261125-010000.tar.gz', { formats: ['json', 'html'] });
312
+ await lxray.saveReports(result, '/srv/tickets/4521');
313
+ ```
314
+
315
+ ### 5.12 React / Vue front-end
316
+
317
+ The browser never runs LXRAY: expose `summary` from your backend (scenarios 5.1 to 5.4) and render it.
318
+
319
+ ```jsx
320
+ function ServerHealth() {
321
+ const [s, setS] = useState(null);
322
+ useEffect(() => { fetch('/admin/server-health').then((r) => r.json()).then(setS); }, []);
323
+ if (!s) return <p>Loading…</p>;
324
+ return (<section>
325
+ <h2>{s.hostname}: {s.score}/100 ({s.grade})</h2>
326
+ <ul>{s.issues.map((i) => <li key={i.id}><b>[{i.severity}]</b> {i.title}: {i.fix}</li>)}</ul>
327
+ </section>);
328
+ }
329
+ ```
330
+
331
+ ## 6. Fleets: many servers over SSH
332
+
333
+ ```js
334
+ const servers = [
335
+ { host: 'web01.example', user: 'lxray', identityFile: '/etc/myapp/keys/lxray' },
336
+ { host: 'db01.example', user: 'lxray', identityFile: '/etc/myapp/keys/lxray', options: { profile: 'full' } },
337
+ { local: true } // the machine your app runs on
338
+ ];
339
+
340
+ const results = await lxray.auditFleet(servers, {
341
+ mode: 'latest', // 'run' (default) | 'privileged' (root wrapper via sudo) | 'latest' (hourly root report, instant)
342
+ concurrency: 4,
343
+ onResult: (entry) => console.log(entry.host, entry.ok ? entry.result.summary.score : entry.error)
344
+ });
345
+ ```
346
+
347
+ - Key authentication only (`BatchMode=yes`); host keys are checked (`acceptNewHostKeys: true` to accept unknown hosts once).
348
+ - One unreachable server never fails the batch: each entry is `{ host, ok, result | error }`.
349
+ - Single machine: `remoteAudit(target, options)`; raw snapshot: `remoteCollect(target, { saveTo })`;
350
+ archive with the audit: `remoteAudit(target, { archive: true })` (`result.archive` is a Buffer).
351
+
352
+ ## 7. Monitoring: thresholds, history, Prometheus
353
+
354
+ ```js
355
+ lxray.evaluate(result, { minScore: 60, warnScore: 80, maxCritical: 0, maxWarning: 5, ignore: ['ID'], partialIsWarning: true });
356
+ // { status: 'ok'|'warning'|'critical', exitCode: 0|1|2, message, reasons, score }
357
+
358
+ lxray.compare(previous, current);
359
+ // { scoreBefore, scoreAfter, scoreDelta, newIssues, resolved, worse, better, persisting }
360
+
361
+ lxray.toPrometheus(resultOrFleet, { prefix: 'lxray', labels: { env: 'prod' } });
362
+
363
+ await lxray.saveReports(result, '/srv/audits/web01', { prefix: '2026-11-25' });
364
+
365
+ await lxray.deps(); // tools LXRAY can use here, missing packages and the install command
366
+ ```
367
+
368
+ ## 8. API reference
136
369
 
137
370
  | Function | Returns |
138
371
  |---|---|
139
- | `audit(options)` (alias `run`) | `{ summary, report, html?, markdown?, text?, partial, durationMs, warnings, outdir?, archivePath? }` |
140
- | `requestRootAudit({ profile, waitMs })` | same, from a root audit run by systemd |
141
- | `readLatest({ spoolDir, maxAgeMinutes })` | same, newest root report |
142
- | `collect(options)` | `{ outdir, snapshotDir, archivePath, partial }` raw snapshot, yours to delete |
143
- | `analyze(pathToSnapshotOrTarGz, options)` | same as `audit()`, for a snapshot from another machine |
144
- | `remoteAudit(target, options)` / `auditFleet(targets, options)` | see Fleets |
145
- | `plugins()`, `version()`, `deps()`, `checkEnvironment()` | installed plugins, version, tools present/missing, what this machine offers |
146
- | `evaluate(result, rules)`, `compare(a, b)`, `toPrometheus(x)`, `saveReports(result, dir)` | monitoring helpers (see above) |
147
- | `remoteCollect(target, options)` | raw snapshot of a remote machine, as a Buffer or saved to a folder |
372
+ | `audit(options)` (alias `run`) | audit result (section 3) |
373
+ | `requestRootAudit({ profile, waitMs, requestDir, spoolDir })` | audit result, root, on demand |
374
+ | `readLatest({ formats, maxAgeMinutes, spoolDir })` | audit result, newest hourly root report |
375
+ | `collect(options)` | `{ outdir, snapshotDir, archivePath, partial }` (files are yours to delete) |
376
+ | `analyze(pathToFolderOrTarGz, { formats })` | audit result |
377
+ | `remoteAudit(target, options)` | audit result + `host`, `mode`, `archive?` |
378
+ | `remoteCollect(target, { saveTo })` | `{ host, archive (Buffer), archiveName, savedTo? }` |
379
+ | `auditFleet(targets, options)` | `[{ host, ok, result?, error? }]` |
380
+ | `createAuditHandler(options)` | `(req, res, next) => Promise<void>` |
381
+ | `evaluate`, `compare`, `toPrometheus`, `saveReports`, `summarize` | monitoring helpers |
382
+ | `checkEnvironment()`, `version()`, `plugins()`, `deps({ install })` | machine information |
148
383
  | `install({ version, installDir })` | user-space LXRAY, GPG signature and key fingerprint checked |
149
- | `summarize(report)`, `resolvePlugins(names)` | helpers |
384
+ | `resolvePlugins(names)`, `PLUGINS`, `PROFILES`, `FORMATS` | constants and helpers |
385
+
386
+ Plugins (id / alias): `00-system` system, `05-raw` raw, `10-cpu-memory` cpu_memory, `20-storage` storage,
387
+ `30-network` network, `40-kernel` kernel, `50-services` services, `60-packages` packages, `70-security` security,
388
+ `80-logs` logs, `85-databases` databases, `90-containers` containers, `95-appstack` applications.
150
389
 
151
- Audit options:
390
+ ## 9. Errors
152
391
 
153
- | Option | Default | |
154
- |---|---|---|
155
- | `formats` | `['json']` | any of `json`, `html`, `md`, `txt` (JSON always included) |
156
- | `profile` | LXRAY's `standard` | `quick` (skips packages, databases, containers), `standard`, `full` |
157
- | `only`, `exclude` | all | plugin ids (`70-security`) or aliases (`security`, `firewall`, `storage`...) |
158
- | `timeout` | profile's | per-command collector timeout, seconds |
159
- | `redactIps` / `noRedact` | false / false | mask IPs / keep secrets unmasked (masked by default) |
160
- | `archive`, `keepArtifacts`, `outdir` | off | keep the .tar.gz / the output folder |
161
- | `privileged`, `wrapperPath` | off | root through sudo and the wrapper |
162
- | `autoInstall`, `binaryPath`, `processTimeout` | off, auto, 600000 ms | |
163
- | `onLog(line, stream)` | none | progress lines while LXRAY runs |
392
+ Every error has a `code`:
164
393
 
165
- Plugins: `00-system` (system), `05-raw` (raw), `10-cpu-memory` (cpu_memory), `20-storage` (storage),
166
- `30-network` (network), `40-kernel` (kernel), `50-services` (services), `60-packages` (packages),
167
- `70-security` (security), `80-logs` (logs), `85-databases` (databases), `90-containers` (containers),
168
- `95-appstack` (applications). `firewall` selects network + security.
394
+ | Code | Meaning |
395
+ |---|---|
396
+ | `LXRAY_NOT_FOUND` | LXRAY is not installed (or not executable) |
397
+ | `LXRAY_EXIT` | LXRAY failed (message includes its error output) |
398
+ | `LXRAY_TIMEOUT` | the audit exceeded `processTimeout` |
399
+ | `LXRAY_PRIVILEGE_DENIED` | root mode not set up for this account (`npx lxray-setup-root`) |
400
+ | `LXRAY_NO_SPOOL`, `LXRAY_NO_REPORT`, `LXRAY_STALE` | no hourly root report available, or too old |
169
401
 
170
- Errors carry a `code`: `LXRAY_NOT_FOUND`, `LXRAY_EXIT`, `LXRAY_TIMEOUT`, `LXRAY_PRIVILEGE_DENIED`,
171
- `LXRAY_NO_SPOOL`, `LXRAY_NO_REPORT`, `LXRAY_STALE`.
402
+ A LXRAY exit code 3 is **not** an error: the collection was partial, the report exists (`result.partial === true`).
172
403
 
173
- ## Tests
404
+ ## 10. Security notes
174
405
 
175
- ```bash
176
- npm test # SDK against a stand-in that reproduces LXRAY 1.2.0 exactly
177
- npm run test:integration # against the real LXRAY installed on the machine
178
- ```
406
+ - Server diagnostics are sensitive: put every route behind your own authentication. `createAuditHandler()` refuses to start without `authorize`.
407
+ - HTML reports should be served with a sandbox Content-Security-Policy (example in 5.1).
408
+ - Raw snapshots (`collect`, `archive`) contain raw system data: keep them private and delete them when done.
409
+ - Remote audits use SSH keys only and check host keys; give the remote account only what it needs (the `lxray` group, or the sudo rule for the wrapper).
410
+
411
+ ## 11. Support and bug reports
412
+
413
+ Found a bug, a wrong result on your distribution, or a missing feature? Please write to
414
+ **[ej@jouan.us](mailto:ej@jouan.us)** with:
415
+
416
+ - the package version (`npm ls @ejouan/lxray`) and the LXRAY version (`lxray version`),
417
+ - your distribution and Node.js version,
418
+ - what you ran, what you expected and what happened (error `code` and message),
419
+ - if possible, the JSON report or the output of `lxray deps` (check it contains nothing you consider private).
420
+
421
+ Security issues: please write to the same address with "SECURITY" in the subject and do not publish details before a fix.
422
+ Every report is read, and answered within a few days.
423
+
424
+ ## Links
425
+
426
+ - LXRAY: https://jouan.us/upstream/en/lxray/
427
+ - Signed packages: https://jouan.us/upstream/packages
428
+ - Releases: https://github.com/eljouan/lxray/releases
429
+ - UpStream, free tools by El Mehdi Jouan: https://jouan.us/upstream/en/
430
+ - Contact and support: ej@jouan.us
179
431
 
180
432
  ## License
181
433
 
182
- Free use, all rights reserved: see LICENSE. Made by El Mehdi Jouan, https://jouan.us
434
+ Free use, all rights reserved: see [LICENSE](LICENSE). © 2026 El Mehdi Jouan.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejouan/lxray",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Node.js SDK for LXRAY, the X-ray for Linux servers: run audits from your application (local, root on demand, or over SSH across a fleet) and get scored reports with the fix for every finding.",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
@@ -36,14 +36,19 @@
36
36
  "sysadmin",
37
37
  "lxray"
38
38
  ],
39
- "author": "El Mehdi Jouan (https://jouan.us)",
39
+ "author": {
40
+ "name": "El Mehdi Jouan",
41
+ "email": "ej@jouan.us",
42
+ "url": "https://jouan.us"
43
+ },
40
44
  "license": "SEE LICENSE IN LICENSE",
41
45
  "homepage": "https://jouan.us/upstream/en/lxray/",
42
46
  "repository": {
43
47
  "type": "git",
44
- "url": "https://github.com/eljouan/lxray.git"
48
+ "url": "git+https://github.com/eljouan/lxray.git"
45
49
  },
46
50
  "bugs": {
47
- "url": "https://github.com/eljouan/lxray/issues"
51
+ "email": "ej@jouan.us",
52
+ "url": "https://jouan.us/upstream/en/lxray/"
48
53
  }
49
54
  }