[Box Backup-commit] COMMIT r1874 - box/trunk/bin/bbackupd/win32

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Wed Oct 17 13:46:32 BST 2007


Author: chris
Date: 2007-10-17 13:46:32 +0100 (Wed, 17 Oct 2007)
New Revision: 1874

Added:
   box/trunk/bin/bbackupd/win32/NotifySysAdmin.vbs
Log:
Add script to notify sysadmin by email on backup failure on Win32, 
thanks to James O'Gorman. (merges [1830])



Copied: box/trunk/bin/bbackupd/win32/NotifySysAdmin.vbs (from rev 1830, box/chris/general/bin/bbackupd/win32/NotifySysAdmin.vbs)
===================================================================
--- box/trunk/bin/bbackupd/win32/NotifySysAdmin.vbs	                        (rev 0)
+++ box/trunk/bin/bbackupd/win32/NotifySysAdmin.vbs	2007-10-17 12:46:32 UTC (rev 1874)
@@ -0,0 +1,83 @@
+Dim hostname
+Dim account
+Dim from
+Dim sendto
+Dim subjtmpl
+Dim subject
+Dim body
+Dim smtpserver
+
+Set WshNet = CreateObject("WScript.Network")
+hostname = WshNet.ComputerName
+
+account = "0a1"
+from = "boxbackup@" & hostname
+sendto = "admin at example.com"
+subjtmpl = "BACKUP PROBLEM on host " & hostname
+smtpserver = "smtp.example.com"
+
+Set args = WScript.Arguments
+
+If args(0) = "store-full" Then
+	subject = subjtmpl & " (store full)"
+	body =	"The store account for "&hostname&" is full." & vbCrLf & vbCrLf & _
+			"=============================" & vbCrLf & _
+			"FILES ARE NOT BEING BACKED UP" & vbCrLf & _
+			"=============================" & vbCrLf & vbCrLf & _
+			"Please adjust the limits on account "&account&" on server "&hostname&"." _
+			& vbCrLf
+	SendMail from,sendto,subject,body
+ElseIf args(0) = "read-error" Then
+	subject = subjtmpl & " (read errors)"
+	body =	"Errors occured reading some files or directories for backup on "&hostname&"." _
+			& vbCrLf & vbCrLf & _
+			"===================================" & vbCrLf & _
+			"THESE FILES ARE NOT BEING BACKED UP" & vbCrLf & _
+			"===================================" & vbCrLf & vbCrLf & _
+			"Check the logs on "&hostname&" for the files and directories which caused" & _
+			"these errors, and take appropraite action." & vbCrLf & vbCrLf & _
+			"Other files are being backed up." & vbCrLf
+	SendMail from,sendto,subject,body
+ElseIf args(0) = "backup-start" Or args(0) = "backup-finish" Then
+	' do nothing for these messages by default
+Else
+	subject = subjtmpl & " (unknown)"
+	body =	"The backup daemon on "&hostname&" reported an unknown error." _
+			& vbCrLf & vbCrLf & _
+			"==========================" & vbCrLf & _
+			"FILES MAY NOT BE BACKED UP" & vbCrLf & _
+			"==========================" & vbCrLf & vbCrLf & _
+			"Please check the logs on "&hostname&"." & vbCrLf
+	SendMail from,sendto,subject,body
+End If
+
+Function CheckSMTPSvc()
+	Set objWMISvc = GetObject("winmgmts:" _
+		& "{impersonationLevel=impersonate}!\\.\root\cimv2")
+	Set colSMTPSvc = objWMISvc.ExecQuery("Select * From Win32_Service " _
+		& "Where Name='SMTPSVC'")
+	If colSMTPSvc.Count > 0 Then
+		CheckSMTPSvc = True
+	Else
+		CheckSMTPSvc = False
+	End If
+End Function
+
+Sub SendMail(from,sendto,subject,body)
+	Set objEmail = CreateObject("CDO.Message")
+	Dim cdoschema
+	cdoschema = "http://schemas.microsoft.com/cdo/configuration/"
+	With objEmail
+		.From = from
+		.To = sendto
+		.Subject = subject
+		.TextBody = body
+		If CheckSMTPSvc = False Then
+			.Configuration.Fields.Item(cdoschema & "sendusing") = 2
+			.Configuration.Fields.Item(cdoschema & "smtpserver") = smtpserver
+			.Configuration.Fields.Item(cdoschema & "smtpserverport") = 25
+			.Configuration.Fields.Update
+		End If
+	End With
+	objEmail.Send
+End Sub




More information about the Boxbackup-commit mailing list