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.

Help getting the test results of the component monitor within the alert emails

Hi,

We are using a certificate date component monitor and we want to get the test results through in the email but can't find a way to get the actual test results that shows the expiring cert / item.

Here's the alert message

Which yeilds the following when simulated.

However when I go to the node concerned and run a test from the component monitor itself I get the following information and it's this I would like in the email message - any ideas folks?

 

Cheers for your thoughts and help

Parents Reply Children
  • Cheers Steven - that's what we've done, included the Component Message but it looks like we can't get the actual cert information into the email.

  • Hi Jamie,

    You can get the cert information in, just have to use one of the script templates. The difference is if the cert is read out to the "console" or to "message: ", where the message value can be recalled but the console one is discarded.

    Does get fiddily with multi-line messages though

    This works in a powershell monitor, recommend setting it to local execution with a very very slow interval, and passing in creds regardless.


    $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
    }