![]() ![]() |
Dec 16 2006, 02:02 PM
Post
#1
|
|
|
INM wizard ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 2,282 Joined: 24-August 04 From: Intellipool AB, Härnösand, Sweden Member No.: 3 |
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 -------------------- |
|
|
|
Jun 19 2007, 06:52 PM
Post
#2
|
|
|
Power user ![]() ![]() ![]() Group: Power users Posts: 192 Joined: 17-May 07 Member No.: 958 |
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 |
|
|
|
Jun 19 2007, 07:07 PM
Post
#3
|
|
|
INM wizard ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 2,282 Joined: 24-August 04 From: Intellipool AB, Härnösand, Sweden Member No.: 3 |
Very nice!
-------------------- |
|
|
|
Jun 26 2007, 12:59 PM
Post
#4
|
|
|
Rookie ![]() Group: Members Posts: 11 Joined: 11-May 07 Member No.: 937 |
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 |
|
|
|
Jun 26 2007, 01:08 PM
Post
#5
|
|
|
INM wizard ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 2,282 Joined: 24-August 04 From: Intellipool AB, Härnösand, Sweden Member No.: 3 |
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" -------------------- |
|
|
|
Jun 26 2007, 01:15 PM
Post
#6
|
|
|
Rookie ![]() Group: Members Posts: 11 Joined: 11-May 07 Member No.: 937 |
I tried it without quotes, same result
\\nhs-sr-db\C$\PROGRA~1\VERITAS\Backup~1\NT works in the run cmd |
|
|
|
Jun 26 2007, 01:29 PM
Post
#7
|
|
|
Rookie ![]() Group: Members Posts: 11 Joined: 11-May 07 Member No.: 937 |
|
|
|
|
Jun 26 2007, 01:33 PM
Post
#8
|
|
|
Power user ![]() ![]() ![]() Group: Power users Posts: 192 Joined: 17-May 07 Member No.: 958 |
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]" |
|
|
|
Jun 26 2007, 01:36 PM
Post
#9
|
|
|
INM wizard ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 2,282 Joined: 24-August 04 From: Intellipool AB, Härnösand, Sweden Member No.: 3 |
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. -------------------- |
|
|
|
Jun 26 2007, 01:36 PM
Post
#10
|
|
|
Rookie ![]() Group: Members Posts: 11 Joined: 11-May 07 Member No.: 937 |
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 |
|
|
|
Jun 26 2007, 01:39 PM
Post
#11
|
|
|
INM wizard ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 2,282 Joined: 24-August 04 From: Intellipool AB, Härnösand, Sweden Member No.: 3 |
"File not found"
-------------------- |
|
|
|
Jun 26 2007, 01:41 PM
Post
#12
|
|
|
Rookie ![]() Group: Members Posts: 11 Joined: 11-May 07 Member No.: 937 |
|
|
|
|
Jun 26 2007, 01:42 PM
Post
#13
|
|
|
Power user ![]() ![]() ![]() Group: Power users Posts: 192 Joined: 17-May 07 Member No.: 958 |
I am now getting "Failed to list files, error code:2" using the above path 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" |
|
|
|
Jun 26 2007, 01:44 PM
Post
#14
|
|
|
INM wizard ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 2,282 Joined: 24-August 04 From: Intellipool AB, Härnösand, Sweden Member No.: 3 |
It looks for files called in the directory you specify.
BEX_*.xml If your backup files is called something else, change that line. -------------------- |
|
|
|
Jun 26 2007, 01:45 PM
Post
#15
|
|
|
Rookie ![]() Group: Members Posts: 11 Joined: 11-May 07 Member No.: 937 |
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 Adam |
|
|
|
Jan 20 2009, 01:57 PM
Post
#16
|
|
|
New to the forum Group: Members Posts: 2 Joined: 11-May 08 Member No.: 1,506 |
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? |
|
|
|
Jan 21 2009, 07:53 AM
Post
#17
|
|
|
INM wizard ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 2,282 Joined: 24-August 04 From: Intellipool AB, Härnösand, Sweden Member No.: 3 |
Error code 2 = File not found.
-------------------- |
|
|
|
Jan 23 2009, 09:10 AM
Post
#18
|
|
|
New to the forum Group: Members Posts: 2 Joined: 11-May 08 Member No.: 1,506 |
|
|
|
|
Jan 23 2009, 10:14 AM
Post
#19
|
|
|
INM wizard ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Root Admin Posts: 2,282 Joined: 24-August 04 From: Intellipool AB, Härnösand, Sweden Member No.: 3 |
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 ? -------------------- |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 31st July 2010 - 05:57 PM |