#!/usr/bin/env node
const { spawn } = require('child_process');
async function getAmazonCloudWatch30Day() {
console.log('π° AMAZON CLOUDWATCH 30-DAY AMORTIZED COST');
console.log('π’ AWS Account: 932213950603');
console.log('π§ Service: "Amazon CloudWatch" (exact name)');
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) {}
}
});
server.stderr.on('data', (data) => {
const msg = data.toString();
if (msg.includes('[CLOUDWATCH-FILTER]')) {
console.log('π§ SERVER:', msg.trim());
}
});
await new Promise(resolve => setTimeout(resolve, 2000));
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));
// Test Aug 4th first with exact name
console.log('π§ͺ Testing Aug 4th with "Amazon CloudWatch"...');
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: 2, method: "tools/call",
params: {
name: 'api___invoices_caui',
arguments: {
startDate: "2025-08-04",
endDate: "2025-08-04",
groupBy: "service",
periodGranLevel: "day",
costType: ["cost"],
isAmortized: true,
cloud_context: "aws",
accountId: "932213950603",
filters: {
service: "Amazon CloudWatch"
}
}
}
}) + '\n');
await new Promise(resolve => setTimeout(resolve, 8000));
const testResponse = responses.find(r => r.id === 2);
if (testResponse?.result?.content?.[0]?.text) {
const text = testResponse.result.content[0].text;
console.log(`β
Aug 4th response: ${text.length} chars`);
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) {
const cwResult = data.results.find(r => r.service === "Amazon CloudWatch");
if (cwResult) {
const cost = parseFloat(cwResult.cost || 0);
console.log(`π― Aug 4th Amazon CloudWatch: $${cost.toFixed(8)}`);
if (cost > 100 && cost < 300) {
console.log('β
Perfect! Matches expected ~$198');
// Now get 30-day costs
console.log('\nπ Getting 30-day costs...');
server.stdin.write(JSON.stringify({
jsonrpc: "2.0", id: 3, 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');
await new Promise(resolve => setTimeout(resolve, 12000));
const monthResponse = responses.find(r => r.id === 3);
if (monthResponse?.result?.content?.[0]?.text) {
const monthText = monthResponse.result.content[0].text;
const monthJsonMatch = monthText.match(/```json\n([\s\S]*?)\n```/);
if (monthJsonMatch) {
const monthData = JSON.parse(monthJsonMatch[1]);
if (Array.isArray(monthData) && monthData.length > 0) {
let totalCost = 0;
let dayCount = 0;
console.log('\nπ° Amazon CloudWatch Daily Costs (30 days):');
console.log('=' .repeat(55));
monthData.forEach((day, i) => {
if (day && day.total_cost !== undefined) {
const cost = parseFloat(day.total_cost || 0);
const date = day.usage_date || `Day ${i+1}`;
totalCost += cost;
dayCount++;
if (cost > 0) {
console.log(`π
${date}: $${cost.toFixed(8)}`);
}
}
});
console.log('\nπ FINAL AMAZON CLOUDWATCH RESULTS:');
console.log('=' .repeat(45));
console.log(`π° Total 30-day Amortized Cost: $${totalCost.toFixed(8)}`);
console.log(`π’ AWS Account: 932213950603`);
console.log(`π§ Service: Amazon CloudWatch`);
console.log(`π³ Cost Type: Amortized`);
console.log(`π
Period: July 27 - August 26, 2025 (31 days)`);
console.log(`π Daily Average: $${(totalCost/31).toFixed(8)}`);
console.log(`π Days processed: ${dayCount}`);
console.log('\nβ
SUCCESS - CloudWatch filtering works correctly!');
} else {
console.log('β Unexpected 30-day format');
}
}
} else {
console.log('β No 30-day response');
}
} else {
console.log(`β Unexpected cost: $${cost} (expected ~$198)`);
}
} else {
console.log('β Amazon CloudWatch not found in filtered results');
}
} else {
console.log('β No results in Aug 4th test');
}
} catch (e) {
console.log('β Parse error:', e.message);
}
} else {
console.log('β No JSON in response');
}
} else {
console.log('β No Aug 4th response');
}
server.kill();
}
getAmazonCloudWatch30Day().catch(console.error);