Итак, я пишу PowerShell на html плату состояния сети, но у нее есть проблема, когда, если что-то не работает, таблица мигает и не загружает остальную часть таблицы. Я попытался изменить html refre sh с meta http-экв = 'refre sh' content = '5' на метатег при загрузке, но тогда он вообще не работал. Я все еще хак в PowerShell, но мне интересно, есть ли способ сделать это лучше. Заранее спасибо за любую помощь.
start .\updown.html
#timer loop
$timeout = new-timespan -Hours 12
$sw = [diagnostics.stopwatch]::StartNew()
while ($sw.elapsed -lt $timeout){
#timer loop
$WorkStations = Get-Content ".\data_files\WorkStations.txt"
$Network = Get-Content ".\data_files\Network.txt"
$Servers = Get-Content ".\data_files\Servers.txt"
$ESXi = Get-Content ".\data_files\ESXi.txt"
$AppServers = Get-Content ".\data_files\AppServers.txt"
$bla = @{}
$outFile = "updown.html"
if (Test-Path $outFile){del $outFile}
$header = "
<HTML>
<HEAD>
<meta http-equiv='refresh' content='5'>
</HEAD>
"
$style = "
<style>
* {
box-sizing: border-box;
}
body {
background-color: black;
}
table {
color : white;
border-collapse: collapse;
width: 33%;
}
td, tr {
color : white;
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
th {
background-color: #696969;
color : white;
border: 1px solid #dddddd;
text-align: center;
padding: 8px;
}
/* Style the header */
.header {
background-color: #f1f1f1;
padding: 30px;
text-align: center;
font-size: 35px;
}
/* Create two equal columns that floats next to each other */
.column {
float: left;
padding: 10px;
}
/* Left and right column */
.column.side {
width: 50%;
}
/* Clear floats after the columns */
.row:after {
content: '';
display: table;
clear: both;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
@media (max-width: 600px) {
.column.side {
width: 100%;
}
}
</style>
"
$bodyOpen = "
<BODY>
<div class='header'>
DATA MANAGMENT SYSTEM
</div>
<div class='row'>
<div class='column side'>
<table>
"
$bodyClose = "
</table>
</div>
<div class='column side' style='color:yellow;'>
<h2><p id='demo'></p></h2>
<script>
var d = new Date();
document.getElementById('demo').innerHTML = d;
</script>
<img src='.\data_files\logo.jpg'>
</div>
</div>
</BODY>
</HTML>
"
#generate HTML
Write-Output $header $style $bodyOpen | Out-File -Append $outFile
# Workstation loop
Write-output "<table style='float: left; width: 33.33%; padding: 50px;'><th>WorkStations</th>" | Out-File -Append $outFile
$WorkStations | ForEach-Object {
$ip = "$_"
if (Test-Connection -Count 1 -Quiet -ComputerName $ip) {
$bla[$_] = "UP"
Write-output "<tr><td><h2 style='color : green; textweight : bold;'> $ip UP </h1></tr></td>" | out-file -Append $outFile
}
else {
$bla[$_] = "DOWN"
Write-output "<tr><td><h2 style='color : red; textweight : bold;'> $ip DOWN </h1></tr></td>" | out-file -Append $outFile
}
}
#end loop
# Network loop
Write-output "<th>Network</th>" | Out-File -Append $outFile
$Network | ForEach-Object {
$ip = "$_"
if (Test-Connection -Count 1 -Quiet -ComputerName $ip) {
$bla[$_] = "UP"
Write-output "<tr><td><h2 style='color : green; textweight : bold;'> $ip UP </h1></tr></td>" | out-file -Append $outFile
}
else {
$bla[$_] = "DOWN"
Write-output "<tr><td><h2 style='color : red; textweight : bold;'> $ip DOWN </h1></tr></td>" | out-file -Append $outFile
}
}
#end loop
# Servers loop
Write-output "</table><table style='float: left; width: 33.33%; padding: 50px;'><th>Servers</th>" | Out-File -Append $outFile
$Servers | ForEach-Object {
$ip = "$_"
if (Test-Connection -Count 1 -Quiet -ComputerName $ip) {
$bla[$_] = "UP"
Write-output "<tr><td><h2 style='color : green; textweight : bold;'> $ip UP </h1></tr></td>" | out-file -Append $outFile
}
else {
$bla[$_] = "DOWN"
Write-output "<tr><td><h2 style='color : red; textweight : bold;'> $ip DOWN </h1></tr></td>" | out-file -Append $outFile
}
}
#end loop
# ESXi loop
Write-output "<th>ESXi</th>" | Out-File -Append $outFile
$ESXi | ForEach-Object {
$ip = "$_"
if (Test-Connection -Count 1 -Quiet -ComputerName $ip) {
$bla[$_] = "UP"
Write-output "<tr><td><h2 style='color : green; textweight : bold;'> $ip UP </h1></tr></td>" | out-file -Append $outFile
}
else {
$bla[$_] = "DOWN"
Write-output "<tr><td><h2 style='color : red; textweight : bold;'> $ip DOWN </h1></tr></td>" | out-file -Append $outFile
}
}
#end loop
# AppServers loop
Write-output "</table><table style='float: left; width: 33.33%; padding: 50px;'><th>AppServers</th>" | Out-File -Append $outFile
$AppServers | ForEach-Object {
$ip = "$_"
if (Test-Connection -Count 1 -Quiet -ComputerName $ip) {
$bla[$_] = "UP"
Write-output "<tr><td><h2 style='color : green; textweight : bold;'> $ip UP </h1></tr></td>" | out-file -Append $outFile
}
else {
$bla[$_] = "DOWN"
Write-output "<tr><td><h2 style='color : red; textweight : bold;'> $ip DOWN </h1></tr></td>" | out-file -Append $outFile
}
}
#end loop
#close HTML
Write-Output $bodyClose | Out-File -Append $outFile
#timer loop
start-sleep -seconds 10
}
write-host "stop"