Certificate Expiry Monitoring Dashboard using PowerShell
Polaris is a micro-framework to build the Wep API/s; similar like Flash (Python) but Polaris is having very minimum feathers & that is worked with PowerShell. Polaris Page can be restricted by Active Directory security group & APIs can be publish using SSL for security .
mkdir c:\temp
cd C:\temp\
git clone https://github.com/21bshwjt/pki-polaris.git
mkdir C:\WebApi\Logs
Copy-Item C:\temp\pki-polaris\* -Recurse C:\WebApi\ -Force -Verbose
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name Polaris -AllowClobber -Force
Install-Module -Name PSWriteHTML -AllowClobber -Force
New-PolarisGetRoute -Path "/certexpiry" -Scriptblock {
$pkiexp = . C:\WebApi\subroutes\certexpiry.ps1
$Response.SetContentType("text/html")
$Response.Send($pkiexp)
}
New-PolarisGetRoute -Path "/certexpiry" -Scriptblock {
if( -not $Request.User.IsInRole("sg-polaris") ) {
$Response.SetContentType('text/html')
$Html = Get-Content C:\WebApi\htmls\denied.html -Raw
$Response.Send($Html)
} else {
$pkiexp = . C:\WebApi\subroutes\certexpiry.ps1
$Response.SetContentType("text/html")
$Response.Send($pkiexp)
}
}
[void](Import-Module PSWriteHTML)
$Title = 'Dashboard | PKI-Expiry'
$icon = 'Your Image URL'
$headertxt = "<h1>Corp Certificate Expiry Report</h1>"
$TableTitle = "MSFT-CA1 Expiry Report"
$data = Get-Content "C:\WebApi\apicache\cert.json" | ConvertFrom-Json
$DbwriteTime = (Get-Item "C:\WebApi\apicache\cert.json").LastWriteTime
New-HTML -FavIcon $icon -TitleText $Title -AutoRefresh 50 {
New-HTMLContent -HeaderText "<center>$headertxt</center><span><center>Refreshed: $DbwriteTime</center></span>" {
New-HTMLTable -Title $TableTitle -DataTable $data -HideFooter -PagingOptions @(12, 24) {
#Conditional Formatting
TableConditionalFormatting -Name 'DaysUntilExpired' -ComparisonType number -Operator le -Value 364 -Color white -BackgroundColor Red
TableConditionalFormatting -Name 'DaysUntilExpired' -ComparisonType number -Operator ge -Value 363 -Color Black -BackgroundColor PaleGreen
}
}
}
$creds = Get-Credential
$HostName = ($env:COMPUTERNAME+"."+$env:USERDNSDOMAIN).ToLower()
$url = "https://$($HostName)/home"
(Invoke-WebRequest -Uri $url -Credential $creds).StatusCode
Path : /home
Method : GET
Path : /certexpiry
Method : GET
Path : /employees
Method : GET
Path : /json_payload
Method : GET
Path : /domaincontroller
Method : GET
An example route is present called jason_payload that can be used from any application and from any operating system.
_______________________________________
+ Please share your comments & feedbacks.