IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Monitoring BackupAssist, using WMI and EventLog
harvester
post Mar 4 2010, 02:02 PM
Post #1


New to the forum


Group: Members
Posts: 9
Joined: 12-January 10
Member No.: 2,294



I wrote a script for monitoring the software BackupAssist with events in the EventLog (application)

My script:
CODE
-- Name: BackupAssist.lua
-- Author: Guillaume Barre pour Insitu Conseil et Informatique
-- Required INM version: 3.4
-- Version: 1.0
-- Date: 04/03/2010
-- Description: This script search the last Event of BackupAssist and attribute the correct status depending on it. It Uses WMI for query the Windows EventLog.
Author = "<p style=\"color:maroon\">Guillaume Barre - InSitu Conseil & informatique</p>"
Description = "<p style=\"color:maroon\">Monitoring the activity of BackupAssist software.<br/>Possibles Status:</p><ul><li style=\"color:green\">The last Backup is successful</li><li style=\"color:green\">The backup is in progress</li><li style=\"color:red\">The last backup failed.</li><li style=\"color:red\">There are no BackupAssist activities.</li></ul>"
VersionMaj = 1
VersionMin = 1

--------------------------------------------------------------------------------
--                            Script configuration                            --
--------------------------------------------------------------------------------
function OnConfigure()
    Config = LuaScriptConfigurator()
        Config:SetAuthor(Author)
        Config:SetDescription(Description)
        Config:SetMinBuildVersion(0)
        Config:SetScriptVersion(VersionMaj,VersionMin)
        Config:SetEntryPoint("main")
    return Config
end

--------------------------------------------------------------------------------
--                                   Main                                     --
--------------------------------------------------------------------------------
function main()
    
    -- Variables
    Time = ""
    bool = false
    -- Variables for Events
    LastEventTime = TLuaDateTime:new();
    LastEventTime:Create(2000,01,01,00,00,00)
    LastEventIdentifier = 0
    CurrentEventTime = TLuaDateTime:new();
    
    -- we create the query
    Query = TLuaWMIQuery:new();
    QueryString = "SELECT * FROM Win32_NTLogEvent WHERE LogFile=\'Application\' AND SourceName=\'BackupAssist\'"
    
    -- we execute it
    if Query:Execute(QueryString) == false then
        ERROR_STRING = "<p style=\"color:red\">Impossible to query the server:</p>"
        ERROR_STRING = ERROR_STRING..Query:GetErrorDescription()
        Query:delete()
        SetExitStatus(ERROR_STRING,false)  
        return;
    end
                                  
     -- for the first event (so the most recent) we take the Date and the Identifier    
    if Query:NextInstance() then

         -- The "TimeWritten" property is in Windows DateTime format. We have to convert it in Lua DateTime format
    bool, Time = Query:GetProperty("TimeWritten",Time)
    year = tonumber(string.sub(Time,0,4));
    month = tonumber(string.sub(Time,5,6));
    day = tonumber(string.sub(Time,7,8));
    hour = tonumber(string.sub(Time,9,10));
    minute = tonumber(string.sub(Time,11,12));
    second = tonumber(string.sub(Time,13,14));
    CurrentEventTime:Create(year, month, day, hour, minute, second)

    -- This condition is useless unless you modifiy the date in LastEventTime
        -- we verify if this event is the most recent
        if CurrentEventTime:Greater(LastEventTime) then
            LastEventTime = CurrentEventTime
            bool, LastEventIdentifier = Query:GetProperty("EventIdentifier",LastEventIdentifier)
        end
    end    
    Query:delete()
        
    -- Depending on the Identifier, we attribute the correct status
    if LastEventIdentifier == "5633" then
        SetExitStatus("<p style=\"color:green;\">The last Backup ("..LastEventTime:GetDate("%d/%m/%Y at %H:%M")..") is successful terminated</p>",true)
    elseif LastEventIdentifier == "5632" then
        SetExitStatus('<p>The Backup begun at '..LastEventTime:GetDate("%d/%m/%Y at %H:%M")..' is in progress</p>',true)
    elseif LastEventIdentifier == "5634" then
        SetExitStatus('<p style="color:red;">The last Backup ('..LastEventTime:GetDate("%d/%m/%Y at %H:%M")..') failed!</p>',false)
    else
    SetExitStatus("<p style=\"color:red;\">No BackupAssist activity can be identified.</p>",false)
    end

end
Go to the top of the page
 
+Quote Post
RA
post Mar 5 2010, 09:28 AM
Post #2


INM wizard
**********

Group: Root Admin
Posts: 2,328
Joined: 24-August 04
From: Intellipool AB, Härnösand, Sweden
Member No.: 3



Great script, an English localization would be great smile.gif


--------------------
Go to the top of the page
 
+Quote Post
harvester
post Mar 5 2010, 11:43 AM
Post #3


New to the forum


Group: Members
Posts: 9
Joined: 12-January 10
Member No.: 2,294



As I receive the help I asked for, I spend time for finalize my script and translate it in english.

thank you again for your help
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 



RSS Lo-Fi Version Time is now: 10th September 2010 - 09:36 PM