#!/usr/bin/env node
const { spawn } = require('child_process');
async function getCloudWatch30DayFixed() {
console.log('π° CLOUDWATCH 30-DAY AMORTIZED COST - USING FIXED SERVER-SIDE FILTERING');
console.log('π’ AWS Account: 932213950603');
console.log('π
Period: July 27 - August 26, 2025 (30 days)');
console.log('π§ Using server-side filters (like UI)');
const server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
UMBRELLA_API_BASE_URL: 'https://api-front.umbrellacost.io/api/v1'
}
});
const responses = [];
server.stdout.on('data', (data) => {
const lines = data.toString().split('\n').filter(line => line.trim());
for (const line of lines) {
try {
responses.push(JSON.parse(line));
} catch (e) {}
}
});
await new Promise(resolve => setTimeout(resolve, 2000));
// Auth
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: 1, method: "tools/call",
params: {
name: 'authenticate_user',
arguments: { username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' }
}
}) + '\n');
console.log('π Authenticating...');
await new Promise(resolve => setTimeout(resolve, 6000));
// CloudWatch 30-day query using SERVER-SIDE filtering (the fix we implemented)
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: 2, method: "tools/call",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-07-27",
endDate: "2025-08-26",
groupBy: "none",
periodGranLevel: "day",
costType: ["cost"],
isAmortized: true,
cloud_context: "aws",
accountId: "932213950603",
filters: {
service: "Amazon CloudWatch"
}
}
}
}) + '\n');
console.log('π Getting CloudWatch costs with server-side filtering...');
for (let i = 0; i < 25; i++) {
await new Promise(resolve => setTimeout(resolve, 1000));
const response = responses.find(r => r.id === 2);
if (response?.result?.content?.[0]?.text) {
const text = response.result.content[0].text;
console.log('β
Response received!');
const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
if (data.results && data.results.length > 0) {
let totalCost = 0;
let daysWithCost = 0;
console.log('\nπ° CloudWatch Daily Amortized Costs (30 days):');
console.log('=' .repeat(50));
data.results.forEach(day => {
const cost = parseFloat(day.cost || 0);
if (cost > 0) {
totalCost += cost;
daysWithCost++;
console.log(`π
${day.date}: $${cost.toFixed(10)}`);
}
});
console.log('\nπ FINAL ANSWER:');
console.log(`π° CloudWatch 30-day Amortized Cost: $${totalCost.toFixed(10)}`);
console.log(`π’ AWS Account: 932213950603`);
console.log(`π§ Service: Amazon CloudWatch (server-side filtered)`);
console.log(`π³ Cost Type: Amortized`);
console.log(`π
Period: July 27 - August 26, 2025`);
console.log(`π Daily Average: $${(totalCost / 30).toFixed(10)}`);
console.log(`π Days with costs: ${daysWithCost}/30`);
// Reference to previous validation
console.log('\nπ Calculation Method:');
console.log('β
Uses server-side filtering (matches UI behavior)');
console.log('β
Same method that fixed Aug 4th discrepancy ($198.50 vs $201.06)');
console.log('β
Amortized cost calculation with proper account filtering');
} else {
console.log('β No results found');
console.log('Data keys:', Object.keys(data));
if (data.message) console.log('Message:', data.message);
}
} catch (e) {
console.log('β Parse error:', e.message);
console.log('Response preview:', text.substring(0, 500));
}
} else {
console.log('Raw response:', text);
}
break;
}
if (i % 5 === 0 && i > 0) console.log(`β³ ${i}s...`);
}
server.kill();
}
getCloudWatch30DayFixed().catch(console.error);