Spaces:
Running
Running
Download index.html from Admintools/cpm-igr: direct link, hf CLI and curl.
- Browser
- Download file 39.3 kB
-
https://huggingface.co/spaces/Admintools/cpm-igr/resolve/main/index.html
- Command line
-
hf download hf://spaces/Admintools/cpm-igr/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Admintools/cpm-igr/resolve/main/index.html
39.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Network Device Monitor</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.28/jspdf.plugin.autotable.min.js"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| .status-online { | |
| background-color: #10b981; | |
| animation: pulse-green 2s infinite; | |
| } | |
| .status-offline { | |
| background-color: #ef4444; | |
| animation: pulse-red 2s infinite; | |
| } | |
| @keyframes pulse-green { | |
| 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); } | |
| 70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); } | |
| 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } | |
| } | |
| @keyframes pulse-red { | |
| 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); } | |
| 70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); } | |
| 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } | |
| } | |
| .fade-in { | |
| animation: fadeIn 0.5s; | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; } | |
| to { opacity: 1; } | |
| } | |
| .rotate { | |
| animation: rotation 2s infinite linear; | |
| } | |
| @keyframes rotation { | |
| from { transform: rotate(0deg); } | |
| to { transform: rotate(359deg); } | |
| } | |
| body { | |
| background-color: #1a1a1a; | |
| color: #e5e7eb; | |
| } | |
| .card { | |
| background-color: #2d2d2d; | |
| border: 1px solid #3d3d3d; | |
| } | |
| .table-header { | |
| background-color: #252525; | |
| } | |
| .table-row { | |
| border-color: #3d3d3d; | |
| } | |
| .table-cell { | |
| color: #e5e7eb; | |
| } | |
| .input-dark { | |
| background-color: #3d3d3d; | |
| border-color: #4d4d4d; | |
| color: #e5e7eb; | |
| } | |
| .input-dark:focus { | |
| border-color: #6366f1; | |
| box-shadow: 0 0 0 1px #6366f1; | |
| } | |
| .notification { | |
| position: fixed; | |
| bottom: 20px; | |
| right: 20px; | |
| z-index: 1000; | |
| max-width: 350px; | |
| transition: all 0.3s ease; | |
| } | |
| .notification-item { | |
| background-color: #3d3d3d; | |
| border-left: 4px solid; | |
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
| margin-bottom: 10px; | |
| transform: translateX(120%); | |
| animation: slideIn 0.3s forwards; | |
| } | |
| .notification-item.online { | |
| border-left-color: #10b981; | |
| } | |
| .notification-item.offline { | |
| border-left-color: #ef4444; | |
| } | |
| @keyframes slideIn { | |
| to { transform: translateX(0); } | |
| } | |
| .filter-active { | |
| background-color: #3b82f6 ; | |
| color: white ; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-900"> | |
| <div class="container mx-auto px-4 py-8"> | |
| <div class="flex justify-between items-center mb-8"> | |
| <h1 class="text-3xl font-bold text-gray-100"> | |
| <i class="fas fa-network-wired mr-2 text-blue-400"></i> Network Device Monitor | |
| </h1> | |
| <div class="flex items-center space-x-4"> | |
| <div class="relative"> | |
| <input type="file" id="fileInput" accept=".xlsx,.xls" class="hidden"> | |
| <label for="fileInput" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg cursor-pointer flex items-center transition-colors"> | |
| <i class="fas fa-file-excel mr-2"></i> Load Excel | |
| </label> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8"> | |
| <!-- Control Panel --> | |
| <div class="card rounded-xl shadow-md p-6 col-span-1"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-200"> | |
| <i class="fas fa-sliders-h mr-2 text-blue-400"></i> Control Panel | |
| </h2> | |
| <div class="space-y-4"> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-300 mb-1">Ping Interval (seconds)</label> | |
| <input type="number" id="pingInterval" min="1" value="5" class="w-full px-3 py-2 input-dark rounded-md focus:outline-none"> | |
| </div> | |
| <div class="flex space-x-3"> | |
| <button id="startPing" class="flex-1 bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg flex items-center justify-center transition-colors"> | |
| <i class="fas fa-play mr-2"></i> Start Ping | |
| </button> | |
| <button id="stopPing" class="flex-1 bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg flex items-center justify-center transition-colors" disabled> | |
| <i class="fas fa-stop mr-2"></i> Stop Ping | |
| </button> | |
| </div> | |
| <div class="pt-4 border-t border-gray-700"> | |
| <div class="flex items-center"> | |
| <div class="w-3 h-3 rounded-full status-online mr-2"></div> | |
| <span class="text-sm text-gray-300">Online: <span id="onlineCount" class="font-medium">0</span></span> | |
| </div> | |
| <div class="flex items-center mt-1"> | |
| <div class="w-3 h-3 rounded-full status-offline mr-2"></div> | |
| <span class="text-sm text-gray-300">Offline: <span id="offlineCount" class="font-medium">0</span></span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Uptime Stats --> | |
| <div class="card rounded-xl shadow-md p-6 col-span-1"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-200"> | |
| <i class="fas fa-chart-pie mr-2 text-blue-400"></i> Uptime Statistics | |
| </h2> | |
| <div class="h-40"> | |
| <canvas id="uptimeChart"></canvas> | |
| </div> | |
| <div class="mt-4 text-center"> | |
| <p class="text-sm text-gray-400">Average Uptime: <span id="avgUptime" class="font-semibold text-gray-200">0%</span></p> | |
| </div> | |
| </div> | |
| <!-- Response Time Stats --> | |
| <div class="card rounded-xl shadow-md p-6 col-span-1"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-200"> | |
| <i class="fas fa-stopwatch mr-2 text-blue-400"></i> Response Time | |
| </h2> | |
| <div class="h-40"> | |
| <canvas id="responseTimeChart"></canvas> | |
| </div> | |
| <div class="mt-4 text-center"> | |
| <p class="text-sm text-gray-400">Avg Response: <span id="avgResponse" class="font-semibold text-gray-200">0 ms</span></p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Filters and Search --> | |
| <div class="card rounded-xl shadow-md p-4 mb-4"> | |
| <div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4"> | |
| <div class="flex items-center space-x-2"> | |
| <span class="text-sm text-gray-300">Filter by:</span> | |
| <button id="filterAll" class="px-3 py-1 text-sm rounded-md bg-gray-700 text-gray-300 hover:bg-gray-600 filter-active">All</button> | |
| <button id="filterOnline" class="px-3 py-1 text-sm rounded-md bg-gray-700 text-gray-300 hover:bg-gray-600">Online</button> | |
| <button id="filterOffline" class="px-3 py-1 text-sm rounded-md bg-gray-700 text-gray-300 hover:bg-gray-600">Offline</button> | |
| </div> | |
| <div class="relative w-full md:w-64"> | |
| <input type="text" id="searchInput" placeholder="Search devices..." class="w-full px-4 py-2 input-dark rounded-md focus:outline-none pl-10"> | |
| <i class="fas fa-search absolute left-3 top-3 text-gray-400"></i> | |
| </div> | |
| <div class="flex space-x-2"> | |
| <button id="exportExcel" class="px-3 py-1 text-sm rounded-md bg-green-700 text-gray-300 hover:bg-green-600 flex items-center"> | |
| <i class="fas fa-file-excel mr-1"></i> Excel | |
| </button> | |
| <button id="exportPDF" class="px-3 py-1 text-sm rounded-md bg-red-700 text-gray-300 hover:bg-red-600 flex items-center"> | |
| <i class="fas fa-file-pdf mr-1"></i> PDF | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Device Table --> | |
| <div class="card rounded-xl shadow-md overflow-hidden mb-8"> | |
| <div class="px-6 py-4 border-b border-gray-700 flex justify-between items-center"> | |
| <h2 class="text-xl font-semibold text-gray-200"> | |
| <i class="fas fa-table mr-2 text-blue-400"></i> Device Status | |
| </h2> | |
| <div class="text-sm text-gray-400"> | |
| Last updated: <span id="lastUpdated" class="text-gray-300">Never</span> | |
| </div> | |
| </div> | |
| <div class="overflow-x-auto"> | |
| <table class="min-w-full divide-y divide-gray-700"> | |
| <thead class="table-header"> | |
| <tr> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">USER NAME</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">IGG</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">HOST NAME</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">IP ADDRESS</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">STATUS</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">LAST PING TIME</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">RESPONSE TIME</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">UPTIME</th> | |
| </tr> | |
| </thead> | |
| <tbody id="deviceTableBody" class="divide-y divide-gray-700"> | |
| <tr class="table-row"> | |
| <td colspan="8" class="px-6 py-4 text-center text-gray-400">No devices loaded. Please upload an Excel file.</td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| <!-- Timeline Chart --> | |
| <div class="card rounded-xl shadow-md p-6 mb-8"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-200"> | |
| <i class="fas fa-chart-line mr-2 text-blue-400"></i> Response Time History | |
| </h2> | |
| <div class="h-80"> | |
| <canvas id="timelineChart"></canvas> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Notification Container --> | |
| <div id="notificationContainer" class="notification"></div> | |
| <script> | |
| // Global variables | |
| let devices = []; | |
| let filteredDevices = []; | |
| let pingIntervalId = null; | |
| let pingHistory = {}; | |
| let chartData = { | |
| labels: [], | |
| datasets: [] | |
| }; | |
| let previousStatus = {}; | |
| let currentFilter = 'all'; | |
| // Initialize charts with dark theme | |
| const uptimeCtx = document.getElementById('uptimeChart').getContext('2d'); | |
| const responseTimeCtx = document.getElementById('responseTimeChart').getContext('2d'); | |
| const timelineCtx = document.getElementById('timelineChart').getContext('2d'); | |
| Chart.defaults.color = '#e5e7eb'; | |
| Chart.defaults.borderColor = '#3d3d3d'; | |
| const uptimeChart = new Chart(uptimeCtx, { | |
| type: 'doughnut', | |
| data: { | |
| labels: ['Online', 'Offline'], | |
| datasets: [{ | |
| data: [0, 0], | |
| backgroundColor: ['#10b981', '#ef4444'], | |
| borderWidth: 0 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| cutout: '70%', | |
| plugins: { | |
| legend: { | |
| position: 'bottom', | |
| labels: { | |
| color: '#e5e7eb' | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| const responseTimeChart = new Chart(responseTimeCtx, { | |
| type: 'bar', | |
| data: { | |
| labels: ['<50ms', '50-100ms', '100-200ms', '>200ms'], | |
| datasets: [{ | |
| label: 'Response Time Distribution', | |
| data: [0, 0, 0, 0], | |
| backgroundColor: [ | |
| '#10b981', | |
| '#a3e635', | |
| '#facc15', | |
| '#ef4444' | |
| ], | |
| borderWidth: 0 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| grid: { | |
| color: '#3d3d3d' | |
| } | |
| }, | |
| x: { | |
| grid: { | |
| color: '#3d3d3d' | |
| } | |
| } | |
| }, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| } | |
| } | |
| }); | |
| const timelineChart = new Chart(timelineCtx, { | |
| type: 'line', | |
| data: { | |
| labels: [], | |
| datasets: [] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| scales: { | |
| y: { | |
| beginAtZero: true, | |
| title: { | |
| display: true, | |
| text: 'Response Time (ms)', | |
| color: '#e5e7eb' | |
| }, | |
| grid: { | |
| color: '#3d3d3d' | |
| } | |
| }, | |
| x: { | |
| title: { | |
| display: true, | |
| text: 'Time', | |
| color: '#e5e7eb' | |
| }, | |
| grid: { | |
| color: '#3d3d3d' | |
| } | |
| } | |
| }, | |
| plugins: { | |
| tooltip: { | |
| mode: 'index', | |
| intersect: false, | |
| backgroundColor: '#2d2d2d', | |
| titleColor: '#e5e7eb', | |
| bodyColor: '#e5e7eb', | |
| borderColor: '#3d3d3d' | |
| }, | |
| legend: { | |
| position: 'bottom', | |
| labels: { | |
| color: '#e5e7eb' | |
| } | |
| } | |
| }, | |
| interaction: { | |
| mode: 'nearest', | |
| axis: 'x', | |
| intersect: false | |
| } | |
| } | |
| }); | |
| // DOM elements | |
| const fileInput = document.getElementById('fileInput'); | |
| const startPingBtn = document.getElementById('startPing'); | |
| const stopPingBtn = document.getElementById('stopPing'); | |
| const pingIntervalInput = document.getElementById('pingInterval'); | |
| const deviceTableBody = document.getElementById('deviceTableBody'); | |
| const onlineCount = document.getElementById('onlineCount'); | |
| const offlineCount = document.getElementById('offlineCount'); | |
| const avgUptime = document.getElementById('avgUptime'); | |
| const avgResponse = document.getElementById('avgResponse'); | |
| const lastUpdated = document.getElementById('lastUpdated'); | |
| const searchInput = document.getElementById('searchInput'); | |
| const filterAll = document.getElementById('filterAll'); | |
| const filterOnline = document.getElementById('filterOnline'); | |
| const filterOffline = document.getElementById('filterOffline'); | |
| const exportExcel = document.getElementById('exportExcel'); | |
| const exportPDF = document.getElementById('exportPDF'); | |
| const notificationContainer = document.getElementById('notificationContainer'); | |
| // Event listeners | |
| fileInput.addEventListener('change', handleFileUpload); | |
| startPingBtn.addEventListener('click', startPing); | |
| stopPingBtn.addEventListener('click', stopPing); | |
| searchInput.addEventListener('input', filterDevices); | |
| filterAll.addEventListener('click', () => setFilter('all')); | |
| filterOnline.addEventListener('click', () => setFilter('online')); | |
| filterOffline.addEventListener('click', () => setFilter('offline')); | |
| exportExcel.addEventListener('click', exportToExcel); | |
| exportPDF.addEventListener('click', exportToPDF); | |
| // Functions | |
| function handleFileUpload(e) { | |
| const file = e.target.files[0]; | |
| if (!file) return; | |
| const reader = new FileReader(); | |
| reader.onload = function(e) { | |
| const data = new Uint8Array(e.target.result); | |
| const workbook = XLSX.read(data, { type: 'array' }); | |
| const firstSheet = workbook.Sheets[workbook.SheetNames[0]]; | |
| const jsonData = XLSX.utils.sheet_to_json(firstSheet); | |
| devices = jsonData.map(device => ({ | |
| userName: device['USER NAME'] || '', | |
| igg: device['IGG'] || '', | |
| hostName: device['HOST NAME'] || '', | |
| ipAddress: device['IP ADDRESS'] || '', | |
| status: 'offline', // Todas as máquinas começam como offline | |
| lastPingTime: '', | |
| responseTime: 0, | |
| uptime: 0, | |
| checks: 0, | |
| onlineChecks: 0 | |
| })); | |
| // Initialize previous status and ping history | |
| devices.forEach(device => { | |
| const key = device.hostName || device.ipAddress; | |
| previousStatus[key] = 'offline'; | |
| if (!pingHistory[key]) { | |
| pingHistory[key] = []; | |
| } | |
| }); | |
| filteredDevices = [...devices]; | |
| renderDeviceTable(); | |
| updateStats(); | |
| }; | |
| reader.readAsArrayBuffer(file); | |
| } | |
| function renderDeviceTable() { | |
| if (filteredDevices.length === 0) { | |
| deviceTableBody.innerHTML = '<tr class="table-row"><td colspan="8" class="px-6 py-4 text-center text-gray-400">No devices match the current filter.</td></tr>'; | |
| return; | |
| } | |
| deviceTableBody.innerHTML = filteredDevices.map(device => ` | |
| <tr class="table-row fade-in"> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm table-cell">${device.userName}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm table-cell">${device.igg}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm table-cell">${device.hostName}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm table-cell">${device.ipAddress}</td> | |
| <td class="px-6 py-4 whitespace-nowrap"> | |
| <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${device.status === 'online' ? 'bg-green-900 text-green-200' : 'bg-red-900 text-red-200'}"> | |
| ${device.status === 'online' ? 'Online' : 'Offline'} | |
| </span> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm table-cell">${device.lastPingTime || 'Never'}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm table-cell">${device.responseTime ? `${device.responseTime} ms` : '-'}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm table-cell">${device.checks > 0 ? `${Math.round((device.onlineChecks / device.checks) * 100)}%` : '0%'}</td> | |
| </tr> | |
| `).join(''); | |
| } | |
| function updateStats() { | |
| const onlineDevices = devices.filter(d => d.status === 'online').length; | |
| const offlineDevices = devices.filter(d => d.status === 'offline').length; | |
| onlineCount.textContent = onlineDevices; | |
| offlineCount.textContent = offlineDevices; | |
| // Update uptime chart | |
| uptimeChart.data.datasets[0].data = [onlineDevices, offlineDevices]; | |
| uptimeChart.update(); | |
| // Calculate average uptime | |
| const avg = devices.length > 0 ? | |
| devices.reduce((sum, device) => sum + (device.checks > 0 ? (device.onlineChecks / device.checks) : 0), 0) / devices.length * 100 : 0; | |
| avgUptime.textContent = `${Math.round(avg)}%`; | |
| // Calculate response time distribution | |
| const responseTimes = devices.filter(d => d.status === 'online').map(d => d.responseTime); | |
| const dist = [0, 0, 0, 0]; // <50, 50-100, 100-200, >200 | |
| responseTimes.forEach(time => { | |
| if (time < 50) dist[0]++; | |
| else if (time < 100) dist[1]++; | |
| else if (time < 200) dist[2]++; | |
| else dist[3]++; | |
| }); | |
| responseTimeChart.data.datasets[0].data = dist; | |
| responseTimeChart.update(); | |
| // Calculate average response time | |
| const avgResp = responseTimes.length > 0 ? | |
| Math.round(responseTimes.reduce((sum, time) => sum + time, 0) / responseTimes.length) : 0; | |
| avgResponse.textContent = `${avgResp} ms`; | |
| // Update last updated time | |
| lastUpdated.textContent = new Date().toLocaleString(); | |
| } | |
| function updateTimelineChart() { | |
| const now = new Date(); | |
| const labels = Array.from({ length: 10 }, (_, i) => { | |
| const d = new Date(now); | |
| d.setMinutes(d.getMinutes() - (9 - i)); | |
| return d.toLocaleTimeString(); | |
| }); | |
| const datasets = devices.slice(0, 5).map((device, i) => { | |
| const history = pingHistory[device.hostName || device.ipAddress] || []; | |
| const data = Array(10).fill(null); | |
| // Fill the last 10 minutes of data | |
| history.slice(-10).forEach((entry, j) => { | |
| const timeDiff = (now - new Date(entry.time)) / (1000 * 60); // minutes ago | |
| const pos = 9 - Math.min(9, Math.floor(timeDiff)); | |
| if (pos >= 0 && pos < 10) { | |
| data[pos] = entry.responseTime; | |
| } | |
| }); | |
| return { | |
| label: device.hostName || device.ipAddress, | |
| data: data, | |
| borderColor: getColor(i), | |
| backgroundColor: 'rgba(0, 0, 0, 0)', | |
| tension: 0.3, | |
| fill: false, | |
| pointRadius: 3, | |
| pointHoverRadius: 5 | |
| }; | |
| }); | |
| timelineChart.data.labels = labels; | |
| timelineChart.data.datasets = datasets; | |
| timelineChart.update(); | |
| } | |
| function getColor(index) { | |
| const colors = [ | |
| '#6366f1', // indigo-500 | |
| '#ec4899', // pink-500 | |
| '#14b8a6', // teal-500 | |
| '#f59e0b', // amber-500 | |
| '#8b5cf6' // violet-500 | |
| ]; | |
| return colors[index % colors.length]; | |
| } | |
| async function pingDevice(device) { | |
| const startTime = Date.now(); | |
| const target = device.hostName || device.ipAddress; | |
| const previous = previousStatus[target]; | |
| try { | |
| // Simulate ping with timeout - agora com 95% de chance de falha para simular máquinas desligadas | |
| await new Promise((resolve, reject) => { | |
| setTimeout(() => { | |
| if (Math.random() > 0.95) { // Apenas 5% de chance de sucesso para demo | |
| resolve(); | |
| } else { | |
| reject(new Error('Request timed out - Device offline')); | |
| } | |
| }, 50 + Math.random() * 150); // Random response time between 50-200ms | |
| }); | |
| const responseTime = Date.now() - startTime; | |
| // Update device status | |
| device.status = 'online'; | |
| device.lastPingTime = new Date().toLocaleString(); | |
| device.responseTime = responseTime; | |
| device.checks++; | |
| device.onlineChecks++; | |
| // Record history | |
| if (!pingHistory[target]) pingHistory[target] = []; | |
| pingHistory[target].push({ | |
| time: new Date(), | |
| responseTime: responseTime, | |
| status: 'online' | |
| }); | |
| // Check for status change notification | |
| if (previous !== 'online') { | |
| showNotification(`${target} is now online`, 'online'); | |
| } | |
| previousStatus[target] = 'online'; | |
| return { success: true, responseTime }; | |
| } catch (error) { | |
| // Update device status | |
| device.status = 'offline'; | |
| device.lastPingTime = new Date().toLocaleString(); | |
| device.responseTime = 0; | |
| device.checks++; | |
| // Record history | |
| if (!pingHistory[target]) pingHistory[target] = []; | |
| pingHistory[target].push({ | |
| time: new Date(), | |
| responseTime: 0, | |
| status: 'offline' | |
| }); | |
| // Check for status change notification | |
| if (previous !== 'offline') { | |
| showNotification(`${target} is now offline`, 'offline'); | |
| } | |
| previousStatus[target] = 'offline'; | |
| return { success: false, error: error.message }; | |
| } | |
| } | |
| function showNotification(message, type) { | |
| const notification = document.createElement('div'); | |
| notification.className = `notification-item ${type}`; | |
| notification.innerHTML = ` | |
| <div class="p-4"> | |
| <div class="flex items-start"> | |
| <div class="flex-shrink-0 pt-0.5"> | |
| <i class="fas ${type === 'online' ? 'fa-check-circle text-green-500' : 'fa-exclamation-circle text-red-500'}"></i> | |
| </div> | |
| <div class="ml-3 w-0 flex-1"> | |
| <p class="text-sm font-medium text-gray-100">${message}</p> | |
| <p class="mt-1 text-xs text-gray-400">${new Date().toLocaleTimeString()}</p> | |
| </div> | |
| <div class="ml-4 flex-shrink-0 flex"> | |
| <button class="close-notification bg-transparent rounded-md inline-flex text-gray-400 hover:text-gray-300 focus:outline-none"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| notificationContainer.appendChild(notification); | |
| // Auto remove after 5 seconds | |
| setTimeout(() => { | |
| notification.style.opacity = '0'; | |
| setTimeout(() => { | |
| notification.remove(); | |
| }, 300); | |
| }, 5000); | |
| // Close button | |
| notification.querySelector('.close-notification').addEventListener('click', () => { | |
| notification.style.opacity = '0'; | |
| setTimeout(() => { | |
| notification.remove(); | |
| }, 300); | |
| }); | |
| } | |
| async function pingAllDevices() { | |
| startPingBtn.innerHTML = '<i class="fas fa-sync-alt rotate mr-2"></i> Pinging...'; | |
| startPingBtn.disabled = true; | |
| const pingPromises = devices.map(device => pingDevice(device)); | |
| await Promise.all(pingPromises); | |
| filterDevices(); | |
| updateStats(); | |
| updateTimelineChart(); | |
| if (pingIntervalId) { | |
| startPingBtn.innerHTML = '<i class="fas fa-play mr-2"></i> Pinging...'; | |
| } else { | |
| startPingBtn.innerHTML = '<i class="fas fa-play mr-2"></i> Start Ping'; | |
| startPingBtn.disabled = false; | |
| } | |
| } | |
| function startPing() { | |
| const interval = parseInt(pingIntervalInput.value) * 1000; | |
| if (isNaN(interval) || interval < 1000) { | |
| alert('Please enter a valid interval (at least 1 second)'); | |
| return; | |
| } | |
| pingAllDevices(); // Run immediately | |
| pingIntervalId = setInterval(pingAllDevices, interval); | |
| startPingBtn.disabled = true; | |
| stopPingBtn.disabled = false; | |
| } | |
| function stopPing() { | |
| if (pingIntervalId) { | |
| clearInterval(pingIntervalId); | |
| pingIntervalId = null; | |
| startPingBtn.innerHTML = '<i class="fas fa-play mr-2"></i> Start Ping'; | |
| startPingBtn.disabled = false; | |
| stopPingBtn.disabled = true; | |
| } | |
| } | |
| function filterDevices() { | |
| const searchTerm = searchInput.value.toLowerCase(); | |
| filteredDevices = devices.filter(device => { | |
| const matchesSearch = | |
| device.userName.toLowerCase().includes(searchTerm) || | |
| device.igg.toLowerCase().includes(searchTerm) || | |
| device.hostName.toLowerCase().includes(searchTerm) || | |
| device.ipAddress.toLowerCase().includes(searchTerm); | |
| const matchesFilter = | |
| currentFilter === 'all' || | |
| (currentFilter === 'online' && device.status === 'online') || | |
| (currentFilter === 'offline' && device.status === 'offline'); | |
| return matchesSearch && matchesFilter; | |
| }); | |
| renderDeviceTable(); | |
| } | |
| function setFilter(filter) { | |
| currentFilter = filter; | |
| // Update active filter button styles | |
| [filterAll, filterOnline, filterOffline].forEach(btn => { | |
| btn.classList.remove('filter-active'); | |
| }); | |
| if (filter === 'all') filterAll.classList.add('filter-active'); | |
| if (filter === 'online') filterOnline.classList.add('filter-active'); | |
| if (filter === 'offline') filterOffline.classList.add('filter-active'); | |
| filterDevices(); | |
| } | |
| function exportToExcel() { | |
| if (devices.length === 0) { | |
| alert('No devices to export'); | |
| return; | |
| } | |
| // Prepare data for export | |
| const exportData = devices.map(device => ({ | |
| 'USER NAME': device.userName, | |
| 'IGG': device.igg, | |
| 'HOST NAME': device.hostName, | |
| 'IP ADDRESS': device.ipAddress, | |
| 'STATUS': device.status === 'online' ? 'Online' : 'Offline', | |
| 'LAST PING TIME': device.lastPingTime, | |
| 'RESPONSE TIME (ms)': device.responseTime || '', | |
| 'UPTIME (%)': device.checks > 0 ? Math.round((device.onlineChecks / device.checks) * 100) : 0 | |
| })); | |
| // Create worksheet | |
| const ws = XLSX.utils.json_to_sheet(exportData); | |
| // Create workbook | |
| const wb = XLSX.utils.book_new(); | |
| XLSX.utils.book_append_sheet(wb, ws, "Device Status"); | |
| // Generate file name with timestamp | |
| const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); | |
| const fileName = `device_status_${timestamp}.xlsx`; | |
| // Export to Excel | |
| XLSX.writeFile(wb, fileName); | |
| } | |
| function exportToPDF() { | |
| if (devices.length === 0) { | |
| alert('No devices to export'); | |
| return; | |
| } | |
| // Initialize jsPDF | |
| const { jsPDF } = window.jspdf; | |
| const doc = new jsPDF(); | |
| // Add title | |
| doc.setFontSize(18); | |
| doc.text('Network Device Status Report', 105, 20, { align: 'center' }); | |
| // Add timestamp | |
| doc.setFontSize(10); | |
| doc.text(`Generated on: ${new Date().toLocaleString()}`, 105, 30, { align: 'center' }); | |
| // Prepare data for table | |
| const tableData = devices.map(device => [ | |
| device.userName, | |
| device.igg, | |
| device.hostName, | |
| device.ipAddress, | |
| device.status === 'online' ? 'Online' : 'Offline', | |
| device.lastPingTime || 'Never', | |
| device.responseTime ? `${device.responseTime} ms` : '-', | |
| device.checks > 0 ? `${Math.round((device.onlineChecks / device.checks) * 100)}%` : '0%' | |
| ]); | |
| // Add table | |
| doc.autoTable({ | |
| head: [['User', 'IGG', 'Host', 'IP', 'Status', 'Last Ping', 'Response', 'Uptime']], | |
| body: tableData, | |
| startY: 40, | |
| styles: { | |
| textColor: [0, 0, 0], | |
| fontSize: 8 | |
| }, | |
| headStyles: { | |
| fillColor: [41, 128, 185], | |
| textColor: [255, 255, 255] | |
| }, | |
| alternateRowStyles: { | |
| fillColor: [245, 245, 245] | |
| }, | |
| margin: { top: 40 } | |
| }); | |
| // Add statistics | |
| const onlineCount = devices.filter(d => d.status === 'online').length; | |
| const offlineCount = devices.filter(d => d.status === 'offline').length; | |
| const avgUptime = devices.length > 0 ? | |
| Math.round(devices.reduce((sum, device) => sum + (device.checks > 0 ? (device.onlineChecks / device.checks) : 0), 0) / devices.length * 100) : 0; | |
| const finalY = doc.lastAutoTable.finalY + 10; | |
| doc.setFontSize(12); | |
| doc.text('Summary Statistics', 14, finalY); | |
| doc.setFontSize(10); | |
| doc.text(`Online Devices: ${onlineCount}`, 14, finalY + 10); | |
| doc.text(`Offline Devices: ${offlineCount}`, 14, finalY + 20); | |
| doc.text(`Average Uptime: ${avgUptime}%`, 14, finalY + 30); | |
| // Generate file name with timestamp | |
| const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); | |
| const fileName = `device_status_${timestamp}.pdf`; | |
| // Save the PDF | |
| doc.save(fileName); | |
| } | |
| // Initialize with some demo data for visualization | |
| window.addEventListener('DOMContentLoaded', () => { | |
| // Add some sample data for the timeline chart | |
| const now = new Date(); | |
| const labels = Array.from({ length: 10 }, (_, i) => { | |
| const d = new Date(now); | |
| d.setMinutes(d.getMinutes() - (9 - i)); | |
| return d.toLocaleTimeString(); | |
| }); | |
| timelineChart.data.labels = labels; | |
| timelineChart.update(); | |
| // Set default filter | |
| setFilter('all'); | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=jair2323/cpm-igr" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |