Skip to content

Commit

Permalink
Adding the configuration to server.psd1
Browse files Browse the repository at this point in the history
  • Loading branch information
tinuwalther committed May 20, 2023
1 parent 1950e7f commit 0b80b50
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 371 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Version | Description | Date | Author
1.0.0 | Initial upload | 2023-05-19 | Martin Walther
1.0.1 | Fix ID in Layouts and Elements | 2023-05-19 | Martin Walther
1.0.2 | Adding the configuration to server.psd1 | 2023-05-20 | Martin Walther
1.0.3 | Reading configuration from server.psd1 | 2023-05-20 | Martin Walther
1.0.4 | Group configuration in server.psd1 | 2023-05-20 | Martin Walther
2 changes: 1 addition & 1 deletion bin/New-PshtmlESXiDiag.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,5 @@ end{
'{1:0}h {2:0}m {3:0}s {4:000}ms' -f $_.Days, $_.Hours, $_.Minutes, $_.Seconds, $_.Milliseconds
}
Write-Verbose $('Finished in:', $Formatted -Join ' ')
return $($OutFile)
"Diargam created: $($OutFile)"
}
45 changes: 31 additions & 14 deletions bin/Start-PodeServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ function Set-PodeRoutes {

Write-Verbose $('[', (Get-Date -f 'yyyy-MM-dd HH:mm:ss.fff'), ']', '[ Begin ]', "$($MyInvocation.MyCommand.Name)" -Join ' ')

New-PodeLoggingMethod -File -Name 'requests' -MaxDays 4 | Enable-PodeRequestLogging
New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging

Use-PodeWebTemplates -Title "PSXi App v$((Get-PodeConfig).PSXiVersion)" -Theme Dark

Add-PodeRoute -Method Get -Path '/classic_ESXiHosts_diag' -ScriptBlock {
Write-PodeViewResponse -Path 'Classic-ESXiHost-Diagram'
}
Expand All @@ -98,7 +93,7 @@ function Set-PodeRoutes {

# Add dynamic pages
$PodeRoot = $($PSScriptRoot).Replace('bin','pode')
foreach($item in (Get-ChildItem (Join-Path $PodeRoot -ChildPath 'pages'))){
foreach($item in (Get-ChildItem -Filter '*.ps1' -Path (Join-Path $PodeRoot -ChildPath 'pages'))){
. "$($item.FullName)"
}
Add-PodeEndpoint -Address * -Port 5989 -Protocol Http -Hostname 'psxi'
Expand Down Expand Up @@ -133,24 +128,41 @@ function Invoke-FileWatcher{
$DBFullPath = Join-Path $DBRoot -ChildPath 'psxi.db'
$TableName = ($FileEvent.Name) -replace '.csv'
if(Test-Path $DBFullPath){

"Database $DBFullPath already available" | Out-PodeHost
if((Get-PodeConfig).DebugLevel -eq 'Info'){
"Database-Check: Database $DBFullPath already exists" | Out-PodeHost
}
# Read header from csv-file and set it as column-names to the table
$th = (Get-Content -Path $FileEvent.FullPath -Encoding utf8 -TotalCount 1).Split(';') + 'Created'
"Ovewrite the Table $($TableName) if it already exists!" | Out-PodeHost
if((Get-PodeConfig).DebugLevel -eq 'Info'){
"Table-Check: Ovewrite the Table $($TableName) if its already exists" | Out-PodeHost
}
New-MySQLiteDBTable -Path $DBFullPath -TableName $TableName -ColumnNames $th -Force
# Add ID as primary-key th the table
Invoke-MySQLiteQuery -Path $DBFullPath -query "ALTER TABLE $TableName ADD ID [INTEGER PRIMARY KEY];"

switch -Regex ($TableName){
'_ESXiHosts' {
"Add content 'ESXiHost' to the table" | Out-PodeHost
if((Get-PodeConfig).DebugLevel -eq 'Info'){
"Item received: $($FileEvent.FullPath)" | Out-PodeHost
"Table-Check: Add content 'ESXiHost' to the table $TableName" | Out-PodeHost
}
Update-ESXiHostTable -CSVFile $FileEvent.FullPath -DBFile $DBFullPath -SqlTableName $TableName
Invoke-PshtmlESXiDiagram -DBFile $($DBFullPath) -ScriptFile $(Join-Path $PSScriptRoot -ChildPath "New-PshtmlESXiDiag.ps1") -SqlTableName $TableName
if((Get-PodeConfig).DebugLevel -eq 'Info'){
"Remove item: $($FileEvent.FullPath)" | Out-PodeHost
}
Remove-Item -Path $FileEvent.FullPath -Force
}
'_summary' {
"Add content 'Summary' to the table" | Out-PodeHost
if((Get-PodeConfig).DebugLevel -eq 'Info'){
"Item received: $($FileEvent.FullPath)" | Out-PodeHost
"Table-Check: Add content 'Summary' to the table $TableName" | Out-PodeHost
}
Update-SummaryTable -CSVFile $FileEvent.FullPath -DBFile $DBFullPath -SqlTableName $TableName
if((Get-PodeConfig).DebugLevel -eq 'Info'){
"Remove item: $($FileEvent.FullPath)" | Out-PodeHost
}
Remove-Item -Path $FileEvent.FullPath -Force
}
}

Expand Down Expand Up @@ -314,11 +326,14 @@ if($CurrentOS -eq [OSType]::Windows){
if(Test-IsElevated -OS $CurrentOS) {
$null = Set-HostEntry -Name 'psxi' -Elevated
Start-PodeServer {
Write-Host "Running on Windows with elevated Privileges since $(Get-Date)" -ForegroundColor Red
Write-Host "Press Ctrl. + C to terminate the Pode server" -ForegroundColor Yellow

Write-Host "Running on Windows with elevated Privileges since $(Get-Date)" -ForegroundColor Red
Get-PodeConfig | Out-Default

Use-PodeWebTemplates -Title "$((Get-PodeConfig).PSXi.AppName) v$((Get-PodeConfig).PSXi.Version)" -Theme Dark -NoPageFilter #-HideSidebar
New-PodeLoggingMethod -File -Name 'requests' -MaxDays 4 | Enable-PodeRequestLogging
New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging

# Initialize new SQLite database
$DBRoot = Join-Path $($PSScriptRoot).Replace('bin','pode') -ChildPath 'db'
$DBFullPath = Join-Path $DBRoot -ChildPath 'psxi.db'
Expand All @@ -329,7 +344,9 @@ if($CurrentOS -eq [OSType]::Windows){

# Set pode routes for web-sites
Set-PodeRoutes


Write-Host "Press Ctrl. + C to terminate the Pode server" -ForegroundColor Yellow

} -RootPath $($PSScriptRoot).Replace('bin','pode')
}else{
Write-Host "Running on Windows and start new session with elevated Privileges" -ForegroundColor Green
Expand Down
Empty file added pode/db/.gitkeep
Empty file.
Binary file modified pode/db/psxi.db
Binary file not shown.
Empty file added pode/errors/.gitkeep
Empty file.
Empty file added pode/logs/.gitkeep
Empty file.
11 changes: 8 additions & 3 deletions pode/pages/classic_esxi_diag.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
Add-PodeWebPage -Group 'Classic' -Name 'Classic ESXi Host Diagram' -Title 'Classic ESXi Host Diagram' -Icon 'server' -ScriptBlock {

<#
Classic Zone
#>
$GroupName = (Get-PodeConfig).PSXi.Group1
Add-PodeWebPage -Group $GroupName -Name "$GroupName ESXi Host Diagram" -Title "$GroupName ESXi Host Diagram" -Icon 'server' -ArgumentList $GroupName -ScriptBlock {
param($GroupName)

Set-PodeWebBreadcrumb -Items @(
New-PodeWebBreadcrumbItem -Name 'Home' -Url '/'
New-PodeWebBreadcrumbItem -Name 'Classic ESXi Host Diagram' -Url '/pages/PageName?value=Classic ESXi Hosts Diagram' -Active
New-PodeWebBreadcrumbItem -Name "$GroupName ESXi Host Diagram" -Url "/pages/PageName?value=$($GroupName) ESXi Hosts Diagram" -Active
)

New-PodeWebIFrame -Url '/classic_ESXiHosts_diag'
Expand Down
38 changes: 14 additions & 24 deletions pode/pages/classic_esxi_tbl.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Add-PodeWebPage -Group 'Classic' -Name 'Classic ESXi Host Table' -Title 'Classic ESXi Host Inventory' -Icon 'server' -ScriptBlock {
<#
Classic Zone
#>
$GroupName = (Get-PodeConfig).PSXi.Group1
Add-PodeWebPage -Group $($GroupName) -Name "$($GroupName) ESXi Host Table" -Title "$($GroupName) ESXi Host Inventory" -Icon 'server' -ArgumentList $GroupName -ScriptBlock {
param($GroupName)
#region module
if(-not(Get-InstalledModule -Name mySQLite -ea SilentlyContinue)){
Install-Module -Name mySQLite -Force
Expand All @@ -9,32 +14,26 @@

Set-PodeWebBreadcrumb -Items @(
New-PodeWebBreadcrumbItem -Name 'Home' -Url '/'
New-PodeWebBreadcrumbItem -Name 'Classic ESXi Host Inventory' -Url '/pages/PageName?value=Classic ESXi Hosts Table' -Active
New-PodeWebBreadcrumbItem -Name "$GroupName ESXi Host Inventory" -Url "/pages/PageName?value=$($GroupName) ESXi Hosts Table" -Active
)

$PodeRoot = $($PSScriptRoot).Replace('pages','db')
$PodeDB = Join-Path $PodeRoot -ChildPath 'psxi.db'
$SqlTableName = 'classic_summary', 'classic_ESXiHosts'
$PodeRoot = $($PSScriptRoot).Replace('pages','db')
$PodeDB = Join-Path $PodeRoot -ChildPath 'psxi.db'
$PSXiTables = (Get-PodeConfig).PSXi.Tables #'classic_summary', 'classic_ESXiHosts'
$SqlTableName = switch -regex ($PSXiTables){ $GroupName { $_ } }

if(Test-Path $PodeDB){

New-PodeWebContainer -NoBackground -Content @(

# $PSModule = Get-Module -ListAvailable pode*
# New-PodeWebCard -Name 'Module check' -Content @(
# foreach($module in $PSModule){
# New-PodeWebAlert -Value "Module: $($module.Name), Version: $($module.Version)" -Type Info
# }
# )

$TableExists = foreach($item in $SqlTableName){
$SqliteQuery = "SELECT * FROM sqlite_master WHERE name like '$item'"
Invoke-MySQLiteQuery -Path $PodeDB -Query $SqliteQuery
}
if([String]::IsNullOrEmpty($TableExists)){
New-PodeWebCard -Name 'Warning' -Content @(
New-PodeWebAlert -Value "Could not find table in $($PodeDB)" -Type Warning
New-PodeWebAlert -Value 'Please upload classic_ESXiHost.csv and classic_Summary.csv' -Type Important
New-PodeWebAlert -Value "Please upload CSV-files ($($SqlTableName))" -Type Important
)
}else{
$MySQLiteDB = Open-MySQLiteDB -Path $PodeDB
Expand All @@ -48,19 +47,10 @@
$SqliteQuery = "Select * from $($SqlTableName)"
$FullDB = Invoke-MySQLiteQuery -Path $PodeDB -Query $SqliteQuery
$VIServer = $FullDB | Group-Object vCenterServer | Select-Object -ExpandProperty Name
$Properties = @(
'HostName'
'Version'
'Manufacturer'
'Model'
'Cluster'
'PhysicalLocation'
'ConnectionState'
'Created'
)
$Properties = (Get-PodeConfig).PSXi.TableHeader

#region Summary
New-PodeWebCard -Name Summary -DisplayName 'Summary of Classic' -Content @(
New-PodeWebCard -Name Summary -DisplayName "Summary of $GroupName" -Content @(
New-PodeWebBadge -Colour Green -Value "$($VIServer.Count) vCenter"
$TotalCluster = $FullDB | Group-Object Cluster
New-PodeWebBadge -Colour Cyan -Value "$($TotalCluster.Count) Cluster"
Expand Down
11 changes: 8 additions & 3 deletions pode/pages/cloud_esxi_diag.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
Add-PodeWebPage -Group 'Cloud' -Name 'Cloud ESXi Host Diagram' -Title 'Cloud ESXi Host Diagram' -Icon 'server' -ScriptBlock {

<#
Cloud Zone
#>
$GroupName = (Get-PodeConfig).PSXi.Group2
Add-PodeWebPage -Group $GroupName -Name "$GroupName ESXi Host Diagram" -Title "$GroupName ESXi Host Diagram" -Icon 'cloud' -ArgumentList $GroupName -ScriptBlock {
param($GroupName)

Set-PodeWebBreadcrumb -Items @(
New-PodeWebBreadcrumbItem -Name 'Home' -Url '/'
New-PodeWebBreadcrumbItem -Name 'Cloud ESXi Host Diagram' -Url '/pages/PageName?value=Cloud ESXi Hosts Diagram' -Active
New-PodeWebBreadcrumbItem -Name "$GroupName ESXi Host Diagram" -Url "/pages/PageName?value=$($GroupName) ESXi Hosts Diagram" -Active
)

New-PodeWebIFrame -Url '/cloud_ESXiHosts_diag'
Expand Down
Loading

0 comments on commit 0b80b50

Please sign in to comment.