This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

How do you get the SSL Certificate Expiration Date Monitor to return the expired cert name?

SSL Certificate Expiration Date Monitor only seems to return the expiration date and number of days until expiration. When testing the component in SAM, it returns a lot of detail about the cert including it's name. Has anyone found a way to return all that information back to the email alert action? The ${N=SwisEntity;M=ComponentAlert.ComponentMessage} doesn't seem to pass that information and I haven't found it in the Db to make a custom variable.

  • Try the error variable it's probably in there

    If it's not in there I've got a powershell equivalent that puts it in a message variable (which is still labled "error" in some places)

  • If you mean here ${N=SwisEntity;M=ComponentAlert.StatusOrErrorDescription} its not there either. When scrolling through all the possible variables, it cannot be found. Support says its not stored.

  • $statistic = $Null
    $date = Get-Date
    $URL = "https://${IP}"

    $WebRequest = [Net.WebRequest]::Create($URL)
    $WebRequest.UseDefaultCredentials = $true
    $WebRequest.PreAuthenticate = $true

    $AllArray = @()

    Try
    {
    $WebResponse = $WebRequest.GetResponse()
    $Cert = [Security.Cryptography.X509Certificates.X509Certificate2]$WebRequest.ServicePoint.Certificate.Handle
    $statistic = $cert.Subject
    $expiry = $cert.NotAfter
    $remaining = $expiry - $date
    $Statistic = $remaining.days
    }
    Catch
    {
    # Write-Host "Web request failed" -ForegroundColor Red
    # Write-Host "Attempting to get cert info regardless..." -ForegroundColor Yellow

    $Cert = [Security.Cryptography.X509Certificates.X509Certificate2]$WebRequest.ServicePoint.Certificate.Handle
    $CN = $cert.Subject
    $expiry = $cert.NotAfter
    $remaining = $expiry - $date
    $Statistic = $remaining.Days
    If($statistic -lt "-2000")
    {
    Clear-Variable statistic
    }
    }
    If($Statistic -ne $null)
    {
    $FormattedExpiry = $expiry.ToString("dd/MM/yyyy")
    $Message = "Certificate $CN will expire on $FormattedExpiry, $statistic days left"
    Write-Host "Statistic: $statistic"
    Write-Host "Message: $message"
    Exit 0;
    }

    Function Get-Direct
    {
    If($statistic -eq $Null)
    {
    #Write-Host "Trying direct cert store script" -ForegroundColor Yellow
    $server = $url.Replace('https://','')
    $objStore = new-object System.Security.Cryptography.X509Certificates.X509Store("\\$Server\MY","LocalMachine")
    $objStore.open("ReadOnly")
    $Cert = $objStore.Certificates | sort notafter
    $CN = $Cert.subject[0]
    $Expiry = $Cert.NotAfter[0]
    $Remaining = $expiry - $date
    $statistic = $remaining.Days
    If($statistic -lt "-2000")
    {
    Clear-Variable statistic
    }

    If($statistic -eq $Null)
    {
    Write-Host "Statistic.ExitCode: 1"
    Exit 1;
    }
    Else
    {
    $FormattedExpiry = $expiry.ToString("dd/MM/yyyy")
    $Message = "Certificate $CN will expire on $FormattedExpiry, $statistic days left"
    Write-Host "Statistic: $statistic"
    Write-Host "Message: $message"
    Exit 0;
    }
    }
    }
    If($statistic -eq $null)
    {
    Get-Direct
    }

  • Switch to this script below and it'll be in Message

    The goal with this script was to cover as many certificate types as possible while also getting cert name and days remaining.

    If it's available at https://${IP} it'll do that. If not it'll try to look in the windows certificate store, it'll return the worst certificate so can require clean-up. Needs solid permissions for windows but none for https testing.

    Recommend a dashboard where you order by dates with Critical -> Warning -> Down -> Up

    Recommend an alert based on warning and critical but not down, and down as a report

  • Thank you! So you are using this as a custom application/component in place of the OOB component? I was also looking at this thread...
    https://thwack.solarwinds.com/product-forums/the-orion-platform/f/alert-lab/91386/embedding-output-into-an-alert-email-action

    As a possible way to get the data stored in the Alert notes.

  • SAM templates -> new -> custom powershell -> save -> application discovery :)

    Notes for extra data is good, but i'd only reccomend that when there's a secondary check that fills in other data. Using Statistic + message + custom SWQL macros gets you almost everything else albeit it's sometimes a faff.

  • This is excellent. Thanks for providing it.