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