Skip to main content
Glama
answer-q7-8months.cjsβ€’6.87 kB
#!/usr/bin/env node const { spawn } = require('child_process'); async function answerQ7() { console.log('πŸ“Š Q7: SHOW ME THE TOTAL AWS AMORTIZED COST PER MONTH FOR THE LAST 8 MONTHS'); console.log('=' .repeat(80)); // Calculate 8 months back from August 2025 const endDate = '2025-08-27'; const startDate = '2025-01-01'; // 8 months: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug 2025 console.log(`πŸ“… Period: ${startDate} to ${endDate} (8 months)`); console.log('☁️ Cloud: AWS'); console.log('πŸ’° Cost Type: Amortized'); console.log('πŸ“ˆ Granularity: Monthly'); console.log(''); 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 { const response = JSON.parse(line); responses.push(response); } catch (e) {} } }); server.stderr.on('data', () => {}); // Suppress server logs await new Promise(resolve => setTimeout(resolve, 2000)); // Authenticate 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...\n'); await new Promise(resolve => setTimeout(resolve, 5000)); // Q7: AWS amortized cost per month for last 8 months console.log('πŸ“‘ Making API call for Q7...'); console.log('Parameters:'); console.log(` β€’ Start Date: ${startDate}`); console.log(` β€’ End Date: ${endDate}`); console.log(' β€’ Group By: none'); console.log(' β€’ Period: month'); console.log(' β€’ Cost Type: cost (amortized)'); console.log(' β€’ Cloud Context: aws'); console.log(' β€’ Account ID: 932213950603'); console.log(''); server.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: 'api___invoices_caui', arguments: { startDate: startDate, endDate: endDate, groupBy: 'none', periodGranLevel: 'month', costType: ['cost'], isAmortized: true, cloud_context: 'aws', accountId: '932213950603' } } }) + '\n'); console.log('⏳ Waiting for response...\n'); await new Promise(resolve => setTimeout(resolve, 15000)); const response = responses.find(r => r.id === 2); if (!response) { console.log('❌ NO RESPONSE RECEIVED'); server.kill(); return; } if (response.error) { console.log('❌ ERROR:', response.error.message || 'Unknown error'); server.kill(); return; } if (response.result?.content?.[0]?.text) { const text = response.result.content[0].text; console.log('πŸ“„ COMPLETE API RESPONSE:'); console.log('=' .repeat(80)); console.log(text); console.log('=' .repeat(80)); // Parse JSON if present const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/); if (jsonMatch) { try { const data = JSON.parse(jsonMatch[1]); console.log('\nπŸ“Š PARSED DATA ANALYSIS:'); console.log('=' .repeat(50)); if (Array.isArray(data)) { console.log(`β€’ Data Type: Array with ${data.length} items`); console.log(`β€’ First item keys: ${Object.keys(data[0] || {}).join(', ')}`); // Calculate monthly totals for 8 months const monthlyTotals = {}; let grandTotal = 0; data.forEach(item => { const date = item.usage_date || item.date || ''; const cost = parseFloat(item.total_cost || item.cost || 0); const month = date.substring(0, 7); // YYYY-MM format if (month) { if (!monthlyTotals[month]) monthlyTotals[month] = 0; monthlyTotals[month] += cost; } grandTotal += cost; }); console.log('\nπŸ’° 8-MONTH AWS AMORTIZED COST BREAKDOWN:'); console.log('-'.repeat(50)); const months = ['2025-01', '2025-02', '2025-03', '2025-04', '2025-05', '2025-06', '2025-07', '2025-08']; months.forEach(month => { const cost = monthlyTotals[month] || 0; const monthName = new Date(month + '-01').toLocaleDateString('en-US', { year: 'numeric', month: 'long' }); console.log(`πŸ“… ${monthName}: $${cost.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`); }); console.log('-'.repeat(50)); console.log(`πŸ† TOTAL AWS AMORTIZED COST (8 months): $${grandTotal.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`); // Calculate average monthly cost const averageMonthlyCost = grandTotal / 8; console.log(`πŸ“ˆ AVERAGE MONTHLY COST: $${averageMonthlyCost.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`); // Show monthly trend console.log('\nπŸ“Š MONTHLY TREND ANALYSIS:'); months.forEach((month, index) => { const cost = monthlyTotals[month] || 0; const monthName = new Date(month + '-01').toLocaleDateString('en-US', { month: 'short' }); let trend = ''; if (index > 0) { const prevCost = monthlyTotals[months[index - 1]] || 0; const change = ((cost - prevCost) / prevCost * 100); if (change > 0) { trend = ` (↗️ +${change.toFixed(1)}%)`; } else if (change < 0) { trend = ` (β†˜οΈ ${change.toFixed(1)}%)`; } else { trend = ` (β†’ 0.0%)`; } } console.log(` ${monthName} 2025: $${cost.toFixed(2)}${trend}`); }); console.log('\nβœ… Q7 ANSWER COMPLETE - 8 MONTHS AWS AMORTIZED COSTS SHOWN'); } else { console.log('β€’ Data Type: Object'); console.log('β€’ Keys:', Object.keys(data).join(', ')); } } catch (e) { console.log('❌ JSON parsing error:', e.message); } } else { console.log('\n⚠️ No JSON data found in response'); } } else { console.log('❌ INVALID RESPONSE FORMAT'); } server.kill(); } answerQ7().catch(console.error);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daviddraiumbrella/invoice-monitoring'

If you have feedback or need assistance with the MCP directory API, please join our Discord server