#!/usr/bin/env node
/**
* Bank Hapoalim 8-Month Cost Summary - Comprehensive Analysis
* Using Customer Detection System for precise targeting
*/
const { spawn } = require('child_process');
const path = require('path');
console.log('π¦ BANK HAPOALIM - 8 MONTH COMPREHENSIVE COST SUMMARY');
console.log('β'.repeat(80));
console.log('Customer Detection System Status: β
OPERATIONAL');
console.log('Bank Hapoalim Account Key: 16185 (Verified from customerDivisions)');
console.log('β'.repeat(80));
// Calculate proper 8-month range
const today = new Date();
const startDate8Months = new Date(today.getFullYear(), today.getMonth() - 8, 1);
const endDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());
const startDateStr = startDate8Months.toISOString().split('T')[0];
const endDateStr = endDate.toISOString().split('T')[0];
console.log(`π
Analysis Period: ${startDateStr} to ${endDateStr}`);
console.log(`π Target Customer: Bank Hapoalim (using customer_account_key: 16185)`);
console.log(`π Expected: Up to 8 months of AWS cost data\n`);
const serverPath = path.join(__dirname, 'src', 'index.ts');
const server = spawn('npx', ['tsx', serverPath], {
env: { ...process.env },
stdio: ['pipe', 'pipe', 'pipe']
});
let responses = {};
let responseBuffer = '';
server.stdout.on('data', (data) => {
responseBuffer += data.toString();
const lines = responseBuffer.split('\n');
for (let i = 0; i < lines.length - 1; i++) {
const line = lines[i].trim();
if (line) {
try {
const response = JSON.parse(line);
if (response.id) {
responses[response.id] = response;
}
} catch (e) {}
}
}
responseBuffer = lines[lines.length - 1];
});
server.stderr.on('data', (data) => {
const output = data.toString();
if (output.includes('Umbrella MCP Server started successfully')) {
setTimeout(() => runAnalysis(), 1000);
}
});
async function runAnalysis() {
console.log('π Starting Bank Hapoalim Cost Analysis...\n');
// Initialize
server.stdin.write(JSON.stringify({
jsonrpc: '2.0',
method: 'initialize',
params: { protocolVersion: '0.1.0', capabilities: {}, clientInfo: { name: 'bank-hapoalim-summary', version: '1.0.0' }},
id: 0
}) + '\n');
await new Promise(resolve => setTimeout(resolve, 2000));
// Authenticate
console.log('π Authenticating with MSP account (david+allcloud@umbrellacost.com)...');
server.stdin.write(JSON.stringify({
jsonrpc: '2.0',
method: 'tools/call',
params: {
name: 'authenticate_user',
arguments: {
username: 'david+allcloud@umbrellacost.com',
password: 'B4*zcI7#F7poEC'
}
},
id: 1
}) + '\n');
await new Promise(resolve => setTimeout(resolve, 8000));
if (!responses[1]?.result?.content?.[0]?.text?.includes('Successfully authenticated')) {
console.log('β Authentication failed or unclear response');
console.log('Response:', responses[1]?.result?.content?.[0]?.text?.substring(0, 300) || 'None');
server.kill();
return;
}
console.log('β
Authentication successful\n');
// Get Bank Hapoalim costs
console.log('π Requesting Bank Hapoalim cost data...');
console.log('π― Using MSP customer detection: customer_account_key = 16185');
server.stdin.write(JSON.stringify({
jsonrpc: '2.0',
method: 'tools/call',
params: {
name: 'api___invoices_caui',
arguments: {
startDate: startDateStr,
endDate: endDateStr,
groupBy: 'none',
periodGranLevel: 'month',
costType: ['cost', 'discount'],
isUnblended: true,
cloud_context: 'aws',
customer_account_key: '16185' // Bank Hapoalim
}
},
id: 2
}) + '\n');
await new Promise(resolve => setTimeout(resolve, 12000));
displayResults();
}
function displayResults() {
console.log('\nπ° **BANK HAPOALIM - FINAL COST RESULTS**');
console.log('β'.repeat(80));
if (!responses[2]) {
console.log('β No cost data response received');
server.kill();
return;
}
if (responses[2].error) {
console.log('β Cost request error:', responses[2].error);
server.kill();
return;
}
const content = responses[2].result?.content?.find(c => c.type === 'text')?.text || '';
const jsonMatch = content.match(/```json\n([\s\S]*?)\n```/);
if (jsonMatch) {
try {
const data = JSON.parse(jsonMatch[1]);
console.log('π¦ **BANK HAPOALIM AWS COSTS - LAST 8 MONTHS**');
console.log('β'.repeat(60));
console.log(`π Customer: Bank Hapoalim`);
console.log(`π Account Key: 16185 (MSP Customer Detection)`);
console.log(`βοΈ Cloud: AWS`);
console.log(`π
Period: ${startDateStr} to ${endDateStr}`);
console.log('β'.repeat(60));
if (Array.isArray(data) && data.length > 0) {
let totalCost = 0;
let validMonths = 0;
console.log('\nπ **MONTHLY BREAKDOWN:**');
data.forEach((item, index) => {
const cost = parseFloat(item.total_cost || 0);
const date = item.usage_date || 'Unknown';
const [year, month] = date.split('-');
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const monthName = monthNames[parseInt(month) - 1] || month;
if (cost !== 0) {
totalCost += cost;
validMonths++;
}
const costDisplay = cost.toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
const indicator = cost > 0 ? 'π°' : cost < 0 ? 'πΈ' : 'βͺ';
console.log(` ${indicator} ${monthName} ${year}: $${costDisplay}`);
});
console.log('\nπ **SUMMARY STATISTICS:**');
console.log('β'.repeat(40));
console.log(`π° Total 8-Month Cost: $${totalCost.toLocaleString('en-US', {minimumFractionDigits: 2})}`);
console.log(`π Months with Data: ${data.length}`);
console.log(`π Valid Cost Months: ${validMonths}`);
console.log(`π Average Monthly: $${validMonths > 0 ? (totalCost / validMonths).toLocaleString('en-US', {minimumFractionDigits: 2}) : '0.00'}`);
console.log('\nβ
**CUSTOMER VERIFICATION:**');
console.log('π― Customer Detection: SUCCESSFUL');
console.log('π¦ Bank Name: Bank Hapoalim');
console.log('π Account Key: 16185');
console.log('π Data Source: MSP customerDivisions mapping');
console.log('π Authentication: MSP account (allcloud)');
} else {
console.log('β οΈ No cost data array found or empty dataset');
console.log('Data type:', typeof data);
console.log('Data preview:', JSON.stringify(data, null, 2).substring(0, 300));
}
} catch (e) {
console.log('β Error parsing cost data:', e.message);
}
} else {
console.log('β οΈ No JSON cost data found in response');
console.log('Response preview:', content.substring(0, 500));
}
console.log('\nπ― **BANK HAPOALIM COST ANALYSIS COMPLETE**');
console.log('β'.repeat(80));
server.kill();
}
setTimeout(() => {
console.error('β Analysis timeout');
server.kill();
process.exit(1);
}, 30000);