Submit a ticketCall us

Get a crash course on Network Monitoring delivered right to your inbox
This free 7-day email course provides a primer to the philosophy, theory, and fundamental concepts involved in IT monitoring. Lessons will explain not only how to perform various monitoring tasks, but why and when you should use them. Sign up now.

Home > Success Center > Server & Application Monitor (SAM) > Monitor SSL certificate expiration date

Monitor SSL certificate expiration date

Table of contents

Updated March 11th, 2016


This article provides brief information and steps to monitor your SSL certificate expiration date. 

SAM has an SSL Expiration Date Monitor beginning in APM version 4.2, which can be found here.

In order to calculate the number of days until an SSL certificate expires, a vbscript can be implemented with the Windows Script Monitor. This script relies on OpenSSL being installed on your Orion server to check for the expiration date. The script below accepts one argument in the form of a URL, with the socket number, and returns the statistic in the number of days remaining until expiration.

Before using this script you need to install OpenSSL, which is freely available on the internet. Ensure the path given below has the OpenSSL plug-in installed or change the path as per your OpenSSL plug-in.

For each instance of the monitor, change the text file that the monitor writes to, for example, cer1.txt, cer2.txt, otherwise the monitors may return a value of, Unknown.


All SAM versions using APM version 4.2


WarningThe code below is user-submitted. Use at your own risk. SolarWinds is not responsible for the impact this code may have on your system. Exercise caution when executing any code with which you are not familiar.


You will need to pass the argument site name plus the port number. 




Option Explicit

Dim oShell
Dim ArgObj
Dim Fh
Dim Line
Dim Expiry
Dim DaysLeft
Dim ExpDate
Dim oExec
Dim cert
Dim tstream
Dim i
Dim str
Dim PluginPath
Dim CertFilePath
Dim char
Dim XString

Const ForReading = 1

CertFilePath = "C:\TMP\cert99.txt"
PluginPath = "C:\Program Files\Solarwinds\Common\OpenSSL\bin\"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set tstream = FSO.createtextfile(CertFilePath, True)

ArgObj = wscript.Arguments(0)

Set oShell = wscript.CreateObject("WScript.Shell")

'Calling funtion to retieve the host
Set oExec = oShell.exec(PluginPath & "openssl.exe s_client -connect " & ArgObj)

'Write the certificate into a text file
Do Until oExec.StdOut.AtEndOfStream
    char = oExec.StdOut.Read(1)
    tstream.Write (char)
    If Len(XString) < 20 Then
        XString = XString & char
    ElseIf XString = "END CERTIFICATE-----" Then

Exit Do

        XString = Mid(XString, 2, 19)
        XString = XString & char
    End If



'Read SSL certificate for start date and end date
Set oExec = oShell.exec(PluginPath & "openssl.exe x509 -noout -in " & CertFilePath & " -dates")

'Return start date and end date of the certificate
Line = oExec.StdOut.Readall

'Get the expiration date of the certificate
Expiry = (Mid(Line, Len(Line) - 24, 24))
ExpDate = ConvertDate(Expiry)

'Calculating number of days
DaysLeft = DateDiff("d", Now(), ExpDate)

'Display the number of days remaining until expiration
wscript.echo "Statistic: " & DaysLeft
wscript.echo "Message:  Number of days remaning of expiry for SSL certificate are " & DaysLeft

'Object Closing code
Set oShell = Nothing
Set oExec = Nothing

'This function converts the date into the required format
Function ConvertDate(DateStr)

Dim Components
Dim Month
Dim Day
Dim Year

Components = Split(DateStr)

Select Case Components(0)
    Case "Jan", "January"
    Month = 1

    Case "Feb", "February"
    Month = 2
    Case "Mar", "March"
    Month = 3
    Case "Apr", "April"
    Month = 4

    Case "May"
    Month = 5

    Case "Jun", "June"
    Month = 6

    Case "Jul", "July"
    Month = 7

    Case "Aug", "August"
    Month = 8

    Case "Sep", "Sept", "September"
    Month = 9

    Case "Oct", "October"
    Month = 10
    Case "Nov", "November"
    Month = 11

    Case "Dec", "December"
    Month = 12

Case Else

    Month = 1
End Select

    Day = Components(1)
    Year = Components(3)

If UBound(Components) = 5 Then
    Day = Components(2)
    Year = Components(4)
    Day = Components(1)
    Year = Components(3)
End If

ConvertDate = CDate(Day & "/" & Month & "/" & Year)

End Function



Last modified
11:54, 1 Jun 2017