@aerocorp/cli
Version:
AeroCorp CLI 5.1.0 - Future-Proofed Enterprise Infrastructure with Live Preview, Tunneling & Advanced DevOps
211 lines ⢠9.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HealthService = void 0;
const axios_1 = __importDefault(require("axios"));
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
const auth_1 = require("./auth");
const config_1 = require("./config");
class HealthService {
constructor() {
this.authService = new auth_1.AuthService();
this.configService = new config_1.ConfigService();
}
async checkHealth() {
console.log(chalk_1.default.cyan('š„ AeroCorp System Health Check'));
console.log(chalk_1.default.cyan('================================'));
const checks = [
{ name: 'Authentication', check: () => this.checkAuth() },
{ name: 'Coolify API', check: () => this.checkCoolifyAPI() },
{ name: 'AI-Proxy', check: () => this.checkAIProxy() },
{ name: 'Server Connection', check: () => this.checkServerConnection() },
{ name: 'Configuration', check: () => this.checkConfiguration() }
];
const results = [];
for (const healthCheck of checks) {
const spinner = (0, ora_1.default)(`Checking ${healthCheck.name}...`).start();
try {
const result = await healthCheck.check();
spinner.succeed(`${healthCheck.name}: ${result.status}`);
results.push({ name: healthCheck.name, status: 'healthy', details: result });
}
catch (error) {
spinner.fail(`${healthCheck.name}: ${error.message}`);
results.push({ name: healthCheck.name, status: 'unhealthy', error: error.message });
}
}
// Summary
const healthy = results.filter(r => r.status === 'healthy').length;
const total = results.length;
console.log(chalk_1.default.cyan(`\nš Health Summary: ${healthy}/${total} checks passed`));
if (healthy === total) {
console.log(chalk_1.default.green('ā
All systems operational'));
}
else {
console.log(chalk_1.default.yellow('ā ļø Some issues detected'));
const unhealthy = results.filter(r => r.status === 'unhealthy');
console.log(chalk_1.default.red('\nā Issues:'));
unhealthy.forEach(issue => {
console.log(chalk_1.default.red(` ⢠${issue.name}: ${issue.error}`));
});
}
return results;
}
async showStatus() {
console.log(chalk_1.default.cyan('š AeroCorp System Status'));
console.log(chalk_1.default.cyan('=========================='));
try {
// System info
console.log(chalk_1.default.blue('\nš„ļø System Information:'));
console.log(chalk_1.default.white(` Server IP: ${this.configService.get('server_ip') || '128.140.35.238'}`));
console.log(chalk_1.default.white(` Environment: ${this.configService.get('environment') || 'production'}`));
console.log(chalk_1.default.white(` CLI Version: 2.1.0`));
// Authentication status
console.log(chalk_1.default.blue('\nš Authentication:'));
const isAuth = this.authService.isAuthenticated();
console.log(chalk_1.default[isAuth ? 'green' : 'red'](` Status: ${isAuth ? 'Authenticated' : 'Not authenticated'}`));
if (isAuth) {
const coolifyUrl = this.authService.getCoolifyUrl();
console.log(chalk_1.default.white(` Coolify URL: ${coolifyUrl}`));
const hasRootToken = !!process.env.AEROCORP_CLI_ROOT_API_TOKEN;
if (hasRootToken) {
console.log(chalk_1.default.red(' Root Access: ENABLED'));
}
}
// Configuration
console.log(chalk_1.default.blue('\nāļø Configuration:'));
const config = this.configService.getAll();
Object.entries(config).forEach(([key, value]) => {
let displayValue = value;
if (key.includes('token') || key.includes('password')) {
displayValue = typeof value === 'string' ? '*'.repeat(Math.min(value.toString().length, 10)) : value;
}
console.log(chalk_1.default.white(` ${key}: ${displayValue}`));
});
// Services status
await this.checkServicesStatus();
}
catch (error) {
console.error(chalk_1.default.red(`Error getting status: ${error.message}`));
}
}
async checkAuth() {
const isAuthenticated = this.authService.isAuthenticated();
if (!isAuthenticated) {
throw new Error('Not authenticated');
}
const hasRootToken = !!process.env.AEROCORP_CLI_ROOT_API_TOKEN;
return {
status: 'Authenticated',
rootAccess: hasRootToken,
coolifyUrl: this.authService.getCoolifyUrl()
};
}
async checkCoolifyAPI() {
if (!this.authService.isAuthenticated()) {
throw new Error('Not authenticated');
}
const coolifyUrl = this.authService.getCoolifyUrl();
const headers = this.authService.getAuthHeaders();
const response = await axios_1.default.get(`${coolifyUrl}/api/v1/projects`, {
headers,
timeout: 10000
});
if (response.status !== 200) {
throw new Error(`API returned status ${response.status}`);
}
return {
status: 'API accessible',
projects: response.data.length,
responseTime: response.headers['x-response-time'] || 'N/A'
};
}
async checkAIProxy() {
const serverIP = this.configService.get('server_ip') || '128.140.35.238';
try {
const response = await axios_1.default.get(`http://${serverIP}:8082/api/health`, {
timeout: 5000
});
if (response.status === 200 && response.data.status === 'healthy') {
return {
status: 'AI-Proxy healthy',
version: response.data.version,
endpoints: Object.keys(response.data.endpoints || {}).length
};
}
else {
throw new Error('AI-Proxy not healthy');
}
}
catch (error) {
throw new Error(`AI-Proxy unreachable: ${error.message}`);
}
}
async checkServerConnection() {
const serverIP = this.configService.get('server_ip') || '128.140.35.238';
try {
// Check if we can reach the server
const response = await axios_1.default.get(`http://${serverIP}:8000`, {
timeout: 5000,
validateStatus: () => true // Accept any status code
});
return {
status: 'Server reachable',
serverIP,
responseCode: response.status
};
}
catch (error) {
if (error.code === 'ECONNREFUSED') {
throw new Error('Connection refused');
}
else if (error.code === 'ETIMEDOUT') {
throw new Error('Connection timeout');
}
else {
throw new Error(`Network error: ${error.message}`);
}
}
}
async checkConfiguration() {
const config = this.configService.getAll();
const requiredKeys = ['coolify_url', 'server_ip'];
const missing = requiredKeys.filter(key => !config[key]);
if (missing.length > 0) {
throw new Error(`Missing configuration: ${missing.join(', ')}`);
}
return {
status: 'Configuration valid',
configPath: this.configService.getConfigPath(),
keys: Object.keys(config).length
};
}
async checkServicesStatus() {
console.log(chalk_1.default.blue('\nš Services Status:'));
const services = [
{ name: 'Coolify', url: 'https://coolify.aerocorpindustries.org', port: 8000 },
{ name: 'AI-Proxy', url: 'http://128.140.35.238:8082', port: 8082 },
{ name: 'CapRover', url: 'http://client.aerocorpindustries.org:10000', port: 10000 },
{ name: 'Ollama', url: 'http://128.140.35.238:11434', port: 11434 }
];
for (const service of services) {
try {
const response = await axios_1.default.get(service.url, {
timeout: 3000,
validateStatus: () => true
});
const status = response.status < 400 ? 'healthy' : 'issues';
const color = status === 'healthy' ? 'green' : 'yellow';
console.log(chalk_1.default[color](` ā ${service.name}: ${status} (${response.status})`));
}
catch (error) {
console.log(chalk_1.default.red(` ā ${service.name}: unreachable`));
}
}
}
}
exports.HealthService = HealthService;
//# sourceMappingURL=health.js.map