-
-
Save canberkaslan/38c708de7c49fb8e5a20b046c2679048 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-module PSWriteHTML | |
#Import server list | |
$Servers = Import-Csv -Path "C:\Couchbase\ServerList.csv" | |
#Get Couchbase informations json | |
$Result = $Servers | ForEach-Object -Parallel { | |
#Import main function for threads. | |
(. "C:\Couchbase\Get-CbServer.ps1") | |
$Credential = Import-CliXml -Path "C:\Couchbase\CbCred.xml" | |
Get-CbServer -CbServer $_ -CbCredential $Credential | select @{N='Json'; E={$_}} | |
} -ThrottleLimit $env:NUMBER_OF_PROCESSORS | |
#Split result | |
$HealthyServers = $Result | select -ExpandProperty Json | ConvertFrom-Json -Depth 10 | where {$_.status -eq 'healthy' -and $_.clusterMembership -eq 'active'} | sort uuid, CbServer | |
$UnhealthyServers = $Result | select -ExpandProperty Json | ConvertFrom-Json -Depth 10 | where {$_.Notes -notlike "*Unauthorized*" -and ($_.status -ne 'healthy' -or $_.clusterMembership -ne 'active')} | sort uuid, CbServer | |
$UnauthorizedServers = $Result | select -ExpandProperty Json | ConvertFrom-Json -Depth 10 | where {$_.Notes -like "*Unauthorized*"} | sort uuid, CbServer | |
#Some customization for HTML output | |
$dt_UnhealthyServers = $UnhealthyServers | select CbServer, status, clusterMembership, @{N='Services'; E={$_.services -join ', '}}, @{N='Buckets'; E={$_.bucket -join ', '}}, clusterName, Notes, CollectionDate | |
$dt_HealthyServers = $HealthyServers | select CbServer, status, clusterMembership, @{N='Services'; E={$_.services -join ', '}}, @{N='Buckets'; E={$_.bucket -join ', '}}, clusterName, CollectionDate | |
$dt_UnauthorizedServers = $UnauthorizedServers | select CbServer, Notes, CollectionDate | |
#Generate HTML | |
$CollectionTime = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") | |
New-HTML -TitleText "Couchbase Status" -FilePath "C:\Couchbase\StatusDashboard.html" { | |
New-HTMLText -Text "Overall Couchbase Server Status" -FontSize 20 -Alignment center | |
New-HTMLSection -JustifyContent center -Invisible { | |
Chart { | |
ChartToolbar | |
ChartLegend -Name 'Healthy', 'Unhealthy', 'Unauthorized' -Color Green, Red, Gray | |
ChartBar -Value $dt_HealthyServers.Count, $dt_UnhealthyServers.Count, $dt_UnauthorizedServers.Count | |
ChartBarOptions -Type barStacked -DataLabelsColor White | |
} -Height 125 -Width 1000 | |
} | |
if ($dt_UnhealthyServers.count -gt 0) { | |
New-HTMLSection -HeaderText "Unhealthy Servers" -CanCollapse -HeaderTextAlignment center -HeaderBackGroundColor Red -Content { | |
New-Htmlpanel { | |
New-HTMLTable -DataTable $dt_UnhealthyServers { | |
TableHeader -Names 'status', 'clusterMembership' -Title 'Status' | |
} -PagingOptions 10,20,50 -FreezeColumnsLeft 1 -HideFooter -OrderMulti -Style nowrap, row-border | |
} -Invisible -Width '98%' -Margin '10px' | |
} -JustifyContent center | |
} | |
if ($dt_HealthyServers.count -gt 0) { | |
New-HTMLSection -HeaderText "Healthy Servers" -HeaderBackGroundColor Green -Collapsed -CanCollapse -HeaderTextAlignment center -Content { | |
New-Htmlpanel { | |
New-HTMLTable -DataTable $dt_HealthyServers { | |
TableHeader -Names 'status', 'clusterMembership' -Title 'Status' | |
} -PagingOptions 10,20,50 -FreezeColumnsLeft 1 -HideFooter -OrderMulti -Style nowrap, row-border | |
} -Invisible -Width '98%' -Margin '10px' | |
} -JustifyContent center | |
} | |
if ($dt_UnauthorizedServers.count -gt 0) { | |
New-HTMLSection -HeaderText "Unauthorized Servers" -HeaderBackGroundColor Gray -Collapsed -CanCollapse -HeaderTextAlignment center -Content { | |
New-Htmlpanel { | |
New-HTMLTable -DataTable $dt_UnauthorizedServers { | |
TableHeader -Names 'status', 'clusterMembership' -Title 'Status' | |
} -PagingOptions 10,20,50 -FreezeColumnsLeft 1 -HideFooter -OrderMulti -Style nowrap, row-border | |
} -Invisible -Width '98%' -Margin '10px' | |
} -JustifyContent center | |
} | |
"Updated: $CollectionTime" | |
} -Encoding UTF8 -Online -AutoRefresh 300 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment