Upon request I have put together a Lua script that can be used with the Lua script monitor to check if a HTTP server certificate is about to expire. The arguments for the script is port number, number of days before the expiry date the monitor should alarm, and if it should suppress connection failures. You need to have INM v4 Build 5290 and later to use this script. Enjoy ! CODE function OnEnumerate(sFieldToEnum)
Enum = LuaScriptEnumResult() if sFieldToEnum == "Ignore connection problems" then Enum:Add("Yes") Enum:Add("No") end return Enum end function OnConfigure() Config = LuaScriptConfigurator() Config:SetAuthor("Robert Aronsson, Intellipool AB") Config:SetDescription("The script check if a certificate is about to expire within the configured number of days.") Config:SetMinBuildVersion(5290) Config:SetScriptVersion(1,0) Config:AddArgument("Port number","Port number to connect on",LuaScriptConfigurator.CHECK_NOT_EMPTY) Config:AddArgument("Number of days","Check if certificate expres within this period",LuaScriptConfigurator.CHECK_NOT_EMPTY) Config:AddArgument("Ignore connection problems","Do you want the script to report connection problems as well ?",LuaScriptConfigurator.ENUM_AVAIL + LuaScriptConfigurator.CHECK_NOT_EMPTY) Config:SetEntryPoint("main") return Config end -- This is the entry point function main() local iPort = GetArgument(0) local iNumDays = GetArgument(1) local bReportConnectionProblem = false; if GetArgument(2) == "Yes" then bReportConnectionProblem = true end -- Timeperiod that the certificate should be valid within local iOffsetTime = (60 * 60 * 24) * iNumDays -- Default values for test eval local bTestOk = true; local sText = "Certificate ok"; -- Open socket Socket = TLuaSocketSecure() if Socket:Open(iPort) ~= 0 then CurrentTime = TLuaDateTime(); -- The time was retrived during the connect Time = Socket:GetCertificateExpiryDate(); print("Certificate expires ("..Time:GetDate() .." " .. Time:GetTime()..")"); -- Check time iExpiryTime = Time:Get() - iOffsetTime; if Time:Get() < CurrentTime:Get() then bTestOk = false; sText = "Certificate have already expired ("..Time:GetDate() .." " .. Time:GetTime()..")"; else if iExpiryTime < CurrentTime:Get() then bTestOk = false; sText = "Certificate is about to expire in less than "..iNumDays.." days" end end else -- Failed to open the socket, server down ? if bReportConnectionProblem == true then bTestOk = false; end sText = "Cannot connect to host."; end -- Report status and exit SetExitStatus(sText,bTestOk); end
|
About Intellipool
Intellipool is a privately held software developer based in Sundsvall, Sweden. This blog is here to post news and tips regarding our product Intellipool Network Monitor.
Intellipool Network Monitor is a system for agentless server monitoring, alerting and reporting of a large selection of operating systems and SNMP capable devices. Last entries
My Blog Links
Links
Intellipool Network Monitor links
Intellipool Customer Portal INM Documentation INM Lua API Documentation INM Download page Friends and allies The Tech Teapot Sentinel Last Comments
brettzle on Friday post
Henk Dirksen on Automatic rotation of dashboards brettzle on Friday post kprestage on More widgets - INM 4.0 David on More widgets - INM 4.0 brettzle on More widgets - INM 4.0 David on Status widgets - INM 4.0 brettzle on Status widgets - INM 4.0 David on The search bar - INM 4.0 brettzle on The search bar - INM 4.0
|