Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

PowerShell HTML Server Racks Cabinet Live Diagram maker Demo

This is test code I built to create dynamic Server / Racks cabinet live diagram on HTML as frontend from provided input inside Excel CSV using PowerShell script. I am still working on the code, whatever code I have worked so far I am posting it online. Basically after generating Diagram on HTML webpage looks like below.

To live update the racks I am taking few idea from earlier written script PowerShell HTML based Live Ping Monitor Demo. Make sure you have installed your Web Server to host this webpages and data.

Microsoft excel server racks cabinet HTML CSS JAVAScript PowerShell 42u 52u 18u rack servers hpe dell storage ups firewall diagram maker free live monitor.png

This is the implementation of small video, how this online diagram looks and data is generated.

This diagram is generated based on the input you provide inside CSV file, You will need to fill up the CSV files accordingly the columns mentioned. First column is UnitID, in my example my cabinet has 42 unit slots, and you need to give number from descending order. Next is unitSize. Generally rack server size comes in units from 1 to 4. for example if rack server is 1 or more unit in size mention the number of unit size. If server is 2 units in size, next unit is occupied by the same server so next unit size will be 0 as highlighted below. For 4 unit size next 3 slots will be 0.

Next if in case there is no server in the slot, mention it as yes in isEmpty. If occupied by server mention no to isEmpty. Provide objectType is a self explanatory (If you have any other type server object, which is not mentioned below, add an icon file with the same name). 

For fetchInfo column I am working on gathering the information from server and showing on the page. Other remaining columns are self explanatory.

Microsoft Excel CSV Powershell automation pwsh vmware vsphere virtualization Rack unit is empty empty slot fetch info server rack lab diagram creator.png

Once you Fill up the csv file, execute FetchRackInfo.ps1 PowerShell script to generate diagram.

 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
#<#
Clear-Host

$notExist = $true
$pingIteration = 1
do {
    Write-Host -ForegroundColor Cyan "- Ping Interation: $pingIteration"
    $rackUnits = Import-CSV $PSScriptRoot\RackServers.csv
    $allServerList = $rackUnits | Group-Object ServerName #Select-Object -Unique ServerName
    $nonEmptyServerList = $allServerList | where-Object {-not [string]::IsNullOrEmpty($_.name)}
    
    Get-Job | Remove-Job -Force -Confirm:$false

    $nonEmptyServerList | ForEach-Object { #-ThrottleLimit 10 -Parallel {
        $null = Start-ThreadJob {
            #$argServerName = $args[0]
            try {
                $pingTest = Test-Connection -TargetName $args[0] -Count 1 -ErrorAction Stop
                [PSCustomObject]@{
                    #New-Object psobject -Property[ordered]@{ 
                    id = $pingTest.Destination
                    servername = $args[0]
                    name = $pingTest.Destination
                    ipaddress = ($null -ne $pingTest.Address) ? $pingTest.Address.IPAddressToString : $pingTest.Destination
                    status = ($pingTest.Status.ToString() -eq 'Success') ? 'on' : 'off'
                } #[PSCustomObject]@{
            } #try {
            catch {
                [PSCustomObject]@{
                    id = $args[0]
                    servername = $args[0]
                    name = $args[0]
                    ipaddress = 'Unknown'
                    status = 'unknown'
                }
            } #catch {
            finally {}
        } -ArgumentList $_.Name.Trim() -ThrottleLimit 10 #$null = Start-ThreadJob
    } #$serverList | ForEach-Object {

    Start-Sleep -Seconds 10
    $report = Get-Job | Wait-Job | Receive-Job #| Select-Object @{N='id'; E={$_.Destination}}, @{N='name'; E={$_.Destination}}, @{N='ipAddress'; E={$_.Address.IPAddressToString}}, @{N='status'; E={($_.Status -eq 'Success') ? 'On' : 'Off'}} #Using the ternary operator syntax

    $information =  New-Object System.Collections.ArrayList
    foreach ($rack in $rackUnits)
    {
        if ($rack.ServerName -in $report.serverName)
        {
            $matchReport = $report | Where-object {$_.servername -eq  $rack.ServerName }
        }
        else {
            $matchReport = [PSCustomObject]@{
                id = 'n/a'
                servername = 'n/a'
                name = 'n/a'
                ipaddress = 'n/a'
                status = 'n/a'
            }
        }
        $rackInfo = @{}
        $serverInfo = @{}
        $rack.psobject.properties | Foreach-Object { $rackInfo[$_.Name] = $_.Value }
        $matchReport.psobject.properties | Foreach-Object { $serverInfo[$_.Name] = $_.Value }
        [void]$rackInfo.Add('serverinfo', $serverInfo)
        [void]$information.Add($rackInfo)
    }

    $information | ConvertTo-Json | Out-File $PSScriptRoot\dbase\serverData.json
    $pingIteration++
} while (
    # Condition that stops the loop if it returns false 
    $notExist -eq $true
) #while (
#>

Download this script Live_HTML_Rack_Cabinet_Maker.zip here or it is also available on github.com.

Useful Articles
Powershell adding leading zeros to string or int
PowerShell convert string to base64 value
PowerShell Encode or Decode an WebURL
Create an interactive HTML report with PowerShell data
Executing PowerShell script from PHP HTML web server
Send system disk space utilization HTML report Email using PowerShell
Send Email using PowerShell with .net object System.Net.Mail.MailMessage

Go Back



Comment

Blog Search

Page Views

11386876

Follow me on Blogarama