kern0-cli 0.1.4 → 0.1.5
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/lib/cli/commands/health.ts +174 -0
- package/lib/cli/index.ts +36 -0
- package/package.json +1 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { requireAuthentication, requireOrganization } from "../config";
|
|
2
|
+
import { apiCall } from "../api";
|
|
3
|
+
|
|
4
|
+
export async function analyzeReadiness(): Promise<void> {
|
|
5
|
+
try {
|
|
6
|
+
requireAuthentication();
|
|
7
|
+
const orgId = requireOrganization();
|
|
8
|
+
|
|
9
|
+
console.log("\n⏳ Analyzing recovery readiness...\n");
|
|
10
|
+
|
|
11
|
+
const response = await apiCall<{
|
|
12
|
+
readinessPercentage: number;
|
|
13
|
+
totalEnvironments: number;
|
|
14
|
+
onlineCount: number;
|
|
15
|
+
offlineCount: number;
|
|
16
|
+
validBackupsCount: number;
|
|
17
|
+
assessment: string;
|
|
18
|
+
}>("GET", `/api/v1/orgs/${orgId}/readiness`);
|
|
19
|
+
|
|
20
|
+
const pct = response.readinessPercentage;
|
|
21
|
+
const bar = "█".repeat(Math.floor(pct / 5)) + "░".repeat(20 - Math.floor(pct / 5));
|
|
22
|
+
|
|
23
|
+
console.log("📊 Recovery Readiness Assessment\n");
|
|
24
|
+
console.log(` Readiness: [${bar}] ${pct}%\n`);
|
|
25
|
+
console.log(` Assessment: ${response.assessment}\n`);
|
|
26
|
+
console.log(" Details:");
|
|
27
|
+
console.log(` • Total Environments: ${response.totalEnvironments}`);
|
|
28
|
+
console.log(` • Online: ${response.onlineCount}`);
|
|
29
|
+
console.log(` • Offline: ${response.offlineCount}`);
|
|
30
|
+
console.log(` • Valid Backups: ${response.validBackupsCount}/${response.totalEnvironments}\n`);
|
|
31
|
+
|
|
32
|
+
if (pct < 50) {
|
|
33
|
+
console.log(" ⚠️ Action Required: Below 50% readiness\n");
|
|
34
|
+
} else if (pct < 80) {
|
|
35
|
+
console.log(" ⚡ Action Recommended: Room for improvement\n");
|
|
36
|
+
} else {
|
|
37
|
+
console.log(" ✅ Status: Good\n");
|
|
38
|
+
}
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error instanceof Error) {
|
|
41
|
+
console.error("Error:", error.message);
|
|
42
|
+
}
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function checkBackupHealth(): Promise<void> {
|
|
48
|
+
try {
|
|
49
|
+
requireAuthentication();
|
|
50
|
+
const orgId = requireOrganization();
|
|
51
|
+
|
|
52
|
+
console.log("\n⏳ Checking backup health...\n");
|
|
53
|
+
|
|
54
|
+
const response = await apiCall<{
|
|
55
|
+
healthyBackups: number;
|
|
56
|
+
totalEnvironments: number;
|
|
57
|
+
failedBackups: Array<{
|
|
58
|
+
environmentId: string;
|
|
59
|
+
label: string;
|
|
60
|
+
reason: string;
|
|
61
|
+
lastBackup: number;
|
|
62
|
+
}>;
|
|
63
|
+
summary: string;
|
|
64
|
+
}>("GET", `/api/v1/orgs/${orgId}/backups/health`);
|
|
65
|
+
|
|
66
|
+
console.log("💾 Backup Health Status\n");
|
|
67
|
+
console.log(` Healthy: ${response.healthyBackups}/${response.totalEnvironments}\n`);
|
|
68
|
+
console.log(` Summary: ${response.summary}\n`);
|
|
69
|
+
|
|
70
|
+
if (response.failedBackups.length > 0) {
|
|
71
|
+
console.log(" ⚠️ Failed Backups:\n");
|
|
72
|
+
response.failedBackups.forEach((backup) => {
|
|
73
|
+
const lastBackupDate = new Date(backup.lastBackup).toLocaleDateString();
|
|
74
|
+
console.log(` • ${backup.label}`);
|
|
75
|
+
console.log(` Reason: ${backup.reason}`);
|
|
76
|
+
console.log(` Last backup: ${lastBackupDate}\n`);
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
console.log(" ✅ All backups healthy\n");
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (error instanceof Error) {
|
|
83
|
+
console.error("Error:", error.message);
|
|
84
|
+
}
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function getEnvironmentStatus(envId: string): Promise<void> {
|
|
90
|
+
try {
|
|
91
|
+
requireAuthentication();
|
|
92
|
+
const orgId = requireOrganization();
|
|
93
|
+
|
|
94
|
+
console.log("\n⏳ Loading environment details...\n");
|
|
95
|
+
|
|
96
|
+
const response = await apiCall<{
|
|
97
|
+
id: string;
|
|
98
|
+
label: string;
|
|
99
|
+
status: "online" | "offline" | "degraded";
|
|
100
|
+
customer: string;
|
|
101
|
+
product: string;
|
|
102
|
+
lastHeartbeat: number;
|
|
103
|
+
backupStatus: "healthy" | "warning" | "critical";
|
|
104
|
+
recoveryReadiness: number;
|
|
105
|
+
nodeCount: number;
|
|
106
|
+
onlineNodes: number;
|
|
107
|
+
}>("GET", `/api/v1/orgs/${orgId}/environments/${envId}`);
|
|
108
|
+
|
|
109
|
+
const statusEmoji =
|
|
110
|
+
response.status === "online" ? "🟢" : response.status === "offline" ? "🔴" : "🟡";
|
|
111
|
+
const backupEmoji =
|
|
112
|
+
response.backupStatus === "healthy" ? "✅" : response.backupStatus === "warning" ? "⚠️" : "❌";
|
|
113
|
+
|
|
114
|
+
console.log("🌍 Environment Status\n");
|
|
115
|
+
console.log(` Label: ${response.label}`);
|
|
116
|
+
console.log(` Status: ${statusEmoji} ${response.status.toUpperCase()}`);
|
|
117
|
+
console.log(` Customer: ${response.customer}`);
|
|
118
|
+
console.log(` Product: ${response.product}\n`);
|
|
119
|
+
|
|
120
|
+
console.log("📊 Health Metrics:");
|
|
121
|
+
console.log(` Backup Status: ${backupEmoji} ${response.backupStatus}`);
|
|
122
|
+
console.log(` Recovery Readiness: ${response.recoveryReadiness}%`);
|
|
123
|
+
console.log(` Nodes: ${response.onlineNodes}/${response.nodeCount} online`);
|
|
124
|
+
console.log(` Last Heartbeat: ${new Date(response.lastHeartbeat).toLocaleString()}\n`);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (error instanceof Error) {
|
|
127
|
+
console.error("Error:", error.message);
|
|
128
|
+
}
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function listAuditLogs(limit: string = "50"): Promise<void> {
|
|
134
|
+
try {
|
|
135
|
+
requireAuthentication();
|
|
136
|
+
const orgId = requireOrganization();
|
|
137
|
+
|
|
138
|
+
console.log("\n⏳ Loading audit logs...\n");
|
|
139
|
+
|
|
140
|
+
const limitNum = parseInt(limit) || 50;
|
|
141
|
+
const response = await apiCall<{
|
|
142
|
+
logs: Array<{
|
|
143
|
+
id: string;
|
|
144
|
+
timestamp: number;
|
|
145
|
+
userId: string;
|
|
146
|
+
action: string;
|
|
147
|
+
resource: string;
|
|
148
|
+
status: number;
|
|
149
|
+
}>;
|
|
150
|
+
}>("GET", `/api/v1/orgs/${orgId}/audit-logs?limit=${limitNum}`);
|
|
151
|
+
|
|
152
|
+
const logs = response.logs || [];
|
|
153
|
+
|
|
154
|
+
if (logs.length === 0) {
|
|
155
|
+
console.log(" No audit logs found.\n");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
console.log(`📋 Recent Actions (${logs.length} logs)\n`);
|
|
160
|
+
|
|
161
|
+
logs.forEach((log) => {
|
|
162
|
+
const timestamp = new Date(log.timestamp).toLocaleString();
|
|
163
|
+
const statusEmoji = log.status >= 200 && log.status < 300 ? "✅" : "❌";
|
|
164
|
+
console.log(` ${statusEmoji} ${timestamp}`);
|
|
165
|
+
console.log(` Action: ${log.action} ${log.resource}`);
|
|
166
|
+
console.log(` User: ${log.userId}\n`);
|
|
167
|
+
});
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (error instanceof Error) {
|
|
170
|
+
console.error("Error:", error.message);
|
|
171
|
+
}
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
}
|
package/lib/cli/index.ts
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { login, logout } from "./commands/auth";
|
|
4
4
|
import { setupCommand } from "./commands/setup";
|
|
5
|
+
import {
|
|
6
|
+
analyzeReadiness,
|
|
7
|
+
checkBackupHealth,
|
|
8
|
+
getEnvironmentStatus,
|
|
9
|
+
listAuditLogs,
|
|
10
|
+
} from "./commands/health";
|
|
5
11
|
import {
|
|
6
12
|
listOrgs,
|
|
7
13
|
selectOrg,
|
|
@@ -45,6 +51,30 @@ async function main() {
|
|
|
45
51
|
await setupCommand();
|
|
46
52
|
break;
|
|
47
53
|
|
|
54
|
+
// Health & Monitoring commands
|
|
55
|
+
case "health":
|
|
56
|
+
case "readiness":
|
|
57
|
+
await analyzeReadiness();
|
|
58
|
+
break;
|
|
59
|
+
|
|
60
|
+
case "backups":
|
|
61
|
+
await checkBackupHealth();
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case "audit":
|
|
65
|
+
case "logs":
|
|
66
|
+
await listAuditLogs(arg1);
|
|
67
|
+
break;
|
|
68
|
+
|
|
69
|
+
case "env-status":
|
|
70
|
+
case "env-health":
|
|
71
|
+
if (!arg1) {
|
|
72
|
+
console.error("Usage: kern0 env-status <envId>");
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
await getEnvironmentStatus(arg1);
|
|
76
|
+
break;
|
|
77
|
+
|
|
48
78
|
// Organization commands
|
|
49
79
|
case "org":
|
|
50
80
|
switch (subcommand) {
|
|
@@ -187,6 +217,12 @@ AUTHENTICATION:
|
|
|
187
217
|
logout Clear credentials and log out
|
|
188
218
|
whoami Show current user, organization, and customer
|
|
189
219
|
|
|
220
|
+
MONITORING & HEALTH:
|
|
221
|
+
health Analyze recovery readiness (%)
|
|
222
|
+
backups Check backup health status
|
|
223
|
+
audit [limit] View recent action audit logs
|
|
224
|
+
env-status <id> Get detailed environment status
|
|
225
|
+
|
|
190
226
|
ORGANIZATIONS:
|
|
191
227
|
org list List your organizations
|
|
192
228
|
org select <id> Switch to an organization
|