1283 lines
43 KiB
HTML
1283 lines
43 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>OpenShift Resource Governance Tool</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background-color: #f5f5f5;
|
|
color: #333;
|
|
}
|
|
|
|
.header {
|
|
background: linear-gradient(135deg, #cc0000, #8b0000);
|
|
color: white;
|
|
padding: 1rem 2rem;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 1.8rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.header p {
|
|
margin-top: 0.5rem;
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 2rem;
|
|
}
|
|
|
|
.card {
|
|
background: white;
|
|
border-radius: 8px;
|
|
padding: 1.5rem;
|
|
margin-bottom: 1.5rem;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.card h2 {
|
|
color: #cc0000;
|
|
margin-bottom: 1rem;
|
|
font-size: 1.3rem;
|
|
}
|
|
|
|
.stats-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 1rem;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.stat-card {
|
|
background: white;
|
|
padding: 1.5rem;
|
|
border-radius: 8px;
|
|
text-align: center;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.stat-number {
|
|
font-size: 2rem;
|
|
font-weight: bold;
|
|
color: #cc0000;
|
|
}
|
|
|
|
.stat-label {
|
|
color: #666;
|
|
margin-top: 0.5rem;
|
|
}
|
|
|
|
.btn {
|
|
background: #cc0000;
|
|
color: white;
|
|
border: none;
|
|
padding: 0.75rem 1.5rem;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 1rem;
|
|
transition: background-color 0.2s;
|
|
}
|
|
|
|
.btn:hover {
|
|
background: #8b0000;
|
|
}
|
|
|
|
.btn:disabled {
|
|
background: #ccc;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: #6c757d;
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background: #545b62;
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
padding: 2rem;
|
|
color: #666;
|
|
}
|
|
|
|
.error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
padding: 1rem;
|
|
border-radius: 4px;
|
|
margin: 1rem 0;
|
|
}
|
|
|
|
.success {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
padding: 1rem;
|
|
border-radius: 4px;
|
|
margin: 1rem 0;
|
|
}
|
|
|
|
.validation-item {
|
|
padding: 1rem;
|
|
border-left: 4px solid #ccc;
|
|
margin: 0.75rem 0;
|
|
background: #f8f9fa;
|
|
border-radius: 6px;
|
|
border: 1px solid #dee2e6;
|
|
}
|
|
|
|
.validation-item.error {
|
|
border-left-color: #dc3545;
|
|
background: #f8d7da;
|
|
}
|
|
|
|
.validation-item.warning {
|
|
border-left-color: #ffc107;
|
|
background: #fff3cd;
|
|
}
|
|
|
|
.validation-item.critical {
|
|
border-left-color: #dc3545;
|
|
background: #f8d7da;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.validation-header {
|
|
font-weight: bold;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.validation-message {
|
|
color: #666;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.validation-recommendation {
|
|
font-style: italic;
|
|
color: #007bff;
|
|
}
|
|
|
|
.export-section {
|
|
display: flex;
|
|
gap: 1rem;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.export-section select,
|
|
.export-section input {
|
|
padding: 0.5rem;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.table th,
|
|
.table td {
|
|
padding: 0.75rem;
|
|
text-align: left;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
|
|
.table th {
|
|
background: #f8f9fa;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.severity-badge {
|
|
padding: 0.25rem 0.5rem;
|
|
border-radius: 12px;
|
|
font-size: 0.8rem;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.severity-error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
.severity-warning {
|
|
background: #fff3cd;
|
|
color: #856404;
|
|
}
|
|
|
|
.severity-critical {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
.hidden {
|
|
display: none;
|
|
}
|
|
|
|
/* Accordion Styles */
|
|
.accordion {
|
|
border: 1px solid #ddd;
|
|
border-radius: 8px;
|
|
margin-bottom: 1rem;
|
|
overflow: visible;
|
|
}
|
|
|
|
.accordion-header {
|
|
background: #f8f9fa;
|
|
padding: 1rem 1.5rem;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
border-bottom: 1px solid #ddd;
|
|
transition: all 0.2s;
|
|
position: relative;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.accordion-title {
|
|
flex: 0 0 auto;
|
|
font-weight: 600;
|
|
font-size: 1.1rem;
|
|
color: #333;
|
|
min-width: 0;
|
|
}
|
|
|
|
.accordion-stats {
|
|
display: flex;
|
|
gap: 1rem;
|
|
align-items: center;
|
|
flex: 0 0 auto;
|
|
margin-left: auto;
|
|
}
|
|
|
|
.accordion-stat {
|
|
font-size: 0.9rem;
|
|
font-weight: 500;
|
|
white-space: nowrap;
|
|
text-align: right;
|
|
}
|
|
|
|
.accordion-arrow {
|
|
font-size: 1.2rem;
|
|
transition: transform 0.3s ease;
|
|
color: #6c757d;
|
|
flex: 0 0 auto;
|
|
margin-left: 0.5rem;
|
|
}
|
|
|
|
.accordion-header:hover {
|
|
background: #e9ecef;
|
|
}
|
|
|
|
.accordion-header.active .accordion-arrow {
|
|
transform: rotate(90deg);
|
|
}
|
|
|
|
.accordion-header.active {
|
|
background: #cc0000;
|
|
color: white;
|
|
}
|
|
|
|
.accordion-title {
|
|
font-weight: 600;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.accordion-stats {
|
|
display: flex;
|
|
gap: 1rem;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.accordion-stat {
|
|
background: rgba(255,255,255,0.2);
|
|
padding: 0.25rem 0.5rem;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.accordion-content {
|
|
padding: 1rem 1.5rem;
|
|
max-height: 0;
|
|
overflow: hidden;
|
|
transition: max-height 0.3s ease;
|
|
background: white;
|
|
border-top: 1px solid #dee2e6;
|
|
}
|
|
|
|
.accordion-content.active {
|
|
max-height: none;
|
|
overflow: visible;
|
|
padding: 1rem 1.5rem;
|
|
}
|
|
|
|
/* Garantir que o conteúdo não seja cortado */
|
|
.accordion-content .validation-item:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.accordion-content .historical-validation:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.pod-list {
|
|
padding: 1rem 1.5rem;
|
|
}
|
|
|
|
.pod-item {
|
|
background: #f8f9fa;
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 6px;
|
|
padding: 1rem;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.pod-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.pod-name {
|
|
font-weight: 600;
|
|
color: #cc0000;
|
|
}
|
|
|
|
.pod-validations-count {
|
|
background: #6c757d;
|
|
color: white;
|
|
padding: 0.25rem 0.5rem;
|
|
border-radius: 12px;
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.validation-list {
|
|
margin-top: 0.5rem;
|
|
}
|
|
|
|
.validation-item {
|
|
padding: 0.75rem;
|
|
border-left: 4px solid #ccc;
|
|
margin: 0.25rem 0;
|
|
background: white;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.validation-item.error {
|
|
border-left-color: #dc3545;
|
|
}
|
|
|
|
.validation-item.warning {
|
|
border-left-color: #ffc107;
|
|
}
|
|
|
|
.validation-item.critical {
|
|
border-left-color: #dc3545;
|
|
font-weight: bold;
|
|
}
|
|
|
|
/* Pagination Styles */
|
|
.pagination {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
margin: 2rem 0;
|
|
}
|
|
|
|
.pagination button {
|
|
padding: 0.5rem 1rem;
|
|
border: 1px solid #ddd;
|
|
background: white;
|
|
cursor: pointer;
|
|
border-radius: 4px;
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.pagination button:hover:not(:disabled) {
|
|
background: #f8f9fa;
|
|
}
|
|
|
|
.pagination button:disabled {
|
|
background: #f8f9fa;
|
|
color: #6c757d;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
/* Historical Analysis Styles */
|
|
.historical-summary {
|
|
background: #f8f9fa;
|
|
border: 1px solid #dee2e6;
|
|
border-radius: 8px;
|
|
padding: 1rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.historical-summary h3 {
|
|
margin: 0 0 1rem 0;
|
|
color: #495057;
|
|
}
|
|
|
|
.historical-stats {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 1rem;
|
|
}
|
|
|
|
.historical-stat {
|
|
background: white;
|
|
padding: 0.75rem;
|
|
border-radius: 6px;
|
|
border-left: 4px solid #007bff;
|
|
}
|
|
|
|
.historical-stat h4 {
|
|
margin: 0 0 0.5rem 0;
|
|
font-size: 0.9rem;
|
|
color: #6c757d;
|
|
}
|
|
|
|
.historical-stat .value {
|
|
font-size: 1.5rem;
|
|
font-weight: bold;
|
|
color: #007bff;
|
|
}
|
|
|
|
.historical-validation {
|
|
background: #fff3cd;
|
|
border: 1px solid #ffeaa7;
|
|
border-radius: 6px;
|
|
padding: 1rem;
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
|
|
.historical-validation.error {
|
|
background: #f8d7da;
|
|
border-color: #f5c6cb;
|
|
}
|
|
|
|
.historical-validation.warning {
|
|
background: #fff3cd;
|
|
border-color: #ffeaa7;
|
|
}
|
|
|
|
.historical-validation.info {
|
|
background: #d1ecf1;
|
|
border-color: #bee5eb;
|
|
}
|
|
|
|
.historical-validation.critical {
|
|
background: #f8d7da;
|
|
border-color: #f5c6cb;
|
|
border-left: 4px solid #dc3545;
|
|
}
|
|
|
|
.pagination button.active {
|
|
background: #cc0000;
|
|
color: white;
|
|
border-color: #cc0000;
|
|
}
|
|
|
|
.pagination-info {
|
|
color: #666;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
/* Filters */
|
|
.filters {
|
|
display: flex;
|
|
gap: 1rem;
|
|
margin-bottom: 1rem;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
}
|
|
|
|
.filter-group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.25rem;
|
|
}
|
|
|
|
.filter-group label {
|
|
font-size: 0.9rem;
|
|
color: #666;
|
|
}
|
|
|
|
.filter-group select,
|
|
.filter-group input {
|
|
padding: 0.5rem;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.checkbox-label {
|
|
display: flex !important;
|
|
flex-direction: row !important;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.checkbox-label input[type="checkbox"] {
|
|
margin: 0;
|
|
width: auto;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.container {
|
|
padding: 1rem;
|
|
}
|
|
|
|
.stats-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.export-section {
|
|
flex-direction: column;
|
|
align-items: stretch;
|
|
}
|
|
|
|
.filters {
|
|
flex-direction: column;
|
|
align-items: stretch;
|
|
}
|
|
|
|
.accordion-stats {
|
|
flex-direction: column;
|
|
gap: 0.25rem;
|
|
}
|
|
|
|
.pod-header {
|
|
flex-direction: column;
|
|
align-items: flex-start;
|
|
gap: 0.5rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1>OpenShift Resource Governance Tool</h1>
|
|
<p>Resource governance tool for OpenShift clusters</p>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<!-- Cluster Statistics -->
|
|
<div class="stats-grid" id="statsGrid">
|
|
<div class="stat-card">
|
|
<div class="stat-number" id="totalPods">-</div>
|
|
<div class="stat-label">Total Pods</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-number" id="totalNamespaces">-</div>
|
|
<div class="stat-label">Namespaces</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-number" id="totalNodes">-</div>
|
|
<div class="stat-label">Nodes</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-number" id="criticalIssues">-</div>
|
|
<div class="stat-label">Critical Issues</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Controls -->
|
|
<div class="card">
|
|
<h2>Controls</h2>
|
|
<div style="display: flex; gap: 1rem; flex-wrap: wrap;">
|
|
<button class="btn" onclick="loadClusterStatus()">Refresh Status</button>
|
|
<button class="btn btn-secondary" onclick="loadValidationsByNamespace()">View Analysis</button>
|
|
<button class="btn btn-secondary" onclick="loadHistoricalValidations()">Historical Analysis</button>
|
|
<button class="btn btn-secondary" onclick="loadVPARecommendations()">View VPA</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Export Reports -->
|
|
<div class="card">
|
|
<h2>Export Reports</h2>
|
|
<div class="export-section">
|
|
<select id="exportFormat">
|
|
<option value="json">JSON</option>
|
|
<option value="csv">CSV</option>
|
|
<option value="pdf">PDF</option>
|
|
</select>
|
|
<input type="text" id="namespaces" placeholder="Namespaces (optional, comma-separated)">
|
|
<label>
|
|
<input type="checkbox" id="includeVPA" checked> Include VPA
|
|
</label>
|
|
<label>
|
|
<input type="checkbox" id="includeValidations" checked> Include Analysis
|
|
</label>
|
|
<button class="btn" onclick="exportReport()">Export</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Historical Analysis -->
|
|
<div class="card" id="historicalCard" style="display: none;">
|
|
<h2>Historical Analysis with Prometheus</h2>
|
|
|
|
<!-- Historical analysis filters -->
|
|
<div class="filters">
|
|
<div class="filter-group">
|
|
<label for="timeRangeFilter">Period:</label>
|
|
<select id="timeRangeFilter">
|
|
<option value="1h">1 hour</option>
|
|
<option value="6h">6 hours</option>
|
|
<option value="24h" selected>24 hours</option>
|
|
<option value="7d">7 days</option>
|
|
<option value="30d">30 days</option>
|
|
</select>
|
|
</div>
|
|
<div class="filter-group">
|
|
<label for="historicalSeverityFilter">Severity:</label>
|
|
<select id="historicalSeverityFilter">
|
|
<option value="">All</option>
|
|
<option value="error">Error</option>
|
|
<option value="warning">Warning</option>
|
|
<option value="info">Info</option>
|
|
<option value="critical">Critical</option>
|
|
</select>
|
|
</div>
|
|
<button class="btn" onclick="loadHistoricalValidations()">Apply Analysis</button>
|
|
</div>
|
|
|
|
<div id="historicalSummary" class="historical-summary"></div>
|
|
<div id="historicalValidationsList"></div>
|
|
</div>
|
|
|
|
<!-- Resource Analysis -->
|
|
<div class="card" id="validationsCard" style="display: none;">
|
|
<h2>Resource Analysis</h2>
|
|
|
|
<!-- Filters -->
|
|
<div class="filters">
|
|
<div class="filter-group">
|
|
<label for="severityFilter">Severity:</label>
|
|
<select id="severityFilter">
|
|
<option value="">All</option>
|
|
<option value="error">Error</option>
|
|
<option value="warning">Warning</option>
|
|
<option value="critical">Critical</option>
|
|
</select>
|
|
</div>
|
|
<div class="filter-group">
|
|
<label for="pageSizeFilter">Per page:</label>
|
|
<select id="pageSizeFilter">
|
|
<option value="10">10</option>
|
|
<option value="20" selected>20</option>
|
|
<option value="50">50</option>
|
|
<option value="100">100</option>
|
|
</select>
|
|
</div>
|
|
<div class="filter-group">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="includeSystemNamespaces" onchange="loadValidationsByNamespace()">
|
|
Include system namespaces
|
|
</label>
|
|
</div>
|
|
<button class="btn" onclick="loadValidationsByNamespace()">Apply Filters</button>
|
|
</div>
|
|
|
|
<div id="validationsList"></div>
|
|
<div id="pagination" class="pagination"></div>
|
|
</div>
|
|
|
|
<!-- Recomendações VPA -->
|
|
<div class="card" id="vpaCard" style="display: none;">
|
|
<h2>VPA Recommendations</h2>
|
|
<div id="vpaList"></div>
|
|
</div>
|
|
|
|
<!-- Loading -->
|
|
<div class="loading hidden" id="loading">
|
|
<p>Loading data...</p>
|
|
</div>
|
|
|
|
<!-- Error -->
|
|
<div class="error hidden" id="error"></div>
|
|
|
|
<!-- Success -->
|
|
<div class="success hidden" id="success"></div>
|
|
</div>
|
|
|
|
<script>
|
|
let currentData = null;
|
|
let currentPage = 1;
|
|
let currentPageSize = 20;
|
|
let currentSeverity = '';
|
|
|
|
// Carregar status inicial
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
loadClusterStatus();
|
|
});
|
|
|
|
async function loadClusterStatus() {
|
|
showLoading();
|
|
hideMessages();
|
|
|
|
try {
|
|
const response = await fetch('/api/v1/cluster/status');
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
currentData = data;
|
|
updateStats(data);
|
|
showSuccess('Cluster status loaded successfully. Loading analysis...');
|
|
|
|
// Automatically load validations after initial scan
|
|
await loadValidationsByNamespace();
|
|
|
|
} catch (error) {
|
|
showError('Error loading cluster status: ' + error.message);
|
|
} finally {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
async function loadValidations() {
|
|
if (!currentData) {
|
|
showError('Carregue o status do cluster primeiro');
|
|
return;
|
|
}
|
|
|
|
showLoading();
|
|
|
|
try {
|
|
const response = await fetch('/api/v1/validations');
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
displayValidations(data.validations || data);
|
|
document.getElementById('validationsCard').style.display = 'block';
|
|
|
|
} catch (error) {
|
|
showError('Error loading analysis: ' + error.message);
|
|
} finally {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
async function loadValidationsByNamespace() {
|
|
showLoading();
|
|
|
|
try {
|
|
const severity = document.getElementById('severityFilter').value;
|
|
const pageSize = parseInt(document.getElementById('pageSizeFilter').value);
|
|
const includeSystem = document.getElementById('includeSystemNamespaces').checked;
|
|
|
|
currentSeverity = severity;
|
|
currentPageSize = pageSize;
|
|
currentPage = 1;
|
|
|
|
const params = new URLSearchParams({
|
|
page: currentPage,
|
|
page_size: currentPageSize,
|
|
include_system_namespaces: includeSystem
|
|
});
|
|
|
|
if (severity) {
|
|
params.append('severity', severity);
|
|
}
|
|
|
|
const response = await fetch(`/api/v1/validations/by-namespace?${params}`);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
displayValidationsByNamespace(data);
|
|
document.getElementById('validationsCard').style.display = 'block';
|
|
|
|
} catch (error) {
|
|
showError('Error loading analysis by namespace: ' + error.message);
|
|
} finally {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
async function loadPage(page) {
|
|
currentPage = page;
|
|
showLoading();
|
|
|
|
try {
|
|
const params = new URLSearchParams({
|
|
page: currentPage,
|
|
page_size: currentPageSize
|
|
});
|
|
|
|
if (currentSeverity) {
|
|
params.append('severity', currentSeverity);
|
|
}
|
|
|
|
const response = await fetch(`/api/v1/validations/by-namespace?${params}`);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
displayValidationsByNamespace(data);
|
|
|
|
} catch (error) {
|
|
showError('Error loading page: ' + error.message);
|
|
} finally {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
async function loadVPARecommendations() {
|
|
showLoading();
|
|
|
|
try {
|
|
const response = await fetch('/api/v1/vpa/recommendations');
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const recommendations = await response.json();
|
|
displayVPARecommendations(recommendations);
|
|
document.getElementById('vpaCard').style.display = 'block';
|
|
|
|
} catch (error) {
|
|
showError('Error loading VPA recommendations: ' + error.message);
|
|
} finally {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
async function exportReport() {
|
|
showLoading();
|
|
|
|
try {
|
|
const format = document.getElementById('exportFormat').value;
|
|
const namespaces = document.getElementById('namespaces').value;
|
|
const includeVPA = document.getElementById('includeVPA').checked;
|
|
const includeValidations = document.getElementById('includeValidations').checked;
|
|
|
|
const requestBody = {
|
|
format: format,
|
|
includeVPA: includeVPA,
|
|
includeValidations: includeValidations
|
|
};
|
|
|
|
if (namespaces.trim()) {
|
|
requestBody.namespaces = namespaces.split(',').map(n => n.trim());
|
|
}
|
|
|
|
const response = await fetch('/api/v1/export', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(requestBody)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const result = await response.json();
|
|
showSuccess(`Report exported: ${result.filepath}`);
|
|
|
|
} catch (error) {
|
|
showError('Error exporting report: ' + error.message);
|
|
} finally {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
function updateStats(data) {
|
|
document.getElementById('totalPods').textContent = data.total_pods || 0;
|
|
document.getElementById('totalNamespaces').textContent = data.total_namespaces || 0;
|
|
document.getElementById('totalNodes').textContent = data.total_nodes || 0;
|
|
document.getElementById('criticalIssues').textContent = data.summary?.critical_issues || 0;
|
|
}
|
|
|
|
function displayValidations(validations) {
|
|
const container = document.getElementById('validationsList');
|
|
|
|
if (validations.length === 0) {
|
|
container.innerHTML = '<p>No validations found.</p>';
|
|
return;
|
|
}
|
|
|
|
let html = '<table class="table"><thead><tr><th>Pod</th><th>Namespace</th><th>Container</th><th>Type</th><th>Severity</th><th>Message</th></tr></thead><tbody>';
|
|
|
|
validations.forEach(validation => {
|
|
const severityClass = `severity-${validation.severity}`;
|
|
html += `
|
|
<tr>
|
|
<td>${validation.pod_name}</td>
|
|
<td>${validation.namespace}</td>
|
|
<td>${validation.container_name}</td>
|
|
<td>${validation.validation_type}</td>
|
|
<td><span class="severity-badge ${severityClass}">${validation.severity}</span></td>
|
|
<td>${validation.message}</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
|
|
html += '</tbody></table>';
|
|
container.innerHTML = html;
|
|
}
|
|
|
|
function displayValidationsByNamespace(data) {
|
|
const container = document.getElementById('validationsList');
|
|
const paginationContainer = document.getElementById('pagination');
|
|
|
|
if (!data.namespaces || data.namespaces.length === 0) {
|
|
container.innerHTML = '<p>No validations found.</p>';
|
|
paginationContainer.innerHTML = '';
|
|
return;
|
|
}
|
|
|
|
let html = '';
|
|
|
|
data.namespaces.forEach((namespace, index) => {
|
|
const pods = Object.values(namespace.pods);
|
|
const totalValidations = namespace.total_validations;
|
|
const errorCount = namespace.severity_breakdown.error || 0;
|
|
const warningCount = namespace.severity_breakdown.warning || 0;
|
|
|
|
html += `
|
|
<div class="accordion">
|
|
<div class="accordion-header" onclick="toggleAccordion(${index})">
|
|
<div class="accordion-title">${namespace.namespace}</div>
|
|
<div class="accordion-stats">
|
|
<div class="accordion-stat">${pods.length} pods</div>
|
|
<div class="accordion-stat">${totalValidations} analysis</div>
|
|
<div class="accordion-stat" style="color: #dc3545;">${errorCount} errors</div>
|
|
<div class="accordion-stat" style="color: #ffc107;">${warningCount} warnings</div>
|
|
</div>
|
|
<div class="accordion-arrow">▶</div>
|
|
</div>
|
|
<div class="accordion-content" id="accordion-${index}">
|
|
<div class="pod-list">
|
|
`;
|
|
|
|
pods.forEach(pod => {
|
|
if (pod.validations && pod.validations.length > 0) {
|
|
html += `
|
|
<div class="pod-item">
|
|
<div class="pod-header">
|
|
<div class="pod-name">${pod.pod_name}</div>
|
|
<div class="pod-validations-count">${pod.validations.length} validations</div>
|
|
</div>
|
|
<div class="validation-list">
|
|
`;
|
|
|
|
pod.validations.forEach(validation => {
|
|
const severityClass = validation.severity;
|
|
html += `
|
|
<div class="validation-item ${severityClass}">
|
|
<div class="validation-header">
|
|
<span class="severity-badge severity-${severityClass}">${validation.severity}</span>
|
|
${validation.validation_type} - ${validation.container_name}
|
|
</div>
|
|
<div class="validation-message">${validation.message}</div>
|
|
<div class="validation-recommendation">${validation.recommendation}</div>
|
|
</div>
|
|
`;
|
|
});
|
|
|
|
html += `
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
});
|
|
|
|
html += `
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
});
|
|
|
|
container.innerHTML = html;
|
|
|
|
// Renderizar paginação
|
|
renderPagination(data.pagination);
|
|
}
|
|
|
|
function renderPagination(pagination) {
|
|
const container = document.getElementById('pagination');
|
|
|
|
if (!pagination || pagination.total_pages <= 1) {
|
|
container.innerHTML = '';
|
|
return;
|
|
}
|
|
|
|
let html = '';
|
|
|
|
// Botão anterior
|
|
html += `<button onclick="loadPage(${pagination.page - 1})" ${pagination.page <= 1 ? 'disabled' : ''}>Previous</button>`;
|
|
|
|
// Pages
|
|
const startPage = Math.max(1, pagination.page - 2);
|
|
const endPage = Math.min(pagination.total_pages, pagination.page + 2);
|
|
|
|
if (startPage > 1) {
|
|
html += `<button onclick="loadPage(1)">1</button>`;
|
|
if (startPage > 2) {
|
|
html += `<span>...</span>`;
|
|
}
|
|
}
|
|
|
|
for (let i = startPage; i <= endPage; i++) {
|
|
const activeClass = i === pagination.page ? 'active' : '';
|
|
html += `<button class="${activeClass}" onclick="loadPage(${i})">${i}</button>`;
|
|
}
|
|
|
|
if (endPage < pagination.total_pages) {
|
|
if (endPage < pagination.total_pages - 1) {
|
|
html += `<span>...</span>`;
|
|
}
|
|
html += `<button onclick="loadPage(${pagination.total_pages})">${pagination.total_pages}</button>`;
|
|
}
|
|
|
|
// Botão próximo
|
|
html += `<button onclick="loadPage(${pagination.page + 1})" ${pagination.page >= pagination.total_pages ? 'disabled' : ''}>Next</button>`;
|
|
|
|
// Informações da paginação
|
|
html += `<div class="pagination-info">
|
|
Page ${pagination.page} of ${pagination.total_pages}
|
|
(${pagination.total} namespaces)
|
|
</div>`;
|
|
|
|
container.innerHTML = html;
|
|
}
|
|
|
|
function toggleAccordion(index) {
|
|
const accordion = document.querySelectorAll('.accordion')[index];
|
|
const header = accordion.querySelector('.accordion-header');
|
|
const content = accordion.querySelector('.accordion-content');
|
|
|
|
const isActive = header.classList.contains('active');
|
|
|
|
// Fechar todos os acordeões
|
|
document.querySelectorAll('.accordion-header').forEach(h => h.classList.remove('active'));
|
|
document.querySelectorAll('.accordion-content').forEach(c => c.classList.remove('active'));
|
|
|
|
// Abrir o selecionado se não estava ativo
|
|
if (!isActive) {
|
|
header.classList.add('active');
|
|
content.classList.add('active');
|
|
}
|
|
}
|
|
|
|
function displayVPARecommendations(recommendations) {
|
|
const container = document.getElementById('vpaList');
|
|
|
|
if (recommendations.length === 0) {
|
|
container.innerHTML = '<p>No VPA recommendations found.</p>';
|
|
return;
|
|
}
|
|
|
|
let html = '<table class="table"><thead><tr><th>Name</th><th>Namespace</th><th>Target</th><th>Recommendations</th></tr></thead><tbody>';
|
|
|
|
recommendations.forEach(rec => {
|
|
html += `
|
|
<tr>
|
|
<td>${rec.name}</td>
|
|
<td>${rec.namespace}</td>
|
|
<td>${rec.target_ref?.kind}/${rec.target_ref?.name || 'N/A'}</td>
|
|
<td>${JSON.stringify(rec.recommendations, null, 2)}</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
|
|
html += '</tbody></table>';
|
|
container.innerHTML = html;
|
|
}
|
|
|
|
function showLoading() {
|
|
document.getElementById('loading').classList.remove('hidden');
|
|
}
|
|
|
|
function hideLoading() {
|
|
document.getElementById('loading').classList.add('hidden');
|
|
}
|
|
|
|
function showError(message) {
|
|
const errorDiv = document.getElementById('error');
|
|
errorDiv.textContent = message;
|
|
errorDiv.classList.remove('hidden');
|
|
setTimeout(() => errorDiv.classList.add('hidden'), 5000);
|
|
}
|
|
|
|
function showSuccess(message) {
|
|
const successDiv = document.getElementById('success');
|
|
successDiv.textContent = message;
|
|
successDiv.classList.remove('hidden');
|
|
setTimeout(() => successDiv.classList.add('hidden'), 3000);
|
|
}
|
|
|
|
function hideMessages() {
|
|
document.getElementById('error').classList.add('hidden');
|
|
document.getElementById('success').classList.add('hidden');
|
|
}
|
|
|
|
// Historical analysis functions
|
|
async function loadHistoricalValidations() {
|
|
showLoading();
|
|
|
|
try {
|
|
const timeRange = document.getElementById('timeRangeFilter').value;
|
|
const severity = document.getElementById('historicalSeverityFilter').value;
|
|
|
|
// Carregar resumo histórico
|
|
const summaryResponse = await fetch(`/api/v1/cluster/historical-summary?time_range=${timeRange}`);
|
|
if (summaryResponse.ok) {
|
|
const summaryData = await summaryResponse.json();
|
|
displayHistoricalSummary(summaryData.summary);
|
|
}
|
|
|
|
// Load historical validations
|
|
const params = new URLSearchParams({
|
|
time_range: timeRange
|
|
});
|
|
|
|
if (severity) {
|
|
params.append('severity', severity);
|
|
}
|
|
|
|
const response = await fetch(`/api/v1/validations/historical?${params}`);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
displayHistoricalValidations(data);
|
|
document.getElementById('historicalCard').style.display = 'block';
|
|
|
|
} catch (error) {
|
|
showError('Error loading historical analysis: ' + error.message);
|
|
} finally {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
function displayHistoricalSummary(summary) {
|
|
const container = document.getElementById('historicalSummary');
|
|
|
|
if (!summary || Object.keys(summary).length === 0) {
|
|
container.innerHTML = '<p>Unable to get historical data from Prometheus.</p>';
|
|
return;
|
|
}
|
|
|
|
const cpuUtilization = summary.cpu_utilization || 0;
|
|
const memoryUtilization = summary.memory_utilization || 0;
|
|
|
|
container.innerHTML = `
|
|
<h3>Historical Cluster Summary (${summary.time_range})</h3>
|
|
<div class="historical-stats">
|
|
<div class="historical-stat">
|
|
<h4>CPU Utilization</h4>
|
|
<div class="value">${cpuUtilization.toFixed(1)}%</div>
|
|
</div>
|
|
<div class="historical-stat">
|
|
<h4>Memory Utilization</h4>
|
|
<div class="value">${memoryUtilization.toFixed(1)}%</div>
|
|
</div>
|
|
<div class="historical-stat">
|
|
<h4>CPU Usage</h4>
|
|
<div class="value">${summary.cpu_usage ? summary.cpu_usage.toFixed(3) : '0'} cores</div>
|
|
</div>
|
|
<div class="historical-stat">
|
|
<h4>Memory Usage</h4>
|
|
<div class="value">${summary.memory_usage ? (summary.memory_usage / (1024*1024*1024)).toFixed(2) : '0'} GiB</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
function displayHistoricalValidations(data) {
|
|
const container = document.getElementById('historicalValidationsList');
|
|
|
|
if (!data.validations || data.validations.length === 0) {
|
|
container.innerHTML = '<p>No historical validations found.</p>';
|
|
return;
|
|
}
|
|
|
|
// Filtrar por severidade se especificado
|
|
let validations = data.validations;
|
|
const severity = document.getElementById('historicalSeverityFilter').value;
|
|
if (severity) {
|
|
validations = validations.filter(v => v.severity === severity);
|
|
}
|
|
|
|
// Agrupar por namespace
|
|
const groupedByNamespace = {};
|
|
validations.forEach(validation => {
|
|
if (!groupedByNamespace[validation.namespace]) {
|
|
groupedByNamespace[validation.namespace] = [];
|
|
}
|
|
groupedByNamespace[validation.namespace].push(validation);
|
|
});
|
|
|
|
let html = '';
|
|
Object.keys(groupedByNamespace).forEach(namespace => {
|
|
const namespaceValidations = groupedByNamespace[namespace];
|
|
const errorCount = namespaceValidations.filter(v => v.severity === 'error').length;
|
|
const warningCount = namespaceValidations.filter(v => v.severity === 'warning').length;
|
|
const infoCount = namespaceValidations.filter(v => v.severity === 'info').length;
|
|
const criticalCount = namespaceValidations.filter(v => v.severity === 'critical').length;
|
|
|
|
html += `
|
|
<div class="accordion">
|
|
<div class="accordion-header" onclick="toggleAccordion(this)">
|
|
<div>
|
|
<strong>${namespace}</strong>
|
|
<span class="badge">${namespaceValidations.length} validations</span>
|
|
</div>
|
|
<div class="severity-badges">
|
|
${criticalCount > 0 ? `<span class="badge severity-critical">${criticalCount} critical</span>` : ''}
|
|
${errorCount > 0 ? `<span class="badge severity-error">${errorCount} error</span>` : ''}
|
|
${warningCount > 0 ? `<span class="badge severity-warning">${warningCount} warning</span>` : ''}
|
|
${infoCount > 0 ? `<span class="badge severity-info">${infoCount} info</span>` : ''}
|
|
</div>
|
|
<span class="accordion-icon">▼</span>
|
|
</div>
|
|
<div class="accordion-content">
|
|
${namespaceValidations.map(validation => `
|
|
<div class="historical-validation ${validation.severity}">
|
|
<div class="validation-header">
|
|
<strong>${validation.pod_name}</strong> - ${validation.container_name}
|
|
<span class="severity-badge severity-${validation.severity}">${validation.severity}</span>
|
|
</div>
|
|
<div class="validation-message">${validation.message}</div>
|
|
<div class="validation-recommendation">
|
|
<strong>Recommendation:</strong> ${validation.recommendation}
|
|
</div>
|
|
</div>
|
|
`).join('')}
|
|
</div>
|
|
</div>
|
|
`;
|
|
});
|
|
|
|
container.innerHTML = html;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|