Intellipool server monitoring blog

Welcome Guest ( Log In | Register )

Rating 0
entry Nov 12 2009, 10:53 AM
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

 
« Next Oldest · Intellipool server monitoring blog · Next Newest »
 
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.





SMTWTFS
1
2
3
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28