-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/groupe1 affichage terminal #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
f14f1f5
Refactor log display in Azure log analysis report with enhanced forma…
WhiteMuush 64f42a9
Enhance log highlighting functionality with additional comments for c…
WhiteMuush 8de5f8a
Update project configuration to include apprenants and ensure proper …
WhiteMuush File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": ["..."], | ||
| "api": { | ||
| "port": 5000, | ||
| "host": "localhost", | ||
| "route": "/api/logs", | ||
| "log_file": "server.log" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
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(); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.