@saptools/cf-events 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dong Tran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # @saptools/cf-events
2
+
3
+ Inspect SAP BTP Cloud Foundry application **audit events** and detect active
4
+ **SSH / debug sessions** from the command line. Point it at a
5
+ `region/org/space/app` target and it answers questions like "what just happened
6
+ to this app?", "is anyone SSH'd into it right now?", and "why did it crash?".
7
+
8
+ `cf-events` reuses [`@saptools/cf-sync`](https://github.com/dongitran/saptools/tree/main/packages/cf-sync)
9
+ for the synced `region/org/space/app` topology, then calls the Cloud Foundry v3
10
+ API (`/v3/audit_events`, process stats, SSH status) through the `cf` CLI.
11
+
12
+ ## Prerequisites
13
+
14
+ - Node.js >= 20.
15
+ - The [Cloud Foundry CLI v8+](https://github.com/cloudfoundry/cli) on `PATH`.
16
+ - A topology snapshot produced by `cf-sync`. Run `cf-sync sync` (or a targeted
17
+ `cf-sync space <region> <org> <space>`) once so `cf-events` can resolve and
18
+ validate selectors. The snapshot lives at `~/.saptools/cf-structure.json`.
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ npm install -g @saptools/cf-events
24
+ # or run it on demand
25
+ npx @saptools/cf-events --help
26
+ ```
27
+
28
+ ## Authentication
29
+
30
+ Credentials are read from environment variables (preferred) or flags:
31
+
32
+ ```bash
33
+ export SAP_EMAIL="you@example.com"
34
+ export SAP_PASSWORD="your-password"
35
+ ```
36
+
37
+ Every command also accepts `--email` and `--password`. Credentials are passed
38
+ to the `cf` CLI through the environment, never on the command line, and each
39
+ invocation runs in an isolated, ephemeral `CF_HOME`.
40
+
41
+ ## Selectors
42
+
43
+ Every command takes a single positional selector:
44
+
45
+ - A full path: `ap10/my-org/dev/orders-srv`.
46
+ - A bare app name: `orders-srv` — resolved against the `cf-sync` snapshot. If
47
+ the name is ambiguous across spaces, `cf-events` lists the candidates and
48
+ asks for a full path.
49
+
50
+ ## Commands
51
+
52
+ ### `events <selector>`
53
+
54
+ List recent audit events for an app (deployments, restarts, scaling, crashes,
55
+ SSH activity, ...).
56
+
57
+ ```bash
58
+ cf-events events ap10/my-org/dev/orders-srv
59
+ cf-events events orders-srv --limit 100 --since 6h
60
+ cf-events events orders-srv --type ssh --json
61
+ ```
62
+
63
+ Options: `--limit <count>` (default 50), `--since <duration>` (e.g. `30m`,
64
+ `6h`, `7d`), `--type <types>` (comma-separated CF event types, or the
65
+ shorthand `ssh` / `crash`), `--json`.
66
+
67
+ ### `ssh-status <selector>`
68
+
69
+ Show whether SSH is enabled for the app and surface recent SSH / debug
70
+ activity: who opened a session and when, plus any denied attempts.
71
+
72
+ ```bash
73
+ cf-events ssh-status orders-srv
74
+ cf-events ssh-status orders-srv --since 7d --json
75
+ ```
76
+
77
+ Options: `--since <duration>` (default `24h`), `--json`.
78
+
79
+ > Cloud Foundry exposes no live-session API and emits no event when an SSH
80
+ > session closes. `cf-events` therefore *infers* "likely active" sessions from
81
+ > recent `ssh-authorized` audit events — treat it as a strong hint, not proof.
82
+
83
+ ### `crashes <selector>`
84
+
85
+ Summarize recent crash events: how many, the most recent one, and the exit
86
+ reason.
87
+
88
+ ```bash
89
+ cf-events crashes orders-srv
90
+ cf-events crashes orders-srv --since 24h --json
91
+ ```
92
+
93
+ Options: `--limit <count>` (default 50), `--since <duration>`, `--json`.
94
+
95
+ ### `status <selector>`
96
+
97
+ A one-glance health view: requested state, per-instance state / uptime / CPU /
98
+ memory, the SSH-enabled flag, and the most recent audit event.
99
+
100
+ ```bash
101
+ cf-events status orders-srv --json
102
+ ```
103
+
104
+ ### `watch <selector>`
105
+
106
+ Poll `/v3/audit_events` on an interval and print new events as they appear.
107
+ Press `Ctrl+C` to stop.
108
+
109
+ ```bash
110
+ cf-events watch orders-srv
111
+ cf-events watch orders-srv --interval 30000 --type crash
112
+ ```
113
+
114
+ Options: `--interval <ms>` (default 15000, minimum 2000), `--lookback
115
+ <duration>` (initial window on start, default `2m`), `--type <types>`,
116
+ `--json` (line-delimited JSON).
117
+
118
+ ## Programmatic use
119
+
120
+ The package also ships a typed library entry:
121
+
122
+ ```ts
123
+ import { CfEventsRuntime } from "@saptools/cf-events";
124
+
125
+ const runtime = new CfEventsRuntime();
126
+ const events = await runtime.fetchEvents("orders-srv", credentials, {
127
+ limit: 50,
128
+ since: "6h",
129
+ types: [],
130
+ });
131
+ ```
132
+
133
+ ## License
134
+
135
+ MIT
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare function main(argv: readonly string[]): Promise<void>;
2
+
3
+ export { main };