In questo articolo, utilizzeremo uno script PowerShell (.ps1) per creare un diagramma che mappa l'indirizzo pubblico degli agenti. Questo vi aiuterà a tenere traccia delle varie reti di cui fanno parte gli agenti di un cliente per una gestione più semplice.
Note: È necessario installare i moduli PSAtera e PSWriteHTML in Powershell prima di utilizzare questo script.
1. Copiate il seguente script.
Import-Module PSAtera Import-Module PSWriteHTML function Map-Agents($CustomerID) { # Get all Atera Agents for the customer $Agents = Get-AteraAgents -CustomerID $CustomerID New-Html -TitleText "Atera Agent Map" -Online -FilePath $PSScriptRoot\Atera-Agents.html { New-HTMLTabStyle -SlimTabs New-HTMLTab -Name "Atera Agents" { New-HTMLSection -HeaderText "Atera Networks" { New-HTMLPanel { New-HTMLDiagram -Height 'calc(85vh)' { New-DiagramOptionsPhysics -RepulsionNodeDistance 150 -Solver repulsion # Generate Level 1: Public network $Agents | Select-Object ReportedFromIP -Unique | ForEach-Object { New-DiagramNode -Label $_.ReportedFromIP -Level 1 -ColorBackground Red } $PrivateNetworks = @() foreach($Agent in $Agents) { # Ignore any self-assigned IP addresses $Agent.IPAddresses | Where-Object { !($_.StartsWith("169.254.")) } | ForEach-Object { $Address = [IPAddress]$_ $AddressBytes = $Address.GetAddressBytes() $Network = "" # Stupidly get the Network ID based on the Class of IP address if ($AddressBytes[0] -eq 10) { # Class A $Network = "10.0.0.0/8" } elseif ($AddressBytes[0] -eq 172 -and $AddressBytes[1] -ge 16 -and $AddressBytes[1] -le 31) { # Class B $Network = "172.16.$($AddressBytes[2]).0/16" } elseif ($AddressBytes[0] -eq 192 -and $AddressBytes[1] -eq 168) { $Network = "192.168.$($AddressBytes[2]).0/24" } # Create the Diagram node for the network ID under the public IP address if ($PrivateNetworks -notcontains "$Network,$($Agent.ReportedFromIP)") { $PrivateNetworks += "$Network,$($Agent.ReportedFromIP)" New-DiagramNode -Label $Network -Id "$Network,$($Agent.ReportedFromIP)" -To $Agent.ReportedFromIP -Level 2 -ArrowsToEnabled -ColorBackground Green } # Create the Diagram node for the agent under it's corrent network ID New-DiagramNode -Label "$($Agent.MachineName)`t$($Address.IPAddressToString)" -Level 3 -To "$Network,$($Agent.ReportedFromIP)" -ArrowsToEnabled } } } } } } } -ShowHTML }
2. Salvare lo script con il nome Map-Agents.ps1 ed eseguire quanto segue, sostituendo l'ID cliente con quello desiderato:
3. Verrà generato il seguente diagramma, che si aprirà nel browser predefinito.
- Rosso nodi: Indirizzi pubblici
- Verde nodi: Identificativi di rete
- Blu nodi: Gli agenti
È possibile aggiungere lo script in Atera ed eseguirlo attraverso un profilo IT Automaton.
NOTA: Lo script non è stato sottoposto a screening di funzionalità e non offre supporto per la risoluzione dei problemi. Si consiglia di esaminarlo e testarlo prima nel proprio ambiente di laboratorio.
Grazie, Dave Long, per aver creato questo script e per il tuo contributo alla comunità Atera!