Help - Search - Members - Calendar
Full Version: Example: Backup Exec job status monitoring
Intellipool Network Monitor - Forum > Intellipool Network Monitor > Lua scripts
RA
Download a free trial of Intellipool Network Monitor today!

CODE
----------------------------------------------------------------------------------------------------------
-- Name: BackupExec.lua
-- Author: Robert Aronsson - Intellipool AB
-- Required INM version: 3.1 Build 1536
-- Version: 1.0
-- Date: 2006-12-12
-- Description: Checks for a completion status in a BackupExec XML log file
-- Arguments:         
-- 1) Max age of file to check, in hours
-- 2) Path of the folder contaning the XML Files, path cant contain space
----------------------------------------------------------------------------------------------------------

sErrorString = "";

----------------------------------------------------------------------------------------------------------
-- Creates a table of all lines ending with CR in the text file
function makeTable(s)
    local sInData = s;
    iLastPos = 0;
    
    t = {};
    max = string.len(sInData);
    for count = 0, max do
        cCharacter = string.byte(sInData,count);
        if cCharacter == 10 then
            local sTemp = string.sub(sInData,iLastPos,count-1);
            table.insert(t,sTemp);
            iLastPos = count+1;
        end
    end
    return t;
end

----------------------------------------------------------------------------------------------------------
-- Checks if a file meets the conditions set
function CheckFile(sFileName,iFileAge)

    file = TLuaFile();
    iLen = file:GetFileSize( sFileName );
    -- if file size == 0 then we assume that backupexec currently are writing to the file
    if iLen > 0 then
            
        TimeSpan = TLuaDateTime();
        TimeSpan:CreateSpan(iFileAge,0,0);

        FileTime1 = TLuaDateTime();
        FileTime2 = file:GetFileModifiedTime(sFileName);
        

        FileTime1:Sub(TimeSpan);

        -- Check time of file, ignore older files
        if FileTime2:GreaterOrEqual(FileTime1) then
        --print("File time: "..FileTime2:GetDate().." "..FileTime2:GetTime());
        --print("Check time: "..FileTime1:GetDate().." "..FileTime1:GetTime());

            -- Get File size
            iLength = file:GetFileSize( sFileName );

            -- Open file
            if file:Open(sFileName)  == 0 then
                    iRes = GetLastError();
                    sRes = FormatErrorString(iRes)
                sErrorString = sErrorString.."\n".."Cant open file: "..sFileName .." "..sRes;
                    return;
            end

            -- Read the binary data
            local RawData = file:ReadData(iLength);

            -- Close file
            file:Close();

            -- Convert it to 8 bit text
            local StringData = ConvertFromUTF16(RawData,iLength);

            -- Search for the string and return depending on the search result
            iPos = string.find(StringData,"<completeStatus>3</completeStatus>");
            if iPos == nil then
                sErrorString = sErrorString.."\n".."Completion status incorrect in file: "..sFileName;
                return;
            end
        end
    end
end

-- Extract arguments
iFileAge = GetArgument(0);
sFolderPath = GetArgument(1);


-- Create the table
tableFiles = {};

file = TLuaFile();

-- List directory and aquire length
sRet = file:GetFileList( sFolderPath, "BEX_*.xml" );
file:Close();
iLen = string.len( sRet );

-- Check if we got a list of files, this can be modified so that an empty directory does not yeild an error
if iLen==0 then
    sErrString = "Failed to list files, error code:"..GetLastError().."\n"
    SetExitStatus(sErrString,false);
    return;
else
    tableFiles = makeTable( sRet );
end


-- step through the table of files
nTableMax = table.getn(tableFiles);
for count=1, nTableMax do
    sFileName = tableFiles[count];
    --print("\nChecking file "..sFileName);
    CheckFile(sFileName,iFileAge)
end

-- Determin if we got a happy ending
if string.len(sErrorString) > 0 then
    sErrorString = "Backups not ok."..sErrorString;
    -- Not, teh end !
    SetExitStatus(sErrorString,false);
else
    -- Everything ok, teh end !
    SetExitStatus("Backups ok",true);
end
kprestage
On BackupExec 11d, we had to make some minor changes to the script.

1. It looks like job success is now status code 19 and not 3
2. It looks like some maintenance jobs that backup exec runs creates some other xml files in the directory that show <![CDATA[19]]> in the value field. To get around this, we created a 3rd argument for the script to look for the Job Name that we want to check.

Our script is below.

CODE
----------------------------------------------------------------------------------------------------------
-- Name: BackupExec.lua
-- Author: Robert Aronsson - Intellipool AB
-- Required INM version: 3.1 Build 1536
-- Version: 1.0
-- Date: 2006-12-12
-- Description: Checks for a completion status in a BackupExec XML log file
-- Arguments:          
-- 1) Max age of file to check, in hours
-- 2) Path of the folder contaning the XML Files.  Enclose path in quotes if it contains spaces.
-- 3) Job Name to check status of
----------------------------------------------------------------------------------------------------------

sErrorString = "";

----------------------------------------------------------------------------------------------------------
-- Creates a table of all lines ending with CR in the text file
function makeTable(s)
    local sInData = s;
    iLastPos = 0;
    
    t = {};
    max = string.len(sInData);
    for count = 0, max do
        cCharacter = string.byte(sInData,count);
        if cCharacter == 10 then
            local sTemp = string.sub(sInData,iLastPos,count-1);
            table.insert(t,sTemp);
            iLastPos = count+1;
        end
    end
    return t;
end

----------------------------------------------------------------------------------------------------------
-- Checks if a file meets the conditions set
function CheckFile(sFileName,iFileAge)

    file = TLuaFile();
    iLen = file:GetFileSize( sFileName );
    -- if file size == 0 then we assume that backupexec currently are writing to the file
    if iLen > 0 then
            
        TimeSpan = TLuaDateTime();
        TimeSpan:CreateSpan(iFileAge,0,0);

        FileTime1 = TLuaDateTime();
        FileTime2 = file:GetFileModifiedTime(sFileName);
        

        FileTime1:Sub(TimeSpan);

        -- Check time of file, ignore older files
        if FileTime2:GreaterOrEqual(FileTime1) then
        --print("File time: "..FileTime2:GetDate().." "..FileTime2:GetTime());
        --print("Check time: "..FileTime1:GetDate().." "..FileTime1:GetTime());

            -- Get File size
            iLength = file:GetFileSize( sFileName );

            -- Open file
            if file:Open(sFileName)  == 0 then
                    iRes = GetLastError();
                    sRes = FormatErrorString(iRes)
                sErrorString = sErrorString.."\n".."Cant open file: "..sFileName .." "..sRes;
                    return;
            end

            -- Read the binary data
            local RawData = file:ReadData(iLength);

            -- Close file
            file:Close();

            -- Convert it to 8 bit text
            local StringData = ConvertFromUTF16(RawData,iLength);


        -- Search for the Job Name
        iPos2 = string.find(StringData, GetArgument(2));
        if iPos2 == nill then
            return;
        end

            -- Search for the string and return depending on the search result
            iPos = string.find(StringData,"<completeStatus>19</completeStatus>");
            if iPos == nil then
            sErrorString = sErrorString.."\n".."Completion status incorrect in file: "..sFileName;
            return;
            end
        end
    end
end

-- Extract arguments
iFileAge = GetArgument(0);
sFolderPath = GetArgument(1);


-- Create the table
tableFiles = {};

file = TLuaFile();

-- List directory and aquire length
sRet = file:GetFileList( sFolderPath, "BEX_*.xml" );
file:Close();
iLen = string.len( sRet );

-- Check if we got a list of files, this can be modified so that an empty directory does not yeild an error
if iLen==0 then
    sErrString = "Failed to list files, error code:"..GetLastError().."\n"
    SetExitStatus(sErrString,false);
    return;
else
    tableFiles = makeTable( sRet );
end


-- step through the table of files
nTableMax = table.getn(tableFiles);
for count=1, nTableMax do
    sFileName = tableFiles[count];
    --print("\nChecking file "..sFileName);
    CheckFile(sFileName,iFileAge)
end

-- Determin if we got a happy ending
if string.len(sErrorString) > 0 then
    sErrorString = "Backups not ok."..sErrorString;
    -- Not, teh end !
    SetExitStatus(sErrorString,false);
else
    -- Everything ok, teh end !
    SetExitStatus("Backups ok",true);
end
RA
Very nice!
Adam Witwicki
I get an error "Failed to list files, error code:53"

using arguments "20 \\nhs-sr-db\C$\PROGRA~1\VERITAS\Backup~1\NT"

Thanks
Adam
RA
Windows error code 53 is = Network path not found


"20 \\nhs-sr-db\C$\PROGRA~1\VERITAS\Backup~1\NT"


Looks like a very strange network path btw, did you mean

20 "\\nhs-sr-db\C$\PROGRA~1\VERITAS\Backup~1\NT"
Adam Witwicki
I tried it without quotes, same result sad.gif

\\nhs-sr-db\C$\PROGRA~1\VERITAS\Backup~1\NT works in the run cmd
Adam Witwicki
QUOTE(RA @ Jun 26 2007, 03:25 PM) *
Just because it works in "run" does not mean that your FAT32 8.3 path works in this script. Use a real path.



The real path has spaces.... so this wont work?
kprestage
QUOTE(Adam Witwicki @ Jun 26 2007, 09:59 AM) *
I get an error "Failed to list files, error code:53"

using arguments "20 \\nhs-sr-db\C$\PROGRA~1\VERITAS\Backup~1\NT"

Thanks
Adam



Isn't the path relative to the object being monitored? So if you are monitoring the object that runs backup exec, then your path should just be:

"c:\Program Files\Veritas\Backup Exec\NT"

Although the script says no spaces in the path, we have no problem using these paramters on ours.

24 "c:\Program Files\VERITAS\Backup Exec\Data" "[Backup Job Name]"
RA
QUOTE
Isn't the path relative to the object being monitored?


Silly me, yea it is.

QUOTE
Although the script says no spaces in the path, we have no problem using these paramters on ours.


The arguments can now be enclosed into quotations, this script was published before that feature.
Adam Witwicki
QUOTE(kprestage @ Jun 26 2007, 03:33 PM) *
Isn't the path relative to the object being monitored? So if you are monitoring the object that runs backup exec, then your path should just be:

"c:\Program Files\Veritas\Backup Exec\NT"

Although the script says no spaces in the path, we have no problem using these paramters on ours.

24 "c:\Program Files\VERITAS\Backup Exec\Data" "[Backup Job Name]"



I am now getting "Failed to list files, error code:2" using the above path unsure.gif
RA
"File not found"
Adam Witwicki
QUOTE(RA @ Jun 26 2007, 03:39 PM) *
"File not found"




so what file is it looking for, and should it be generated by default ?
kprestage
QUOTE(Adam Witwicki @ Jun 26 2007, 10:36 AM) *
I am now getting "Failed to list files, error code:2" using the above path unsure.gif


Hopefully not the exact path that I posted. That is the path to my Backup Exec files. Yours might be different! If it still isn't working, try using:

"c$\Program Files\VERITAS\Backup Exec\Data"
RA
It looks for files called in the directory you specify.

BEX_*.xml

If your backup files is called something else, change that line.
Adam Witwicki
QUOTE(kprestage @ Jun 26 2007, 03:42 PM) *
Hopefully not the exact path that I posted. That is the path to my Backup Exec files. Yours might be different! If it still isn't working, try using:

"c$\Program Files\VERITAS\Backup Exec\Data"



Think is working now, using "c:\Program Files\Veritas\Backup Exec\NT\data" and got the following



Backups not ok.
Completion status incorrect in file: c:\Program Files\Veritas\Backup Exec\NT\data\BEX_NHS-SR-DB_00967.xml
Completion status incorrect in file: c:\Program Files\Veritas\Backup Exec\NT\data\BEX_NHS-SR-DB_00969.xml
Completion status incorrect in file: c:\Program Files\Veritas\Backup Exec\NT\data\BEX_NHS-SR-DB_00970.xml


Thanks guys smile.gif

Adam
Compatible
Strangely enough this script doesn't work on 1 server.
I've removed the _ in the filename check so currently it's on: BEX*.XML

But we still receive the: Failed to list files, error code:2
I've tried both versions of this script.

Software version of BE is 9.1 could that be the culprit?
RA
Error code 2 = File not found.
Compatible
QUOTE(RA @ Jan 20 2009, 07:53 PM) *
Error code 2 = File not found.

Yes I've already read that, but when I copy/paste the path in explorer I nicely get the correct files
RA
QUOTE
but when I copy/paste the path in explorer I nicely get the correct files



Its very hard to advice on anything since I dont know your setup and your posts are thin on details, but if I have to guess, I would say credentials, maybe user executing the script in INM is not able to list the directory ?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.