'############################################################################### '# # '# check_ultrabac.vbs # '# # '# Copyright by Thomas Glocker # '# # '# This program is free software; you can redistribute it and/or # '# modify it under the terms of the GNU General Public License # '# as published by the Free Software Foundation; either version 2 # '# of the License, or (at your option) any later version. # '# # '# This program is distributed in the hope that it will be useful, # '# but WITHOUT ANY WARRANTY; without even the implied warranty of # '# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # '# GNU General Public License for more details. # '# # '# GNU General Public License for more details. # '# You should have received a copy of the GNU General Public License # '# along with this program; if not, write to the Free Software # '# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA # '# # '# # '# last change 11.09.2007 by Thomas Glocker # '# # '############################################################################### Dim send_nsca: send_nsca = "C:\nsca\send_nsca.exe" ' please change depanding on your configuration Dim send_nsca_cfg: send_nsca_cfg = "C:\nsca\send_nsca.cfg" ' please change depanding on your configuration Dim nagios_host: nagios_host = "10.31.31.49" ' please change depanding on your configuration set FSO = CreateObject("Scripting.FileSystemObject") Set ws = CreateObject("WScript.Shell") Dim ArgObj Dim Result Dim Args(999) Dim ArgCount Set WshShell = WScript.CreateObject("WScript.Shell") Set WshSysEnv = WshShell.Environment("SYSTEM") Dim Temp: Temp = WshSysEnv("TEMP") Set ArgObj = WScript.Arguments ' Test to make sure there is at least one command line argument If ArgObj.Count < 1 Then DisplayHelpMessage WScript.Quit (GENERAL_FAILURE) End If If ArgObj.Count = 1 and ArgObj.Item(0)="?" Then DisplayFullHelpMessage WScript.Quit (GENERAL_FAILURE) End If Function get_Param(Param) Dim I For I = 0 To ArgObj.Count - 1 If Left(ArgObj.Item(I), Len(Param)) = Param Then get_Param = Right(ArgObj.Item(I), Len(ArgObj.Item(I)) - Len(Param)) Else Args(ArgCount) = ArgObj.Item(I) ArgCount = ArgCount + 1 End If Next End Function Sub DisplayHelpMessage() WScript.Echo WScript.Echo "Usage:" WScript.Echo " check_ultrabac.vbs -H:Host -R:Servicedescription -g:UB Groupfilename" WScript.Echo " -T:Tape Label -L:Logfile -SF:# skipped Files -IF:# in use Files" WScript.Echo " -SE:Sets with Error -ST:Backupstatus -MB:MB backuped" WScript.Echo " -TM:Time of Backup -FC:Filecount" WScript.Echo "" WScript.Echo "For Extended Help type:" WScript.Echo " check_ultrabac.vbs ?" End Sub Sub DisplayFullHelpMessage() WScript.Echo WScript.Echo "Usage:" WScript.Echo " check_ultrabac.vbs -H:Host -R:Servicedescription -g:UB Groupfilename" WScript.Echo " -T:Tape Label -L:Logfile -SF:# skipped Files -IF:# in use Files" WScript.Echo " -SE:Sets with Error -ST:Backupstatus -MB:MB backuped" WScript.Echo " -TM:Time of Backup -FC:Filecount" WScript.Echo "" WScript.Echo "detailed Informations about Ultrabac Before/After Job Macros:" WScript.Echo " http://www.ultrabac.com/kb8/ubq000035.htm" WScript.Echo "" WScript.Echo "-H:Host" WScript.Echo " Host => Hostname as defined in the nagios service check" WScript.Echo "" WScript.Echo "-R:Servicedescription" WScript.Echo " Servicedescription => name of the service-description in the nagios service check" WScript.Echo "" WScript.Echo "-g:UB Groupfilename" WScript.Echo " UB Groupfilename => MACRO:$g$" WScript.Echo " Group filename (e.g. ""testjob.ubb"") no path included. Use the UBDATA share" WScript.Echo " if necessary to access the file." WScript.Echo "" WScript.Echo "-T:Tape Label" WScript.Echo " Tape Label => MACRO:$T$" WScript.Echo " Tape label name (e.g. ""UltraBac Storage Media"")." WScript.Echo "" WScript.Echo "-L:Logfile" WScript.Echo " Logfile => MACRO:$L$" WScript.Echo " Full path/filename to the log file. (e.g. ""c:\ultrabac\logs\bk980122.000"")" WScript.Echo "" WScript.Echo "-SF:# skipped Files" WScript.Echo " # skipped Files => MACRO:$SF$" WScript.Echo " Number of files skipped during the backup. (e.g. ""1"")" WScript.Echo "" WScript.Echo "-IF:# in use Files" WScript.Echo " # in use Files => MACRO:$IF$" WScript.Echo " Number of files backed up ""in-use"". (e.g. ""10"")" WScript.Echo "" WScript.Echo "-SE:Sets with Error" WScript.Echo " Sets with Error => MACRO:$SE$" WScript.Echo " Number of sets in error (e.g. skipped, or unavailable e.g. ""0"")" WScript.Echo "" WScript.Echo "-ST:Backupstatus" WScript.Echo " Backupstatus => MACRO:$ST$" WScript.Echo " Status of backup. If the group is aborted because of a serious error" WScript.Echo " such as a tape drive malfunction, or device unavailable this will be" WScript.Echo " set to ""1"", otherwise ""0"" indicates a normal condition." WScript.Echo "" WScript.Echo "-MB:MB backuped" WScript.Echo " MB backuped => MACRO:$MB$" WScript.Echo " Lists the amount of MB written during the backup" WScript.Echo "" WScript.Echo "-TM:Time of Backup" WScript.Echo " Time of Backup => MACRO:$TM$" WScript.Echo " Lists the backup time" WScript.Echo "" WScript.Echo "-FC:Filecount" WScript.Echo " Filecount => MACRO:$FC$" WScript.Echo " Lists the file count of the backup" WScript.Echo "" End Sub '''''''''''''''''''''''''''' ' ' get arguments ' '''''''''''''''''''''''''''' Dim Host: Host = get_Param("-H:") Dim svc_desc: svc_desc = get_Param("-R:") Dim group_filename: group_filename = get_Param("-g:") Dim tape_label: tape_label = get_Param("-T:") Dim logfile: logfile = get_Param("-L:") Dim skipped_files: skipped_files = get_Param("-SF:") Dim inuse_files: inuse_files = get_Param("-IF:") Dim sets_in_error: sets_in_error = get_Param("-SE:") Dim ST: ST = get_Param("-ST:") Dim MB: MB = get_Param("-MB:") Dim TM: TM = get_Param("-TM:") Dim filecount: filecount = get_Param("-FC:") '''''''''''''''''''''''''''' ' ' read Backuplogfile ' '''''''''''''''''''''''''''' summery=0 Return=Ws.Run("cmd /C type " & logfile & " > " & TEMP & "\logfile.txt") WScript.Sleep(1000) Set BKlogFile = FSO.OpenTextFile(TEMP & "\logfile.txt", 1, -2) Do Until BKlogFile.AtEndOfStream aktLine = BKlogFile.ReadLine if Left(aktLine,12)="Description:" Then desc = Mid(aktLine,14) if aktLine = "BACKUP SUMMARY:" Then summery=1 aktLine = BKlogFile.ReadLine End If if summery > 0 Then Select Case summery case 1 Complete = aktLine case 2 Begin = aktLine case 3 BEnd = aktLine case 4 Duration = aktLine case 5 Capacatiy = aktLine If InStr(1,aktLine,"compression",1)>0 Then Capacatiy = BKlogFile.ReadLine case 6 Remaining = aktLine case 7 ErrWarn = aktLine case 8 FilesComp = aktLine case 9 FoldersComp = aktLine case 10 GBComp = aktLine End Select summery=summery+1 End If Loop BKlogFile.Close Set BKlogFile = CreateObject("Scripting.FileSystemObject") fso.GetFile(TEMP & "\logfile.txt").Delete If summery=0 Then WScript.Quit End If Errors = Left(ErrWarn,InStr(ErrWarn, "Errors") - 2) Warnings = Mid(ErrWarn,InStr(ErrWarn, "Errors") + 11,InStr(ErrWarn, "Warnings") - InStr(ErrWarn, "Errors") - 12) Status = "0" Status_Information = "Backup: " & desc & " completed with " & Errors & " Errors and " & Warnings & " Warnings to " & tape_label & " - Logfile: " & logfile PerfData = "Duration: " & TM & " Files Completed: " & filecount & " Backup Size: " & MB If Errors > 0 Then Status = "1" Status_Information = "Backup: " & desc & " completed with " & Errors & " Errors and " & Warnings & " Warnings to " & tape_label & " - Logfile: " & logfile PerfData = "Duration: " & TM & " Files Completed: " & filecount & " Backup Size: " & MB End If If ST = 1 Then Status = "2" Status_Information = "Backup: " & desc & " aborted. - See Logfile " & logfile & " for detailed Information" PerfData = "Time: " & Mid(BEnd,8,Len(BEnd)) End If Set TestFile = fso.CreateTextFile(TEMP & "\response.txt", True) TestFile.WriteLine(Host & ";" & svc_desc & ";" & Status & ";" & Status_Information & "|" & PerfData) Return=Ws.Run("cmd /C " & send_nsca & " -H " & nagios_host & " -d ; -c " & send_nsca_cfg & " < " & TEMP & "\response.txt",0,false) WScript.Quit