Kind of a PS newb, but trying to get a single sensor to go out and check a list of URLs for SSL cert, exipiring date and how many days left until expired. I would like to set each site as a channel, then have a threshold of 120 days as warning and 30 days as error/down. I have been using this script as a feed for another script, having both of them run at a certain interval and then email results monthly, but would like to move the process to PRTG. I have the following script, found on Stack Overflow:
$WebsiteURLs= @("google.com","aol.com","yahoo.com","espn.com") $WebsitePort=443 $Threshold=120 $Severe=30 $ID=0 Write-Host "# Website_URL: Current Certificate: Expiration Date: Days Remaining: Errors:" foreach ($WebsiteURL in $WebsiteURLs){ $CommonName=$WebsiteURL $ID+=1 Try{ $Conn = New-Object System.Net.Sockets.TcpClient($WebsiteURL,$WebsitePort) Try { $Stream = New-Object System.Net.Security.SslStream($Conn.GetStream(),$false, { param($sender, $certificate, $chain, $sslPolicyErrors) return $true }) $Stream.AuthenticateAsClient($CommonName) $Cert = $Stream.Get_RemoteCertificate() $CN=(($cert.Subject -split "=")[1] -split ",")[0] $ValidTo = [datetime]::Parse($Cert.GetExpirationDatestring()) $ValidDays = $($ValidTo - [datetime]::Now).Days $MyFontColor="darkgreen" if ($ValidDays -lt $Threshold) { $MyFontColor="darkyellow" } if ($ValidDays -lt $Severe) { $MyFontColor="red" } Write-Host "$ID $WebsiteURL $CN $ValidTo $ValidDays" -ForegroundColor $MyFontColor } Catch { Throw $_ } Finally { $Conn.close() } } Catch { Write-Host "$ID $WebsiteURL " $_.exception.innerexception.message -ForegroundColor red } }
Ideally, I would like to show:
Site | Cert Expires In | |
---|---|---|
a | Google.com | 187 days |
I've tried to read through the forums and at the API guide, but am kind of lost. I know that I need to pipe my output to an XML format, then add the PRTG XML parsing code, but that is where I am lost. I am still in a trial with PRTG and would love to have this set up for the demo to my director for budget approval! Thank you for any help or suggestions!
Add comment