Skip to main content
Glama
cloudwatch-final.cjsβ€’5.66 kB
#!/usr/bin/env node const { spawn } = require('child_process'); async function getCloudWatchAmortized() { console.log('πŸ’° CLOUDWATCH 30-DAY AMORTIZED COST'); console.log('=' .repeat(40)); 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) {} } }); 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, 5000)); // Get accounts with correct tool name server.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: 'api___user_management_accounts', arguments: {} } }) + '\n'); await new Promise(resolve => setTimeout(resolve, 4000)); const accountsResponse = responses.find(r => r.id === 2); let accountId = null; if (accountsResponse?.result?.content?.[0]?.text) { const text = accountsResponse.result.content[0].text; console.log('πŸ“‹ Accounts response received'); const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/); if (jsonMatch) { try { const data = JSON.parse(jsonMatch[1]); if (data.accounts && data.accounts.length > 0) { accountId = data.accounts[0].linkedaccid; console.log(`🏒 Using account: ${accountId}`); } } catch (e) { console.log('Error parsing accounts:', e.message); } } } else { console.log('❌ No accounts response'); } if (!accountId) { console.log('❌ Could not get account ID - using fallback approach'); // Try without specific account filtering 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: "service", periodGranLevel: "day", costType: ["cost"], isAmortized: "true", cloud_context: "aws", filters: { service: "Amazon CloudWatch" } } } }) + '\n'); } else { // Use specific account 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: "service", periodGranLevel: "day", costType: ["cost"], isAmortized: "true", cloud_context: "aws", accountId: accountId, filters: { service: "Amazon CloudWatch" } } } }) + '\n'); } console.log('πŸ” Getting CloudWatch amortized costs (30 days)...'); let found = false; for (let i = 0; i < 30 && !found; i++) { await new Promise(resolve => setTimeout(resolve, 1000)); const response = responses.find(r => r.id === 3); if (response?.result?.content?.[0]?.text) { found = true; const text = response.result.content[0].text; const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/); if (jsonMatch) { try { const data = JSON.parse(jsonMatch[1]); console.log('\nπŸ’° CLOUDWATCH AMORTIZED COST RESULTS'); console.log('=' .repeat(42)); if (data.results && data.results.length > 0) { let totalCost = 0; let daysWithCost = 0; data.results.forEach(day => { const cost = parseFloat(day.cost || 0); if (cost > 0) { totalCost += cost; daysWithCost++; console.log(`πŸ“… ${day.date}: $${cost.toFixed(6)}`); } }); console.log('\nπŸ† SUMMARY:'); console.log(`πŸ’° Total CloudWatch Cost (30 days): $${totalCost.toFixed(6)}`); console.log(`πŸ“Š Cost Type: Amortized`); console.log(`πŸ”§ Service: Amazon CloudWatch`); console.log(`πŸ“… Period: July 27 - August 26, 2025`); console.log(`πŸ“ˆ Daily Average: $${(totalCost / 30).toFixed(6)}`); console.log(`πŸ“Š Days with cost: ${daysWithCost}/30`); if (totalCost > 0) { console.log('\nβœ… CloudWatch amortized cost analysis complete'); } } else { console.log('❌ No cost data in response'); console.log('Available keys:', Object.keys(data)); } } catch (e) { console.log('❌ JSON parse error:', e.message); console.log('Response preview:', text.substring(0, 300)); } } else { console.log('❌ No JSON block found'); console.log('Response:', text.substring(0, 200)); } break; } if (i % 10 === 0 && i > 0) console.log(`⏳ ${i}s...`); } server.kill(); } getCloudWatchAmortized().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