Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"projet": "TP-Git-Collaboratif",
"version": "1.1.0",
"promotion": "DevSecOps Azure — Simplon",
"apprenants": [],
"apprenants": ["..."],
Comment thread
NathanTesseyre marked this conversation as resolved.
"api": {
"port": 5000,
"host": "localhost",
"route": "/api/logs",
"log_file": "server.log"
}
}
}
78 changes: 59 additions & 19 deletions node-client/app.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,75 @@
// Client Node.js — Interroge l'API Python et affiche un rapport des logs Azure
Comment thread
NathanTesseyre marked this conversation as resolved.
// -----------------------------------------------------------------

const path = require('path');
const axios = require('axios');
const { clear } = require('console');

// Configuration partagée chargée depuis config.json (à la racine du projet)
const config = require(path.join(__dirname, '..', 'config.json'));
const API_URL = `http://${config.api.host}:${config.api.port}${config.api.route}`;

const axios = require('axios');
/*
* This script retrieves log summaries from a Python API and prints
* a colored, human-readable Azure log analysis report to the terminal.
* It fetches counts for errors/warnings/info and lists detailed messages,
* highlighting important patterns (errors in red, warnings in yellow).
*/

// Codes de couleur ANSI pour le terminal
const RESET = '\x1b[0m';
const BOLD = '\x1b[1m';
const CYAN = '\x1b[36m';
const RED = '\x1b[31m';
const YELLOW = '\x1b[33m';
const GREEN = '\x1b[32m';
const WHITE = '\x1b[37m'

console.clear()

// Second list contains key word to highlight in Red
const RED_WORDS = /Azure Storage|Authentication failed|Database|timeout|insufficient permissions/i;

// First list contains key word to highlight in Yellow
const LOG_LIST = /Azure Storage|Authentication failed|Database|timeout|insufficient permissions|High memory|CPU usage|Disk space|SSL certificate/gi;

// Function to highlight important log patterns in red or yellow
function highlightLog(text) {
return text.replace(LOG_LIST, match =>
RED_WORDS.test(match) ? RED + match + RESET : YELLOW + match + RESET
);
}

async function getLogs() {
try {
// Fetch log summary data from the Python API
const response = await axios.get(API_URL);

// Extract data from the API response
const data = response.data;

console.log('\n========================================');
console.log(' RAPPORT D\'ANALYSE DES LOGS AZURE ');
console.log('========================================');
console.log(` Erreurs detectees : ${data.error_count}`);
console.log(` Avertissements : ${data.warning_count}`);
console.log(` Messages info : ${data.info_count}`);
console.log('\n--- Detail des erreurs ---');
data.errors.forEach(err => console.log(` > ${err}`));
console.log('\n--- Detail des avertissements ---');
data.warnings.forEach(warn => console.log(` > ${warn}`));
console.log('========================================\n');
// Get current date and time in French locale format
const now = new Date().toLocaleString('fr-FR');


console.log('');
console.log(BOLD + CYAN + '┌──────────────────────────────────────┐' + RESET);
console.log(BOLD + CYAN + '│' + WHITE + ' AZURE LOG ANALYSIS REPORT ' + CYAN + '│' + RESET);
console.log(BOLD + CYAN + '├──────────────────────────────────────┘' + RESET);
console.log(CYAN + '│ Version : ' + WHITE + `${config.version || 'N/A'}` + RESET);
console.log(CYAN + '│ Report generated at: ' + WHITE + `${now}` + RESET);
console.log(CYAN + '│' + RESET);
console.log(CYAN + '│ Errors detected : ' + WHITE + `${data.error_count}` + RESET);
console.log(CYAN + '│ Warnings : ' + WHITE + `${data.warning_count}` + RESET);
console.log(CYAN + '│ Info messages : ' + WHITE + `${data.info_count}` + RESET);
console.log(CYAN + '│' + RESET);
console.log(CYAN + '│' + RED + ' --- Error details ---' + RESET);
console.log(CYAN + '│' + RESET);
data.errors.forEach(err => console.log(CYAN + '│ ' + RED + '> ' + RESET + highlightLog(err)));
console.log(CYAN + '│' + RESET);
console.log(CYAN + '│' + YELLOW + ' --- Warning details ---' + RESET);
console.log(CYAN + '│' + RESET);
data.warnings.forEach(warn => console.log(CYAN + '│ ' + YELLOW + '> ' + RESET + highlightLog(warn)));
console.log(CYAN + '│' + RESET);

} catch (error) {
console.error('Erreur de connexion a l\'API Python :', error.message);
console.error('Failed to connect to Python API:', error.message);
}
}

getLogs();
getLogs();
Loading