Hello, I have PowerShell script which runs in the PowerShell CLI but getting the following error from prtg "Your request has timed out. Depending on the sensor type you use, the reason might be that the sensor could not connect to the target host or that a PowerShell command takes too long to execute. For more information, see https://helpdesk.paessler.com/en/support/solutions/articles/76000042368 or https://helpdesk.paessler.com/en/support/solutions/articles/76000063353. (code: PE018)"
this is the code of the script:
echo 0 | openssl s_client -host google.com -port 443 -prexit -showcerts > AllCertificates 2>$null [string[]]$arrayFromFile = Get-Content -Path .\AllCertificates $x=1 $i=0 $count=0 $minDays=10000 while($x) { if ($arrayFromFile[$i] -eq "Server certificate") {break} if ($arrayFromFile[$i] -eq '-----Begin Certificate-----') { while ($arrayFromFile[$i] -ne '-----End Certificate-----') { Write $arrayFromFile[$i] >> .\sslToCheck.crt $i=$i+1 } Write $arrayFromFile[$i] >> .\sslToCheck.crt $i=$i+1 $file = Get-Content .\sslToCheck.crt #Regex pattern to compare two strings $pattern = "-----BEGIN CERTIFICATE-----(.*?)-----END CERTIFICATE-----" #Perform the opperation $result = [regex]::Match($file,$pattern).Groups[1].Value #Redirect each certificate to ssl.crt file Add-Content .\ssl.crt "-----BEGIN CERTIFICATE-----" Add-Content .\ssl.crt "$result" Add-Content .\ssl.crt "-----END CERTIFICATE-----" #Get-Content .\ssl.crt #Return the validation date openssl x509 -noout -issuer -dates -subject -in ssl.crt > .\Outcome #Put the value into variable - VALIDATION TIME $TimeAfter = Get-Content .\Outcome | Select -Index 2 $NotValidAfter=$TimeAfter.Replace("notAfter=","") #Get the name of the Certificate $text = openssl x509 -noout -issuer -dates -subject -in ssl.crt $separator = "CN =" $parts = $text.split($separator) $sslName = $parts[-1] # return the part after the separator #Parse the Date $WordIndex = 1 $month = ($NotValidAfter -split "\s+",($wordIndex +1 ))[($wordIndex-1)] $WordIndex = 2 $dateNum = ($NotValidAfter -split "\s+",($wordIndex +1 ))[($wordIndex-1)] $WordIndex = 4 $tmpyear = ($NotValidAfter -split "\s+",($wordIndex +1 ))[($wordIndex-1)] $tmpyear -as [int] > $null $year = $tmpyear%100 $DateParse1 = "$dateNum-$month-$year" $DateParse2 = [datetime]::parseexact($DateParse1, 'dd-MMM-yy', $null) $certExpiresIn = ($DateParse2 - $(get-date)).Days #The OutPut for each certificate #Write-Host Cert for SSL $sslName expires in $certExpiresIn days on $DateParse2 Clear-Content .\sslToCheck.crt Clear-Content .\ssl.crt if ($minDays -gt $certExpiresIn) { $minDays=$certExpiresIn $sslNameToReturn=$sslName } } else { $i=$i+1 } } Write-Host $minDays,":OK" Exit 0
The script returns the following output in the CLI:
237 :OK
but in the PRTG its showing different errors. this is not the issue of the ExecutionPolicy, we set it to Unrestricted at the level of local machine.
Thanks
Article Comments
Hello,
we have actually solved the issue, by moving the script to EXEXML folder (without changing it) and it ran successfully.
I still do not know the root cause of the issue.
the script running from the core probe itself, and we made adjustments that it will run ok in 32bit PS. the scanning interval is standard 60 seconds.
Jul, 2020 - Permalink
Hi Denis,
Please let me know how long the script needs to be executed on the server where the corresponding Probe runs (32bit Powershell used).
In addition, please let me know which is the used scanning interval and how long is the timeout configured in the Sensor settings?
Jul, 2020 - Permalink