Spaces:
Running
Running
File size: 39,276 Bytes
0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 293b09c 0d130a0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | <!DOCTYPE html>
<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 !important;
color: white !important;
}
</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> |