Pode.Web
Pode.Web copied to clipboard
Loading the page immediately and refreshing the page later.
Hi,
Is it possible to organize the updating of information on the page, for example, by time without updating the entire page? For example ping the Server or Servers.
Thanks.
Hi @eugen257,
If I understand correctly, would Pode.Web's timers work?
Which element are you using, or have you an example? Some support auto-refreshing to periodically update just that element.
Hi @Badgerati,
for example:
New-PodeWebContainer -Content @( $Ping = Test-Connection -Count 1 -ComputerName 8.8.8.8 -ErrorAction SilentlyContinue New-PodeWebText -Value "Srv1" if($Ping){New-PodeWebBadge -Value 'OK' -Colour Green} else{New-PodeWebBadge -Value 'Fehler' -Colour Red} )
is it possible not to wait for the ping of all, for example, 100 servers, first load the page and after that the ping has already started and updated itself every 5 seconds
Thanks
As I get deeper into Pode.Web, I too am interested in all the ways available to update and sync changes on pages and elements. I hope this gets an answer.
Hi @eugen257, @fatherofinvention,
Apologies for the slow response,
To achieve what you're after I would recommend using a Pode Schedule to do the pinging instead. With a potential of 100 servers, the last thing you'd likely want is 100 requests causing 100 pings, and per person who has the webpage open!
I'd say a combination of Pode State and Schedules, plus a Pode.Web Timer should to the trick. You can setup a Pode Schedule to ping all of the servers, say minutely, and store the results in Pode State. On your page you could render all of the Badges as grey and "unknown", and then use a Pode.Web Timer to run every 30-60secs. This Timer's scriptblock could then fetch the ping results from State, and Update-PodeWebBadge
accordingly.
A Pode.Web Timer runs on the frontend, and makes AJAX calls behind the scenes which you can update elements with - without refreshing the whole page.
Something like the following (untested):
# initial state object with servers to ping and the result
Set-PodeState -Name 'ServerPingResults' -Value @{
SERVERNAME1 = 'Unknown'
SERVERNAME2 = 'Unknown'
SERVERNAME3 = 'Unknown'
}
# a minutely schedule to ping the servers in state, and store the results
New-PodeSchedule -Name 'PingServers' -Cron '@minutely' -ScriptBlock {
$servers = Get-PodeState -Name 'ServerPingResults'
foreach ($name in $servers.Keys) {
$servers[$name] = (Test-Connection -Count 1 -ComputerName $name -ErrorAction SilentlyContinue)
}
}
# status page
Add-PodeWebPage -Name 'Server Status' -Layouts @(
# render initial "unknown" server status badges for servers in state
foreach ($name in (Get-PodeState -Name 'ServerPingResults').Keys) {
New-PodeWebContainer -Content @(
New-PodeWebText -Value $name
New-PodeWebBadge -Id $name -Value 'Unknown' -Colour Grey
)
}
# a timer to run every 30s, and update the above badges based on server status from schedule
New-PodeWebTimer -Interval 30 -ScriptBlock {
$servers = Get-PodeState -Name 'ServerPingResults'
foreach ($name in $servers.Keys) {
if ($servers[$name]) {
Update-PodeWebBadge -Id $name -Value 'OK' -Colour Green
}
else {
Update-PodeWebBadge -Id $name -Value 'Fehler' -Colour Red
}
}
}
)
Hope that helps! :)
Super helpful reply @Badgerati , thank you!